Example #1
0
 def test_write_day_and_id(self):
     result = self.writer.write(self.dest, self.trading_days, self.assets)
     idx = 0
     ids = result['id']
     days = result['day']
     for asset_id in self.assets:
         for date in self.dates_for_asset(asset_id):
             self.assertEqual(ids[idx], asset_id)
             self.assertEqual(date, seconds_to_timestamp(days[idx]))
             idx += 1
 def apply_adjustments(self, dates, assets, baseline_values, adjustments):
     min_date, max_date = dates[[0, -1]]
     values = baseline_values.copy()
     for eff_date_secs, ratio, sid in adjustments.itertuples(index=False):
         eff_date = seconds_to_timestamp(eff_date_secs)
         if eff_date < min_date or eff_date > max_date:
             continue
         eff_date_loc = dates.get_loc(eff_date)
         asset_col = assets.get_loc(sid)
         # Apply ratio multiplicatively to the asset column on all rows
         # **strictly less** than the adjustment effective date.  Note that
         # this will be a no-op in the case that the effective date is the
         # first entry in dates.
         values[:eff_date_loc, asset_col] *= ratio
     return values
 def apply_adjustments(self, dates, assets, baseline_values, adjustments):
     min_date, max_date = dates[[0, -1]]
     values = baseline_values.copy()
     for eff_date_secs, ratio, sid in adjustments.itertuples(index=False):
         eff_date = seconds_to_timestamp(eff_date_secs)
         if eff_date < min_date or eff_date > max_date:
             continue
         eff_date_loc = dates.get_loc(eff_date)
         asset_col = assets.get_loc(sid)
         # Apply ratio multiplicatively to the asset column on all rows
         # **strictly less** than the adjustment effective date.  Note that
         # this will be a no-op in the case that the effective date is the
         # first entry in dates.
         values[:eff_date_loc, asset_col] *= ratio
     return values
Example #4
0
 def apply_adjustments(self, dates, assets, baseline_values, adjustments):
     min_date, max_date = dates[[0, -1]]
     # HACK: Simulate the coercion to float64 we do in adjusted_array.  This
     # should be removed when AdjustedArray properly supports
     # non-floating-point types.
     orig_dtype = baseline_values.dtype
     values = baseline_values.astype(float64).copy()
     for eff_date_secs, ratio, sid in adjustments.itertuples(index=False):
         eff_date = seconds_to_timestamp(eff_date_secs)
         # Don't apply adjustments that aren't in the current date range.
         if eff_date not in dates:
             continue
         eff_date_loc = dates.get_loc(eff_date)
         asset_col = assets.get_loc(sid)
         # Apply ratio multiplicatively to the asset column on all rows less
         # than or equal adjustment effective date.
         values[:eff_date_loc + 1, asset_col] *= ratio
     return values.astype(orig_dtype)