Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Simple Mean Reversion-Leverage out of Control

Hey all, I am new to the community and I wanted to create my own version of the mean reversion strategy outlined in the final getting started video. Instead of using individual stocks, I used the 10 sector SPDRs with 10 and 200 day sma. Also, I wanted to eliminate the shorting aspect because it is unwise to short a sector etf in my opinion. The algo seemed to be tracking SPY until the leverage ran way out of control. Does anybody know how I can limit the leverage so It does not make huge jumps? EDIT: If possible, I would like to limit the leverage coefficient at 1.

2 responses

Hi, I do not now about any general solution. But I found the error in your code. When normalizing the portfolio weights, you did not sum the absolute values.

This will solve it:

normalized_weights = raw_weights / raw_weights.abs().sum()  

Thank you!