Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Wrong Total Returns?

Hello,
I am new to Quantopian and to programming, but I have extensive trading experience. I coded a simple day trading strategy based on the simple moving average. If 20 min SMA> 50 min SMA, it puts 20% of my portfolio into the trade, Apple. If 50 min SMA> 20 min SMA, it closes out any positions I have in AAPL, and maintains no positions.

The problem is that when I run a full back test for the month of May, it shows a total return of -15.7%, but when i look at "Transactions Details", and visually see my trades and see the times it bought and sold and and what price, the loss shouldn't be drastic. In fact it may have a profit (I didn't calculate the exact P&L but looking at every day, I know my return would be a -15.7%). Any input or advice would be appreciated.

Thanks

5 responses

Returns for the amount put to work are actually worse than shown above because only 18% was spent.

A workaround here and more info. This contains a minimal version of those metrics. It helps to see clearly.

This code is in keeping with your strategy, you can add securities to context.stocks and adjust the numbers. Eventually be pulling context.stocks from pipeline (maybe 300+ of them), add shorting with an additional code block that just flips your existing logic since it appears to work, go for stability and zero beta and then you can enter such code in the contest.

Hi Dhruvin,

I think the unexpected losses are coming from commissions. The default commission model pays $1 minimum per trade, and this algorithm trades quite frequently. Since you are only trading one share per order, and only have the starting capital set to $1,000, the commissions have a big impact on the overall PnL.

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.

Thanks Jamie,

It solved the problem. I wrote a code and made commissions $0 and it worked out. Thanks very much for your help

Hi Blue,

Thanks for your input and writing out a code to help out the problem. Your code is really helpful and I plan on using your ideas once I become more proficient with Python.

Sure thing, and best of luck.
On commissions: To confirm, the original made $8 with commissions of $165 for the loss of $157.

The promised repost of backtest here with a correction where the extra code is a minimal version of a way to see what your stocks are doing regardless of how much is invested, it helps to see clearly. Like the links I provided above.

This code is in keeping with your strategy. You can add securities to context.stocks and try changing the numbers. Eventually think toward pulling context.stocks from pipeline (maybe 300+ of them), add shorting with an additional code block that just flips your existing logic since it appears to work ok, go for stability and zero beta and then you can enter such code in the contest.