MAINT: Store sharpe values in a DataFrame instead of list.

Eventually, all cumulative metrics, (alpha, beta, etc.) will be
stored in the same DataFrame

For easier tracking of dt to values during debugging, but should be
some performance gains as well.
This commit is contained in:
Eddie Hebert
2013-09-19 15:52:53 -04:00
parent e4d298f3a0
commit 29a80c2f98
2 changed files with 13 additions and 4 deletions
+1 -1
View File
@@ -160,7 +160,7 @@ class TestEventsThroughRisk(unittest.TestCase):
np.testing.assert_almost_equal(
expected_sharpe[current_dt],
crm.sharpe[-1],
crm.metrics.sharpe[current_dt],
decimal=6)
def test_minute_buy_and_hold(self):
+12 -3
View File
@@ -92,7 +92,12 @@ class RiskMetricsCumulative(object):
self.algorithm_period_returns = []
self.benchmark_period_returns = []
self.sharpe = []
self.latest_dt = cont_index[0]
metric_names = ('sharpe',)
self.metrics = pd.DataFrame(index=cont_index, columns=metric_names)
self.sortino = []
self.information = []
self.beta = []
@@ -168,11 +173,15 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}"
self.algorithm_period_returns[-1] - self.treasury_period_return)
self.beta.append(self.calculate_beta())
self.alpha.append(self.calculate_alpha())
self.sharpe.append(self.calculate_sharpe())
self.metrics.sharpe[dt] = self.calculate_sharpe()
self.sortino.append(self.calculate_sortino())
self.information.append(self.calculate_information())
self.max_drawdown = self.calculate_max_drawdown()
# Keep track of latest dt for use in to_dict and other methods
# that report current state.
self.latest_dt = dt
def to_dict(self):
"""
Creates a dictionary representing the state of the risk report.
@@ -193,7 +202,7 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}"
'period_label': period_label
}
rval['sharpe'] = self.sharpe[-1]
rval['sharpe'] = self.metrics.sharpe[self.latest_dt]
rval['sortino'] = self.sortino[-1]
rval['information'] = self.information[-1]