Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Function continuation between time intervals or trade events

Hello,

New to the IDE. Can someone explain (or link me) to how we can:

  1. Either: save data so that it doesn't need to be retrieved and recalculated after every time interval or trade event or pass data between time intervals.
  2. Perform computationally expensive calculations. Can we code in logic to to have a function continue until some calculation is done? Or will it be automatically terminated at the end of the time interval, regardless of it is done?

Any help on this is appreciated.

Thanks,
Alexander

1 response

Alex, welcome to Quantopian! To answer your questions:

  1. You can save state by using context. This will pass the data between functions and between bars in a backtest( ie time intervals). Here is the documentation: https://www.quantopian.com/help#ide-api

  2. What kind of computation are you trying to do? Are you running parameter optimization? If so this should be done in research to tune your variables. In general, the research environment is used to explore the data, run custom analyses, and tune your parameters. Then you can code the details of your algo in the IDE and test.

Here are a few examples of parameter optimization:

https://www.quantopian.com/posts/research-do-you-want-parameter-optimization-click-here-to-get-started-heat-maps-included
https://www.quantopian.com/posts/sensitivity-analysis-aka-parameter-optimization-of-pair-trade-input-parameters

The functions in the IDE run in this order: initialize(), before_trading_start(), handle_data(), schedule_function(). The function before_trading_start() has 5 minutes to update its universe and query for the stocks to trade. Then handle_data() has ~50 seconds to run the computations. It's not possible to pause while another calculation has finished running, but I'm curious, are you running into timeout issues? Or will the research environment help?

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.