MAINT: Use pandas for volatility in risk metrics.

Continue on path of converting values stored inside of risk metrics
to use a DataFrame instead of storing multiple lists.

Also, the need for latest_dt in getting the current volatility for
the sharpe calculation, shows that we need to set the lastest_dt at
the beginning of the update loop.
This commit is contained in:
Eddie Hebert
2013-09-25 11:25:57 -04:00
parent 08bc42dc0c
commit cd3a63415c
2 changed files with 23 additions and 19 deletions
+7 -5
View File
@@ -150,18 +150,19 @@ class TestEventsThroughRisk(unittest.TestCase):
}
for bar in gen:
current_dt = algo.get_datetime()
current_dt = algo.datetime
crm = algo.perf_tracker.cumulative_risk_metrics
np.testing.assert_almost_equal(
crm.algorithm_returns[current_dt],
expected_algorithm_returns[current_dt],
crm.algorithm_returns[-1],
decimal=6)
np.testing.assert_almost_equal(
expected_sharpe[current_dt],
crm.metrics.sharpe[current_dt],
decimal=6)
expected_sharpe[current_dt],
decimal=6,
err_msg="Mismatch at %s" % (current_dt,))
def test_minute_buy_and_hold(self):
with trading.TradingEnvironment():
@@ -305,7 +306,8 @@ class TestEventsThroughRisk(unittest.TestCase):
"be one position after the first day.")
self.assertTrue(
np.isnan(crm.algorithm_volatility[-1]),
np.isnan(
crm.metrics.algorithm_volatility[algo.datetime.date()]),
"On the first day algorithm volatility does not exist.")
second_msg = gen.next()