Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Is there an error in my sample algorithm?

I am new to this forum, and having just created my first backtest of the sample algorithm, I am finding it hard to trust the results. Where is the error here?

3 responses

Hi Jack,

The backtester allows unlimited borrowing, if you don't constrain it (have a look at your cash balance). So, you are borrowing well in excess of your $10,000 initial capital to fund the trading.

Grant

As Grant said the sample algorithm borrows wildly as it has $1 million as the notional max and min.

I have modified your example to add a limit on buying power based on 50% account margin. I attached a backtest with the calculation. Feel free to steal the source code. Although I can't guarantee that it doesn't have bugs!

I had to increase the starting cash to $100k just because Apple has such a high price. But even so the results aren't spectacular :)

Oops, the logic in my original modification could be better. We don't need to check buying power if we are closing an existing position. Fixed!