Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
please help with backtest returns

Hi all, i need help please with the backtest return. How does backtest calculate the return? If I calculate the return on the notebook to buy an Apple share in early April 2012 and sell it in April 2014, I get a return of -4.5%. On the other hand, if I calculate the same strategy in the backtest, it gives me a return of -0.57%. What's going on?

Thank you!

2 responses

The backtest returns are simply the gain in portfolio value. The returns at a given time are portfolio_value_at_t - initial_capital / initial_capital. The 'portfolio_value_at_t' is the sum of all portfolio positions plus cash as of close on day t.

There are several primary reasons why the gains may be different.

  1. commissions
  2. backtests trade in whole shares
  3. backtests may not be fully invested (ie there is cash in the account)
  4. buy/sell prices include slippage and may be spread over the day
  5. dividends are not automatically reinvested in backtest

With such a big difference, the issue is probably a combination of 2 and 3. As an example, assume initial capital of $1000. One tries to buy XYZ and the price is $501. The backtest can only buy 1 share which will leave $499 in cash. Assume XYZ goes up 10% to $551.10. The notebook would show a 10% return. However, the backtest would show a return of ((551.10 + 499.00) - 1000) / 1000 which is about 5%. The 'return' is the portfolio return and not the stock returns.

Does that account for the difference you are seeing?

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Oh yes, now i understood my error, thanks you very much Dan!