Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
modified "Simple Passive Momentum Trading with Bollinger Band"

All,

I modified the "Simple Passive Momentum Trading with Bollinger Band" strategy slightly. I am a little confused about how "Return" is calculated in Quantopian. I started with $1M, and I ended up with ~$6.6M in cash and $1.8M in stock value. So in total I have $8.4M in total, which is 840% increase comparing with the money I started. But the total return Quantopian calculated is 741%. Why there is such a difference? I didn't set commission in the model, so in commission fees are not calculated, right? Slippage is in the model but the total $8.4M should have taken slippage into consideration already, right? I appreciate it if someone can explain. Thanks.

-Peter

9 responses

Hello Huapu Pan,

Slippage (https://www.quantopian.com/help#ide-slippage) is simulated by default based on trading volumes - if you trade larger volumes than were actually being traded you will get partial fills. Commission (https://www.quantopian.com/help#ide-commission) of $0.03 per share in included by default and is reflected in the price at which your order is filled,

P.

Thanks, Peter. That is helpful.

Btw, where does this $0.03 per share come from? Is that what Interactive Broker charge? Does it depend on how much the stock price is per share, or is it flat $0.03 per share regardless of the stock price? Thanks.

-Huapu

Here is the link to IB's commission fees: https://www.interactivebrokers.com/en/index.php?f=commission&p=stocks2

Commissions for US equities are not dependent on the stock price.
For small volume trades the best assumption is probably the flat $1.00 min fee per trade. To apply that you'd use:

set_commission(commission.PerTrade(cost=1.00))

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.

I think the commissions discussion might be off the track from the original question - the calculation of the returns.

Returns, loosely defined, is your percentage gained. You started with $1M, you ended with $8.4M, That's a gain of $7.4M. $7.4/$1=740%. In your calculation, you were counting your original $1M as a gain, which it's not.

Back on the commissions - we have a default commission in the model, so your backtest includes the $.03/share. You can read about the default and how to modify it in the docs.

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.

Peter,

Does this only work for AAPL?  I can't get positive returns on anything else.

--Mike Sabeiha

This strategy works not as well on others. Using AAPL for backtesting can be quite misleading because if you buy and hold AAPL from 2003 you will have enormous return without any strategy. That is why I asked the question if we can modify Quantopian's benchmark to some strategy other than buy and hold S&P 500, but I haven't got any response yet. I usually do my backtest on SPY, not something like AAPL.

-Huapu

Hi Peter, why we don't try to use your algorithm on something like Dj futures/CFD?
Stocks are subjected to dividends, news, change on the board. Much better to trade derivatives based on index!
Send me a message if you can.

set_benchmark function changes the benchmark used

This is the result of the first back test.

Something went wrong. Sorry for the inconvenience. Try using the built-in debugger to analyze your code. If you would like help, send us an email.

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

There was a runtime error on line 36.