Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Backtesting Question

So I have a question about back testing:

Scenario 1: I wrote some code, and selected the time period and $200,000 to trade. In the back testing YTD I get a result of over 700%.

Scenario 2: What I want to do is diversify the risk over five stocks at $200,000 each. So I increased the amount to test against to $1,000,000 and then added:
order_target_percent(context.stockname1, 0.2)
If I understand the tutorial section on this, this would give me $200,000 for that stock to test against. When I run the back test for the same dates and only this stock, it gives me returns of around 240%.

Shouldn't the returns be somewhat closer to each other and track a roughly similar path given that I am trading the same stock, the same value and the same time period?

Thanks for any insights!

2 responses

The returns are the returns of the entire portfolio and not simply one stock. Here's an example.

Scenario 1: buy $200,000 of stock1 starting with a portfolio cash balance of $200,000. Final gain is 700%. This implies that the actual dollar gain for stock 1 must have been $1,400,000 and the final portfolio value is $1,600,000.

$1,400,000 / $200,000 = 7   (700%)

Scenario 2: buy $200,000 of stock1 starting with a portfolio cash balance of $1,000,000. The actual dollar gain for stock 1 is the same $1,400,000. However the portfolio gain is only 140%.

$1,400,000 / $1,000,000 = 1.4   (140%)

What you are seeing is the impact of a lot of cash sitting in your portfolio not making any money. It drags down the total return of the stock+cash portfolio.

Not sure why you see about 240%. You must be doing some trades other than a simple buy and hold? The compounding and timing of those trades impact the total return. (eg $10,000 made early and then reinvested grows to more than $10,000 made the last day of the backtest).

Dan - thank you! That makes sense.