From 2314e8a28174d5b750e2351555c7df77b51453d1 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Fri, 19 Jul 2013 20:28:12 -0400 Subject: [PATCH] TST: Read benchmark variance from answer key. Add reference to updated answer key with benchmark variance cells, and use the new cells as the reference for the benchmark variance test. The values changed from the original hardcoded values, due to the change to close over close benchmarks. --- tests/risk/answer_key.py | 7 ++++ tests/risk/risk-answer-key-checksums | 1 + tests/risk/test_risk.py | 60 +++++++++++----------------- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/tests/risk/answer_key.py b/tests/risk/answer_key.py index 905969c1..8a0449a7 100644 --- a/tests/risk/answer_key.py +++ b/tests/risk/answer_key.py @@ -166,6 +166,13 @@ class AnswerKey(object): 'year': DataIndex('Sim', 'AG', 34, 34), } + ALGORITHM_PERIOD_BENCHMARK_VARIANCE = { + 'Monthly': DataIndex('Sim', 'BB', 23, 34), + '3-Month': DataIndex('Sim', 'BC', 25, 34), + '6-month': DataIndex('Sim', 'BD', 28, 34), + 'year': DataIndex('Sim', 'BE', 34, 34), + } + def __init__(self): self.workbook = xlrd.open_workbook(ANSWER_KEY_PATH) diff --git a/tests/risk/risk-answer-key-checksums b/tests/risk/risk-answer-key-checksums index 9856db9a..8c0f9c51 100644 --- a/tests/risk/risk-answer-key-checksums +++ b/tests/risk/risk-answer-key-checksums @@ -1,2 +1,3 @@ 3ac0773c4be4e9e5bacd9c6fa0e03e15 3a5fae958c8bac684f1773fa8dff7810 +19d580890e211a122e9e746f07c80cbc diff --git a/tests/risk/test_risk.py b/tests/risk/test_risk.py index d62f789f..7f4ad84a 100644 --- a/tests/risk/test_risk.py +++ b/tests/risk/test_risk.py @@ -469,48 +469,36 @@ class TestRisk(unittest.TestCase): for x in self.metrics_06.year_periods], [-8.75273E-06]) - def dtest_benchmark_variance_06(self): - self.assertEqual([round(x.benchmark_variance, 7) + def test_benchmark_variance_06(self): + answer_key_month_periods = ANSWER_KEY.get_values( + AnswerKey.ALGORITHM_PERIOD_BENCHMARK_VARIANCE['Monthly'], + decimal=7) + self.assertEqual([np.round(x.benchmark_variance, 7) for x in self.metrics_06.month_periods], - [0.0000496, - 0.000036, - 0.0000244, - 0.0000332, - 0.0000623, - 0.0000989, - 0.0000765, - 0.0000209, - 0.0000252, - 0.0000194, - 0.0000292, - 0.0000183]) + answer_key_month_periods) - self.assertEqual([round(x.benchmark_variance, 7) + answer_key_three_month_periods = ANSWER_KEY.get_values( + AnswerKey.ALGORITHM_PERIOD_BENCHMARK_VARIANCE['3-Month'], + decimal=7) + self.assertEqual([np.round(x.benchmark_variance, 7) for x in self.metrics_06.three_month_periods], - [0.0000351, - 0.0000298, - 0.0000395, - 0.0000648, - 0.0000773, - 0.0000625, - 0.0000387, - 0.0000211, - 0.0000238, - 0.0000217]) + answer_key_three_month_periods) - self.assertEqual([round(x.benchmark_variance, 7) - for x in self.metrics_06.six_month_periods], - [0.0000499, - 0.0000538, - 0.0000508, - 0.0000517, - 0.0000492, - 0.0000432, - 0.00003]) + answer_key_six_month_periods = ANSWER_KEY.get_values( + AnswerKey.ALGORITHM_PERIOD_BENCHMARK_VARIANCE['6-month'], + decimal=7) + results_six_month_periods = [ + np.round(x.benchmark_variance, 7) + for x in self.metrics_06.six_month_periods] + self.assertEqual(results_six_month_periods, + answer_key_six_month_periods) - self.assertEqual([round(x.benchmark_variance, 7) + answer_key_year_periods = ANSWER_KEY.get_values( + AnswerKey.ALGORITHM_PERIOD_BENCHMARK_VARIANCE['year'], + decimal=7) + self.assertEqual([np.round(x.benchmark_variance, 7) for x in self.metrics_06.year_periods], - [0.0000399]) + answer_key_year_periods) def test_benchmark_returns_08(self): returns = factory.create_returns_from_range(self.sim_params08)