Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Help me understand Alpha and Beta #1269

dinorocks started this conversation in General
Discussion options

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

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

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 %.

You must be logged in to vote
1 reply
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /