Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Should order_target_percent(X, 1.0) sell all shares of non-X stock?
API

Yet another order_target_percent question, but this time it may not have to do with open orders! =)

If my portfolio starts out with 50% APPL and 50% NFLX, and i place an order_target_percent(symbol('AAPL'), 1.0), should the system implicitly sell ALL NFLX shares? This question goes for Live Trading with IB too since order_target_percent seems to make a single IB API call which then relies on IB's black magic to balance out the portfolio. This example question assumes the order is placed in the morning on a trade day, and no other orders are called that day.

I'm not seeing this NFLX sale happen, but it's possible that the orders are staying open for the whole day and then being cancelled at the end of day...leaving a few shares of NFLX remaining.

Similarly, if I started out with the same conditions above (50/50), and then placed an order_target_percent order for 25% each of INTL, CSCO, GOOG, and TSLA, should that then implicitly sell ALL APPL and NFLX to make room for these new stocks?

3 responses

I don't think it sells anything. See the backtest.

it randomly buys a stock everyday with order_target_percent(stock, 1.0) while recording positions.

You're right. Order_target_percent will only buy/sell shares of the specified stock, never anything else. So if your portfolio is worth $1 million and composed of 100% AAPL. Then the program runs order_target_percent(NFLX, 1.0) No shares of AAPL will be bought or sold, instead $1 million worth of NFLX (because that's 100% of your portfolio value) will be bought. Now the portfolio consists of $1 millions worht of AAPL AND $1 million of NFLX, and you are now leveraged 2x.

Order_target_percent never sells something to make room, instead it will add leverage.
EDIT: ^The adding leverage bit is only correct if you are ordering a stock you do not currently hold. If you do hold that stock and use Order_target_percent, the position size (of that stock only) will be adjusted accordingly. That may increase your leverage, decrease it, or do nothing at all. No stocks that aren't referenced in the order_target_percent will be affected any case.