MAINT: Use trading day increment instead of timedelta in test factory.

In the test factory creation of returns, the date creation was using
a timedelta of one day instead of incrementing by trading days.

Working towards changing risk module behavior which would leverage
the trading day map, but tests fail because non-trading days are
created.

Remove `factory.create_returns`, moving uses of that function to us
`factory.create_returns_from_period`, since the number of days input
for `create_returns` was more difficult to use when specifying ranges
over arbirtray dates.
This commit is contained in:
Eddie Hebert
2013-04-01 23:52:50 -04:00
parent 210a43a306
commit dd172dd42a
2 changed files with 13 additions and 34 deletions
+10 -11
View File
@@ -728,8 +728,10 @@ class Risk(unittest.TestCase):
[0.0500])
def test_benchmarkrange(self):
self.check_year_range(datetime.datetime(year=2008, month=1, day=1),
2)
self.check_year_range(
datetime.datetime(
year=2008, month=1, day=1, tzinfo=pytz.utc),
2)
def test_partial_month(self):
@@ -749,21 +751,18 @@ class Risk(unittest.TestCase):
period_end=end
)
returns = factory.create_returns(total_days, sim_params90s)
returns = factory.create_returns_from_range(sim_params90s)
returns = returns[:-10] # truncate the returns series to end mid-month
metrics = risk.RiskReport(returns, sim_params90s)
total_months = 60
self.check_metrics(metrics, total_months, start)
def check_year_range(self, start_date, years):
if(start_date.month <= 2):
ld = calendar.leapdays(start_date.year, start_date.year + years)
else:
# because we may catch the leap of the last year,
# and i think this func is [start,end)
ld = calendar.leapdays(start_date.year,
start_date.year + years + 1)
returns = factory.create_returns(365 * years + ld, self.sim_params08)
sim_params = SimulationParameters(
period_start=start_date,
period_end=start_date.replace(year=(start_date.year + years))
)
returns = factory.create_returns_from_range(sim_params)
metrics = risk.RiskReport(returns, self.sim_params)
total_months = years * 12
self.check_metrics(metrics, total_months, start_date)