mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-04 01:56:36 +08:00
ENH: Allow algorithm to run past end of trading.environment history.
Work towards running an algorithm against 'live' data, which can't be bound to the available benchmarks and treasuries, since the benchmarks and treasury curves for that day won't be published until that night.
This commit is contained in:
@@ -75,7 +75,8 @@ class TradingEnvironment(object):
|
||||
self,
|
||||
load=None,
|
||||
bm_symbol='^GSPC',
|
||||
exchange_tz="US/Eastern"
|
||||
exchange_tz="US/Eastern",
|
||||
max_date=None
|
||||
):
|
||||
self.prev_environment = self
|
||||
self.trading_day_map = OrderedDict()
|
||||
@@ -94,6 +95,8 @@ class TradingEnvironment(object):
|
||||
self.exchange_tz = exchange_tz
|
||||
|
||||
for bm in self.benchmark_returns:
|
||||
if max_date and bm.date > max_date:
|
||||
break
|
||||
self.trading_day_map[bm.date] = bm
|
||||
|
||||
self.first_trading_day = next(self.trading_day_map.iterkeys())
|
||||
|
||||
@@ -168,13 +168,8 @@ class AlgorithmSimulator(object):
|
||||
yield daily_rollup
|
||||
tp = self.algo.perf_tracker.todays_performance
|
||||
tp.rollover()
|
||||
|
||||
if mkt_close < self.algo.perf_tracker.last_close:
|
||||
env = trading.environment
|
||||
_, mkt_close = \
|
||||
env.next_open_and_close(
|
||||
mkt_close
|
||||
)
|
||||
mkt_close = self.get_next_close(mkt_close)
|
||||
|
||||
risk_message = self.algo.perf_tracker.handle_simulation_end()
|
||||
yield risk_message
|
||||
@@ -193,6 +188,12 @@ class AlgorithmSimulator(object):
|
||||
perf_message['intraday_perf']['recorded_vars'] = rvars
|
||||
return perf_message
|
||||
|
||||
def get_next_close(self, mkt_close):
|
||||
if mkt_close >= trading.environment.last_trading_day:
|
||||
return self.sim_params.last_close
|
||||
else:
|
||||
return trading.environment.next_open_and_close(mkt_close)[1]
|
||||
|
||||
def update_universe(self, event):
|
||||
"""
|
||||
Update the universe with new event information.
|
||||
|
||||
Reference in New Issue
Block a user