From 39038131dbd62222a717240f7176f8ccc9023b5c Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 3 Apr 2013 15:03:20 -0400 Subject: [PATCH] MAINT: Remove saving of treasury duration. The treasury_duration member in RiskMetrics is never used except for in unit tests. Remove the saving of treasury_duration in preparation for the move of the choose_treasury method out of the RiskMetrics classes. Down the line, if we do restore the sanving of treasury_duration, choose_treasury can return a tuple that includes treasury_duration instead of just returning the rate. --- tests/test_risk_compare_batch_iterative.py | 6 ----- zipline/finance/risk.py | 28 +++++++++++----------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/tests/test_risk_compare_batch_iterative.py b/tests/test_risk_compare_batch_iterative.py index 4de3fab3..7ae27d86 100644 --- a/tests/test_risk_compare_batch_iterative.py +++ b/tests/test_risk_compare_batch_iterative.py @@ -88,12 +88,6 @@ class RiskCompareIterativeToBatch(unittest.TestCase): self.assertEqual( risk_metrics_original.end_date, risk_metrics_refactor.end_date) - self.assertEqual( - risk_metrics_original.treasury_duration, - risk_metrics_refactor.treasury_duration) - self.assertEqual( - risk_metrics_original.treasury_curve, - risk_metrics_refactor.treasury_curve) self.assertEqual( risk_metrics_original.treasury_period_return, risk_metrics_refactor.treasury_period_return) diff --git a/zipline/finance/risk.py b/zipline/finance/risk.py index ff1bb383..2498f6f4 100644 --- a/zipline/finance/risk.py +++ b/zipline/finance/risk.py @@ -429,32 +429,32 @@ class RiskMetricsBase(object): def choose_treasury(self, start_date, end_date): td = end_date - start_date if td.days <= 31: - self.treasury_duration = '1month' + treasury_duration = '1month' elif td.days <= 93: - self.treasury_duration = '3month' + treasury_duration = '3month' elif td.days <= 186: - self.treasury_duration = '6month' + treasury_duration = '6month' elif td.days <= 366: - self.treasury_duration = '1year' + treasury_duration = '1year' elif td.days <= 365 * 2 + 1: - self.treasury_duration = '2year' + treasury_duration = '2year' elif td.days <= 365 * 3 + 1: - self.treasury_duration = '3year' + treasury_duration = '3year' elif td.days <= 365 * 5 + 2: - self.treasury_duration = '5year' + treasury_duration = '5year' elif td.days <= 365 * 7 + 2: - self.treasury_duration = '7year' + treasury_duration = '7year' elif td.days <= 365 * 10 + 2: - self.treasury_duration = '10year' + treasury_duration = '10year' else: - self.treasury_duration = '30year' + treasury_duration = '30year' end_day = end_date.replace(hour=0, minute=0, second=0) search_day = None if end_day in self.treasury_curves: rate = get_treasury_rate(self.treasury_curves, - self.treasury_duration, + treasury_duration, end_day) if rate is not None: search_day = end_day @@ -468,7 +468,7 @@ class RiskMetricsBase(object): i = bisect.bisect_right(search_days, end_day) for prev_day in search_days[i - 1::-1]: rate = get_treasury_rate(self.treasury_curves, - self.treasury_duration, + treasury_duration, prev_day) if rate is not None: search_day = prev_day @@ -482,7 +482,7 @@ class RiskMetricsBase(object): {dt} and term = {term}. Using {search_day}. Check that date doesn't exceed \ treasury history range." message = message.format(dt=end_date, - term=self.treasury_duration, + term=treasury_duration, search_day=search_day) log.warn(message) @@ -494,7 +494,7 @@ treasury history range." that date doesn't exceed treasury history range." message = message.format( dt=end_date, - term=self.treasury_duration + term=treasury_duration ) raise Exception(message)