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

Hi there everyone

GEtting back into Quantopian as i moved into the BTC industry for a while.

I'm curious to know about how QP settings work for backtesting. When i set a value of say $1000 initial capital, and data frequency to say "daily", am i starting with ONLY 1k?

In other words, if week 1 i earn 0%, week 2 I'll still be sitting on 1k? Or do we add capital to the algorithm on a set term(weekly/daily)?

Also i noticed data frequency is only giving daily or minute, do we not allow weekly or hourly?

3 responses

The backtester setting (daily/minute) is the frequency of data your algo receives. I strongly recommend always running on minute backtesting for more granular data. For a more detailed explanation, see here: https://www.quantopian.com/posts/differences-between-minute-and-daily-backtests

This doesn't mean you need to trade every minute or every day. You can trade at any interval. For example, you can trade weekly while running a minute-level backtest. To do so, use schedule_function to arrange your trades.

The initial capital is the amount of money your algo starts with. If you set $1k, then the algo will only have $1k in cash. The portfolio value will grow/shrink based on your algo's performance. You don't need to add capital to the algo at a regular interval (in fact, this isn't possible).

You can record any of your portfolio attributes to track the changes.

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.

Awesome! Thanks for the detailed information!

Exactly what i was looking for!

Last question, during backrest, is there anyway to indicate a complete loss of portfolio capital? Meaning if my algo continues to buy at a high, sell low, I'd eventually run out of funds, how does the back test engine handle this? Say it trades on a minute by minute basis, for a week and at the end of the week the value is 0, but my timeline for the test is say 6months, will the backtest finish prematurely?

Sure, you can track the context.portfolio.portfolio_value object: https://www.quantopian.com/help#api-portfolio

You can check if this value is above X, and if so, then execute more trades. In the backtester, there are no margin settings, so it will let you borrow an infinite amount of money. Of course, your broker won't let you do this in the real world :)

To prevent your algo from excessive borrowing, try using the order_target_* functions. These are smart to tune towards your portfolio amount and will grow/shrink the target amounts with your portfolio size.