ENH: Use annualized returns for beta and alpha.

So that the units match the other risk calculations, also
use annualized returns for beat and alpha.

Update answer key to match values calculated on the first day.

Also, update performance tracker test so that the returns used
are fractional instead of > 1, so that the annualized numbers are
more in line with real world values.
This commit is contained in:
Eddie Hebert
2013-10-11 00:27:03 -04:00
parent dad34d2ddb
commit 1bad245675
3 changed files with 23 additions and 7 deletions
+16
View File
@@ -94,3 +94,19 @@ class TestRisk(unittest.TestCase):
value,
decimal=2,
err_msg="Mismatch at %s" % (dt,))
def test_alpha_06(self):
for dt, value in answer_key.RISK_CUMULATIVE.alpha.iterkv():
np.testing.assert_almost_equal(
self.cumulative_metrics_06.metrics.alpha[dt],
value,
decimal=2,
err_msg="Mismatch at %s" % (dt,))
def test_beta_06(self):
for dt, value in answer_key.RISK_CUMULATIVE.beta.iterkv():
np.testing.assert_almost_equal(
self.cumulative_metrics_06.metrics.beta[dt],
value,
decimal=2,
err_msg="Mismatch at %s" % (dt,))
+2 -2
View File
@@ -1208,7 +1208,7 @@ class TestPerformanceTracker(unittest.TestCase):
commission=0.50)
benchmark_event_1 = Event({
'dt': start_dt,
'returns': 1.0,
'returns': 0.01,
'type': DATASOURCE_TYPE.BENCHMARK
})
@@ -1218,7 +1218,7 @@ class TestPerformanceTracker(unittest.TestCase):
'bar', 11.0, 20, start_dt + datetime.timedelta(minutes=1))
benchmark_event_2 = Event({
'dt': start_dt + datetime.timedelta(minutes=1),
'returns': 2.0,
'returns': 0.02,
'type': DATASOURCE_TYPE.BENCHMARK
})
+5 -5
View File
@@ -463,9 +463,9 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}"
"""
http://en.wikipedia.org/wiki/Alpha_(investment)
"""
return alpha(self.algorithm_period_returns[self.latest_dt],
return alpha(self.annualized_mean_returns[self.latest_dt],
self.treasury_period_return,
self.benchmark_period_returns[self.latest_dt],
self.annualized_benchmark_returns[self.latest_dt],
self.metrics.beta[dt])
def calculate_volatility(self, daily_returns):
@@ -488,11 +488,11 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}"
"""
# it doesn't make much sense to calculate beta for less than two days,
# so return none.
if len(self.algorithm_returns) < 2:
if len(self.annualized_mean_returns) < 2:
return 0.0
returns_matrix = np.vstack([self.algorithm_returns,
self.benchmark_returns])
returns_matrix = np.vstack([self.annualized_mean_returns,
self.annualized_benchmark_returns])
C = np.cov(returns_matrix, ddof=1)
algorithm_covariance = C[0][1]
benchmark_variance = C[1][1]