mirror of
https://github.com/wassname/catalyst.git
synced 2026-10-28 12:51:29 +08:00
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:
1 parent
e4d298f3a0
commit
29a80c2f98
2 files changed
+13
-4
No files matched your search
@@ -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):
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
Reference in new issue
Block a user