From 94e70a394bd502c6975292bbdc21480f047a86e4 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 27 Mar 2013 11:42:40 -0400 Subject: [PATCH] MAINT: Restricts dates to trading calendar in risk comparison test. Converts the risk iterative and batch comparison tests to use the trading environments next date, instead of just advancing by day, so that the returns being passed into the RiskMetrics in the unit test are using the same trading calendar as the internal checks for trading days. Fixes a case where empty return periods were being into `calculate_period_returns` Clearing the way for the pandas based optimization of the risk module. --- tests/test_risk_compare_batch_iterative.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/test_risk_compare_batch_iterative.py b/tests/test_risk_compare_batch_iterative.py index 2d1901e1..c6ad2701 100644 --- a/tests/test_risk_compare_batch_iterative.py +++ b/tests/test_risk_compare_batch_iterative.py @@ -44,30 +44,32 @@ class RiskCompareIterativeToBatch(unittest.TestCase): self.end_date = datetime.datetime( year=2006, month=12, day=31, tzinfo=pytz.utc) - self.oneday = datetime.timedelta(days=1) - def test_risk_metrics_returns(self): - risk_metrics_refactor = risk.RiskMetricsIterative(self.start_date) + trading.environment = trading.TradingEnvironment() + # Advance start date to first date in the trading calendar + if trading.environment.is_trading_day(self.start_date): + start_date = self.start_date + else: + start_date = trading.environment.next_trading_day(self.start_date) - todays_date = self.start_date + risk_metrics_refactor = risk.RiskMetricsIterative(start_date) + todays_date = start_date cur_returns = [] for i, ret in enumerate(RETURNS): + todays_return_obj = DailyReturn( todays_date, ret ) - cur_returns.append(todays_return_obj) # Move forward day counter to next trading day - todays_date += self.oneday - while not trading.environment.is_trading_day(todays_date): - todays_date += self.oneday + todays_date = trading.environment.next_trading_day(todays_date) try: risk_metrics_original = risk.RiskMetricsBatch( - start_date=self.start_date, + start_date=start_date, end_date=todays_date, returns=cur_returns )