Back to Community
Adustable Timeframe Algo

Does anyone have an example of an algo that uses a different timeframe, for example 15 minute or 30 minute bars instead of 1 minute bars?

I've seen some proof of concept code snippets in the threads but not a working algorithm. I've also tried using the resample method but am running into issues with that because handle_data is still being called on every minute.


2 responses

Hi Chris,

Take a look at the code for the backtest I posted here, I think it might help you out. Let me know if this is what you were looking for.


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.

Hi Chris,

I use the below template to create a adjustable timeframe. Since I haven't figure out how to use the resample function for intraday data, I maintained my own variable in context.container. Please have a look at the sample algorithm attached:

  1. It maintains the most current bar in context.container. I am sure there are better solutions than mine.
  2. It calls the process function every 30 minutes.
  3. Meanwhile it will can intra_interval_process every minute.

Please read the log output for more info.

Clone Algorithm
Backtest from to with initial capital
Total Returns
Max Drawdown
Benchmark Returns
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 560071ba3c5fb00e10ce46b7
There was a runtime error.