MAINT: Change expected type of treasury curves from load to DataFrame.

Instead of converting the curves back and forth from dictionaries to
DataFrame and back, use the DataFrame format when passing to
environment.
This commit is contained in:
Eddie Hebert
2015-04-20 10:26:09 -04:00
parent 82d2ddfa90
commit 0fa44471be
2 changed files with 7 additions and 13 deletions
+1 -11
View File
@@ -229,17 +229,7 @@ def load_market_data(trading_day=trading_day_nyse,
else:
treasury_curves = saved_curves.tz_localize('UTC')
tr_curves = {}
for tr_dt, curve in treasury_curves.T.iteritems():
# tr_dt = tr_dt.replace(hour=0, minute=0, second=0, microsecond=0,
# tzinfo=pytz.utc)
tr_curves[tr_dt] = curve.to_dict()
tr_curves = OrderedDict(sorted(
((dt, c) for dt, c in iteritems(tr_curves)),
key=lambda t: t[0]))
return benchmark_returns, tr_curves
return benchmark_returns, treasury_curves
def _load_raw_yahoo_data(indexes=None, stocks=None, start=None, end=None):
+6 -2
View File
@@ -92,6 +92,11 @@ class TradingEnvironment(object):
max_date=None,
env_trading_calendar=tradingcalendar
):
"""
@load is function that returns benchmark_returns and treasury_curves
The treasury_curves are expected to be a DataFrame with an index of
dates and columns of the curve names, e.g. '10year', '1month', etc.
"""
self.trading_day = env_trading_calendar.trading_day.copy()
# `tc_td` is short for "trading calendar trading days"
@@ -116,10 +121,9 @@ class TradingEnvironment(object):
if not load:
load = load_market_data
self.benchmark_returns, treasury_curves_map = \
self.benchmark_returns, self.treasury_curves = \
load(self.trading_day, self.trading_days, self.bm_symbol)
self.treasury_curves = pd.DataFrame(treasury_curves_map).T
if max_date:
tr_c = self.treasury_curves
# Mask the treasury curves down to the current date.