Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Nonsensical result from order_target_percent

To the best of my understanding, order_target_percent should set a holding of particular security to a given target, say 50% of portfolio in AAPL. That being said, I created a simplest of algorithms that holds one security, SVXY in this case, at 50% of the portfolio value, rebalancing that 50% every day. When backtested, the algorithm trades like mad, into trillions of dollars of nonsensical trades, instead of rebalancing it swings the portfolio by millions a day.

Am I missing something here, or is the order_target_percent() implementation to blame?

3 responses

Keep in mind that order_target_percent() does not manage open orders. I added a check in the attached code. --Grant

It's not the function itself, it's that the order_target style functions do not account for open orders and the backtesting engine simulates slippage so sometimes orders don't fill within one bar. Ordering when previous orders have not filled yet is what is making it go nuts.

Here's the same example but it won't rebalance until all open orders have been filled.

Grant, you beat me to it!!

David,
I see this kind of posts ever other day.
Why not to incorporate one of this

if not get_open_orders():

if get_open_orders(sid=context.only_holding):  
        return

if not sid in get_open_orders().keys():  

into order_target function?