Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
101 Alphas Project Alpha 34

This is my implementation of alpha 34. The ranking is done through just assigning each stock a weight from 0 to 1 ,and all the combined weights will equal up to 1. I'm not sure why it dropped off a cliff at the very end of the test.

edit:
Updated backtest to reflect the recommended changes advised by @Vladimir ,and @Tentor Testivis.
Works a lot better now

3 responses

Line 115
try to replace

combined_alpha = alphas["alpha_34"] / len(alphas["alpha_34"])  

to

combined_alpha = alphas["alpha_34"] / abs(alphas["alpha_34"]).sum()  

@Vladimir Will do other than that does everything look correct

Well, subtracting from 1 isn't really ranking. Since you already imported stats from scipy you might as well use it for this:

            returns_rank = stats.rankdata(returns_std)  

and

            close_delta_rank = stats.rankdata(np.nan_to_num(close_delta))  

To get the result for alpha 34 you should change the cd_ret_rank to something like this:

            cd_ret_rank = stats.rankdata((1 - returns_rank) + (1 - close_delta_rank))  

But I have to say this alpha doesn't make much sense to me. Take the close delta: say you have 2 stocks, one is traded at $ 10 and the other at $ 1,000 on the second last close. Now both have a close $ 5 higher than before ($ 15 and $ 1,005), then they would get the same rank even though the first is up 50 % and the second only 0.5 %