Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
avoid leverage

Hi all,
How it is possible that the leverage will be bigger then 1 (cash<0) in the attached algo?
As I had read that the cause of this is the difference between prices between days, and the solution was to invest only 90% of the money (in line 113 to put 0.9 instead of 1.0) https://www.quantopian.com/posts/negative-cash
But it is not help, there is an idea?

And excuse me for English, it's not my first language.

Thanks.

2 responses

You are selling and buying stocks in the same minute, some trades take a while to go through. Order_target_percent() has no clue that you have already placed orders so it orders more than it should. The way to fix it is to separate the buying and selling logic. Execute the selling logic first and then at another time execute the buying logic with a check using "if get_open_orders(): return"

This uses track_orders to make that visible in the logging window. Clone, run, output.