Could someone from Quantopian finally explain to me how you calculate Beta? I've asked multiple times and never got an answer.
Could you at least confirm or decline the following:
1. Are you calculating Beta of the performance of the whole portfolio by taking change in portfolio_value and comparing it against the change of spx? or
2. Are you calculating Beta by summing/subtracting Beta values of each portfolio position during entering/exiting the trade multiplied by each position weight?
If 2: that would be proper in my opinion, as we want full hedge (Beta=0) on entering the trade and max/min Beta on exiting it.
However, I do feel Quantopian is using 1.
I did find the code on GitHub for Alpha, Beta: in statistical.py
def regress(y, x): regr_results = linregress(y=y, x=x) # `linregress` returns its results in the following order: # slope, intercept, r-value, p-value, stderr alpha[i] = regr_results beta[i] = regr_results ...
Yes, this is correct assuming position and hedge are using and will be using the same Beta. Like in case we invested in SPX long and short in the same amount. Then when SPX moves 10% up our long leg increases by 10% and short drops by 10%, however weights are equally increases and decreases proportionally to 10% therefore, as the result Beta of the whole portfolio stays the same at 0.
However, look at the following case: we have an algorithm that generated 1 week event to invest in fully hedged portfolio as there is a signal that SPX will strongly move up while TIP will stay the same during that 1 week. As SPX (Beta=1) and hedge TIP with Beta=-0.128, we created fully hedged portfolio with weights of SPX=1/1=1. and weight of TIP=1/0.128=-7.81. So overall Beta of portfoilo=1*1-7.81*0.128=0
Lets assume that everything has happened as algorithm predicted and in a week SPX moved 10% up, while TIP didn't move at all.
So, portfolio weight of SPX now is 1.1 while weight of TIP is still 7.81. As Betas of SPX is still 1 and TIPs 7.81 we now have full portfolio Beta at: 1*1.1-7.81*0.128=1.1-1=0.1
As you can see: Beta obviously moved and the higher it will move the more Alpha will be generated.
To fight that move would be to rebalance the portfolio more frequently, but who wants that?