Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Excuse my stupidity: What Happened? 8,000% gains??????

Excuse My stupidity but I'm totally new to this and suck at coding. This was the first thing I ever wrote in Quantopian. The program was originally supposed to buy a position when there was an upward trend and short when there was a downward trend. But instead there was an error and instead when there was a downward trend I bought more positions. Also a huge amount of the orders didn't go through. Again probably a stupid mistake but why would u be able to do this? Also why is the beta jump around anywhere from like 2 to 100? Does my algo somehow just do like a 1:1000 leverage? It for some reason doesn't even track the spy etf I'm using. There are lots of times where the etf drops yet my algo makes 100%.

3 responses

Because your code is inside the 'handle_data' function, you are placing orders every minute. The built in 'order_target_percent' function only looks at your current holdings in deciding how much to buy or sell. It doesn't take into account any outstanding, unfilled, orders.

If, for example, you placed an order for 40% of your portfolio to buy SPY using the 'order_target_percent' method, it may put in an actual order for say 40,000 shares. During the next minute, perhaps only 10,000 shares are actually bought. The remaining 30,000 are still open. Your program now places an order for 30,000 shares because it sees that 10,000 are now held. It doesn't look at outstanding orders so it 're-orders' 30,000 more shares. That cycle continues.

Eventually, all those orders may or may not fill but, in any case it's not what you probably intend. The huge gains are from the huge leverage your are creating. Quantopian will let you buy as much as you want. If you don't have the actual cash it 'lends' it to you and effectively create margin.

This comes up a lot (so you're not alone). Maybe take a look at this post https://www.quantopian.com/posts/strange-orders

thank you makes. a lot of sense now.

Hello Alex,
Something like this might help you:
for security in context.longs.index:
if get_open_orders(security):
continue
if data.can_trade(security):
order_target_percent(security, weight)