-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
-
To my naive eyes, it looks like Alpha and Beta aren't calculated correctly. I did a test where I just buy and hold the equity, and the Beta (which should measure correlation to the underlying) was basically 0 (0.02) and Alpha was some large number proportional to my total return %. I would think that just buy and hold would result in a Beta close to 1, and an Alpha close to 0, but maybe I'm not understanding this correctly?
I see on the README.md, the example also shows this phenomenon.
Any answers are much appreciated
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 1 reply
-
Hi ,
In the code, it using different approach of the calculation of alpha, and beta which are not the same as normal definition of the Alpha and beta. Below are the code in _stats.py
equity_log_returns = np.log(equity[1:] / equity[:-1])
market_log_returns = np.log(c[1:] / c[:-1])
beta = np.nan
if len(equity_log_returns) > 1 and len(market_log_returns) > 1:
# len == 0 on dummy call `stats_keys = compute_stats(...)` pre optimization
cov_matrix = np.cov(equity_log_returns, market_log_returns)
beta = cov_matrix[0, 1] / cov_matrix[1, 1]
# Jensen CAPM Alpha: can be strongly positive when beta is negative and B&H Return is large
s.loc['Alpha [%]'] = s.loc['Return [%]'] - risk_free_rate * 100 - beta * (s.loc['Buy & Hold Return [%]'] - risk_free_rate * 100) # noqa: E501
s.loc['Beta'] = beta
As you can see, If beta close to zero, Alpha will close to the total return %.
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.