From 75f7c44223811a9b4f9c522f5cb14396c89422fd Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Sun, 25 Oct 2015 15:47:50 -0400 Subject: [PATCH] BUG: Better check for last date. Use get_loc to find the trading day that ended 2 days before now. --- zipline/data/loader.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/zipline/data/loader.py b/zipline/data/loader.py index 1f529596..2c42759a 100644 --- a/zipline/data/loader.py +++ b/zipline/data/loader.py @@ -130,7 +130,8 @@ def load_market_data(trading_day=trading_day_nyse, first_date = trading_days[0] # We expect to have benchmark and treasury data that's current up until - # two full trading days prior to the most recently completed trading day. + # **two** full trading days prior to the most recently completed trading + # day. # Example: # On Thu Oct 22 2015, the previous completed trading day is Wed Oct 21. # However, data for Oct 21 doesn't become available until the early morning @@ -142,9 +143,10 @@ def load_market_data(trading_day=trading_day_nyse, # We'll attempt to download new data if the latest entry in our cache is # before this date. - last_date = ( - pd.Timestamp('now', tz='UTC').normalize() - (2 * trading_day) - ) + last_date = trading_days[ + trading_days.get_loc(pd.Timestamp.utcnow(), method='ffill') - 2 + ] + benchmark_returns = ensure_benchmark_data( bm_symbol, first_date,