From a29e0c40b6917940c027d86991a07132a4db5556 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 25 Sep 2013 16:24:01 -0400 Subject: [PATCH] MAINT: Reduce the number of minutes included in risk index. Instead of midnight to midnight for each day, use the trading environment's market open and close for each day, so that the index is exactly the trading minutes of each day. Reduces the amount of memory consumed, but more importantly should make it easier to inspect the Series that use the index and check whether the values are correctly being filled. --- zipline/finance/risk/cumulative.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/zipline/finance/risk/cumulative.py b/zipline/finance/risk/cumulative.py index 395ef661..f62a3532 100644 --- a/zipline/finance/risk/cumulative.py +++ b/zipline/finance/risk/cumulative.py @@ -110,8 +110,20 @@ class RiskMetricsCumulative(object): self.daily_treasury = pd.Series(index=self.trading_days) def get_minute_index(self, sim_params): - return pd.date_range(sim_params.first_open, sim_params.last_close, - freq="Min") + """ + Stitches together multiple days worth of business minutes into + one continous index. + """ + trading_minutes = None + for day in self.trading_days: + mkt_open, mkt_close = trading.environment.get_open_and_close(day) + minutes_for_day = pd.date_range(mkt_open, mkt_close, freq='T') + if trading_minutes is None: + # Create container for all minutes on first iteration + trading_minutes = minutes_for_day + else: + trading_minutes = trading_minutes + minutes_for_day + return trading_minutes def get_daily_index(self): return self.trading_days