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

Hi, my code is generating shorts when I want to go long only. I am new to quantopian (just a few days)... Any help would be very appreciated. I am using the order_target_percent. However when the portfolio already has a position of an equity close to 100% and then next month want it to drop to 25%, i am getting a short position while using order_target_percent

Here is my backtest id 59b2f4c35eb40950e8e8a2d0.

Thanks

2 responses

Sanjay,

There is a relatively new API called the Optimize API, which is recommended instead of order_target_percent:

https://www.quantopian.com/posts/optimize-api-generally-available
https://www.quantopian.com/posts/optimize-api-required-for-allocations

You can add a constraint to keep the leverage in check.

Thanks Grant. That worked great! Thanks for the quick response.