From 718ce0270a6f410c22890f8ec8cd387d72d0d197 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Mon, 4 Mar 2013 21:25:27 -0500 Subject: [PATCH] ENH: Improves handling of edge case in data update. If the trading_days end date is not greater than the date being tested, (this can happen if the algorithm's end date is set to a date that is before the latest date available saved in the msgpacks), then trying to get the location will fail, instead searchsorted will get the lastest date available in the trading day map to use as a test date. --- zipline/data/loader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zipline/data/loader.py b/zipline/data/loader.py index f70abd59..2f7fc835 100644 --- a/zipline/data/loader.py +++ b/zipline/data/loader.py @@ -160,7 +160,7 @@ Fetching data from Yahoo Finance. # Find the offset of the last date for which we have trading data in our # list of valid trading days last_bm_date = tuple_to_date(bm_list[-1][0]) - last_bm_date_offset = trading_days.get_loc( + last_bm_date_offset = trading_days.searchsorted( last_bm_date.strftime('%Y/%m/%d')) # If more than 1 trading days has elapsed since the last day where @@ -196,13 +196,13 @@ Fetching data from data.treasury.gov # Find the offset of the last date for which we have trading data in our # list of valid trading days last_tr_date = tuple_to_date(tr_list[-1][0]) - last_tr_date_offset = trading_days.get_loc( + last_tr_date_offset = trading_days.searchsorted( last_tr_date.strftime('%Y/%m/%d')) # If more than 1 trading days has elapsed since the last day where # we have data,then we need to update if len(trading_days) - last_tr_date_offset > 1: - update_benchmarks(last_tr_date) + update_treasury_curves(last_tr_date) fp_tr = get_datafile('treasury_curves.msgpack', "rb") tr_list = msgpack.loads(fp_tr.read())