Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How does order target percent on negatives work?

Also how do shorts work in general, (on Quantopia) what is the time frame. It seems there's a lot of automatic trading that takes place that I don't have a complete handle on. I worked for many hours one night only to see that my order_target_percent ('stock' -value) was purchasing stock, why does that happen?

1 response

When you run order_target_percent with a negative value, you are taking a short position. It means you are selling a stock you don't have yet (you borrow the stocks) but you have to give it back eventually (the stocks, not the money).

Once order_target_percent is executed, you get the money for the selling (context.portfolio.cash increases) but the "borrowing" is recorded in your context.portfolio. The stock that you sold (without having it) is recorded with a negative amount (context.portfolio.positions['stock'].amount). At this point you have a "debt" whose value depends on the current value of the stocks. When, later on, you buy that stock to compensate the negative amount in the portfolio, your debt is paid back: you don't see the stock in your portfolio anymore, but your cash are updated to reflect the purchase (context.portfolio.cash decreases).
You might make money or lose money depending on the difference between stock value at the time of selling it and buying it back.

See here: https://www.quantopian.com/posts/a-few-questions-on-short-selling-and-sell-orders