Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Need help on this Magic Formula Investing code

Hi
This backtest is a a modified version of algorithm I found from a post around here. However, there's an error around Jun-Jul 2010 that the algorithm takes a very large position in particular stock, push the leverage to 8 - 10 times.I tried to experiment with order_target_value at 500$ but the error is still there. So, anybody know how to prevent this kind of error to happen? Maybe a code that check the maximum leverage before each trade. Or how to fix this in anyway?

Thank you everyone,
Nor