Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
losing all funds immediately in backtest

Hello all, I'm fairly new to quantopian and to coding in general.
For some reason whenever I go to backtest, my cash will fall off to -95.5% total returns extremely rapidly, and by that I mean that my algorithm experiences zero gains. Any idea what could be causing this to happen?

Edit: re-ran my test with daily data and I'm not getting an exponential drop-off like with the minute data. I've attached a sample of my minute data.... and I guess my code too.

5 responses

One AM was a bad time to post my question. It's my first algorithm so I'm open to any feedback.

Hello John,
This is a fairly common mistake. Ctrl+f the keywords: "slippage" and "commission" in the Help and API docs. When you don't specify a slippage or commission the default will set one for you. In your case, the algo is making a tremendous amount of trades, and your principal is only 1k, so the trading commission fees and slippage are eating up your profits AND principal. Add this code to the initialize function and you should be ok, but realize that you will have to deal with slippage and commissions IRL.
set_commission(commission.PerTrade(cost=0.0))
set_slippage(slippage.FixedSlippage(spread=0.00))

Thanks a ton! Will this affect my algorithm if submitted for a contest or used for trades on quantopian, since they utilize free trades?

John,
You will not be able to submit the algo to the contest including those 2 lines. The contest rules stipulate that you MUST use the default commission and slippage which means your first algo would be acceptable in the contest and your second with my added suggestions would not be. Conflicts will arise often if you try to make an algo suitable for your own investing purposes and for the contest at the same time. Volume liquidity, slippage, commissions, desirable beta, drawdown and optimal returns to name a few, are some of the areas where goals will conflict.

Hi John,

I think I figured out what was going on with your algorithm. It seems that you commission per trade was nonzero, and your algorithm was executing a large volume of trades, bringing down your returns by a significant percentage every tick. I added a line that sets commissions to zero, and I used the "order_target_percent" method to make sure that shorting never occurs.

-Lota

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.