ENH/BUG: Modeling API enhancements.

- Fixes an error where Modeling API data known as of the close of `day
  N` would be shown to algorithms during `before_trading_start` as of
  the close of the same day.  Algorithms should now only receive data
  during `before_trading_start/handle_data` that was known as of the
  simulation time at which the function would be called.

- All Term instances now have a `mask` attribute that must be a `Filter`
  or an instance of `AssetExists()`.  `mask` can be used to specify that
  a Factor should be computed in a manner that ignores the values that
  were not `True` in the mask.

- Changed the interface for `FFCLoader.load_adjusted_array` and
  `Term._compute` from `(columns, mask)`, with mask as a DataFrame, to
  `(columns, dates, assets, mask)`, where mask is a numpy array.  This
  is primarily to avoid having to reconstruct extra DataFrames when
  using masks produced by non `AssetExists` filters.

- Adds `BoundColumn.latest`, which gives the most-recently-known value
  of a column.
This commit is contained in:
Scott Sanderson
2015-09-16 01:47:11 -04:00
parent 691f6d95d7
commit 26fd6fda8b
32 changed files with 1643 additions and 733 deletions
+12 -1
View File
@@ -1363,13 +1363,24 @@ class TradingAlgorithm(object):
def compute_factor_matrix(self, start_date):
"""
Compute a factor matrix starting at start_date.
Compute a factor matrix containing at least the data necessary to
provide values for `start_date`.
Loads a factor matrix with data extending from `start_date` until a
year from `start_date`, or until the end of the simulation.
"""
days = self.trading_environment.trading_days
# Load data starting from the previous trading day...
start_date_loc = days.get_loc(start_date)
# ...continuing until either the day before the simulation end, or
# until 252 days of data have been loaded. 252 is a totally arbitrary
# choice that seemed reasonable based on napkin math.
sim_end = self.sim_params.last_close.normalize()
end_loc = min(start_date_loc + 252, days.get_loc(sim_end))
end_date = days[end_loc]
return self.engine.factor_matrix(
self._all_terms(),
start_date,