Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Explanation of why results are so good

I am not sure how I have gotten a nearly 1000% yield in a year so I think my code is broken. Help please

5 responses

It looks like the algo keeps on buying shares even when you don't want it to. In this backtest I plotted the leverage used and it gets unrealistically high. You can prevent this using several different methods. I'll post a backtest that gives an example

In this version, your trading logic is only executed once a day. This keeps the leverage at 1.

It's my first time using Quantopian, so I'm not really sure about this, but it looks like your cash is negative. Maybe, transactions takes some minutes to be done, so you keep buying shares, and when all the orders get executed your cash becomes negative. And because the performance is based on your initial capital, you get such a good performance.
When running this daily, your cash get updated before you can place a new order, and you get more reasonable results.

Here are the results by using a auxiliary cash variable.
But the regular cash variable still have a weird step behaviour I don't understand

One problem is on the level of a typo, order(context.security, 0) where you intended to sell, it would buy or sell 0, oops, use order_target(context.security, 0) or order_target_percent(context.security, 0).
And then it looks like SPYG is thinly traded, lots of partial fills (both buy and sell).