mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-13 17:42:42 +08:00
MAINT: Switch treasury curves from Series to DataFrame.
Instead of using a pandas Series of with dictionaries as the values treasury curves, use a DataFrame which more naturally fits the data type of a having a timeseries with mulitple values. Should allow easier slicing/manipulation of the treasury curves, e.g. getting 10 year curves would now be: ``` treasury_curves['10year'] ```
This commit is contained in:
@@ -187,7 +187,7 @@ def alpha(algorithm_period_return, treasury_period_return,
|
||||
def get_treasury_rate(treasury_curves, treasury_duration, day):
|
||||
rate = None
|
||||
|
||||
curve = treasury_curves[day]
|
||||
curve = treasury_curves.ix[day]
|
||||
# 1month note data begins in 8/2001,
|
||||
# so we can use 3month instead.
|
||||
idx = TREASURY_DURATIONS.index(treasury_duration)
|
||||
@@ -238,7 +238,7 @@ def choose_treasury(treasury_curves, start_date, end_date):
|
||||
end_day = end_date.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
search_day = None
|
||||
|
||||
if end_day in treasury_curves:
|
||||
if end_day in treasury_curves.index:
|
||||
rate = get_treasury_rate(treasury_curves,
|
||||
treasury_duration,
|
||||
end_day)
|
||||
|
||||
@@ -85,9 +85,9 @@ class TradingEnvironment(object):
|
||||
self.benchmark_returns, treasury_curves_map = \
|
||||
load(self.bm_symbol)
|
||||
|
||||
self.treasury_curves = pd.Series(treasury_curves_map)
|
||||
self.treasury_curves = pd.DataFrame(treasury_curves_map).T
|
||||
if max_date:
|
||||
self.treasury_curves = self.treasury_curves[:max_date]
|
||||
self.treasury_curves = self.treasury_curves.ix[:max_date, :]
|
||||
|
||||
self.full_trading_day = datetime.timedelta(hours=6, minutes=30)
|
||||
self.early_close_trading_day = datetime.timedelta(hours=3, minutes=30)
|
||||
|
||||
@@ -104,7 +104,7 @@ def create_random_simulation_parameters():
|
||||
len(treasury_curves) - 1
|
||||
)
|
||||
|
||||
start_dt = treasury_curves.keys()[random_index]
|
||||
start_dt = treasury_curves.index[random_index]
|
||||
end_dt = start_dt + timedelta(days=365)
|
||||
|
||||
now = datetime.utcnow().replace(tzinfo=pytz.utc)
|
||||
|
||||
Reference in New Issue
Block a user