Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
What time of the day the handle_data() in the IDE is executed in daily mode?

I guess the title explains my question. When I run the IDE in daily (or minute) mode, I wonder what time of the day (or minute) the function handle_data() is executed. Does the code run at the closing of the day (or minute) or some other time, such as the time when I press backtest button and repeating exactly every 24 hours (or 1 minite)?

Thanks and happy holidays.

4 responses

Hi gi,

In daily mode, handle_data runs at the close of each day. In general, daily is nice for having quick backtests, but you can reproduce the functionality if you run a backtest in minute mode and use the schedule_function() method to run a function once at the end of each day. This is better practice as it can be translated to live trading.

I hope this helps and happy holidays to you too!

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 for your answer and tip. I am kind of novice at this site as well as trading world. You recommend to run in minute mode and run the scheduled function once at the end of each day. Then what would you do at each minute when I run in minute mode while I run the scheduled function only once a day? Thanks in advance and Happy Christmas!

The backtester mode signifies how often you get new market data. Daily mode means once per day (at market close) and Minute mode means every single minute. In the backtester, you place an order in one bar and it gets filled in the next bar (according to the slippage model). If an algo is running in daily mode, an order is submitted at market close of one day (ie Monday) and filled at market close the next day (ie Tuesday). This leaves a gap of 24 hrs of price movements in the simulation.

The better route is to always run your backtest in minute mode, as Jamie suggested. However, this doesn't mean your algo has to trade every single minute. You can use schedule_function to indicate when the algo trades. This lets the algo trade once per day at market close, and fills at the next day's open (the next minute bar), instead of waiting until the next day's close price.

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 a lot Alisa for clarification - it really helps me getting started.