Back to Community
Differences between Minute and Daily Backtests

Hello,
I was wandering why sometimes some of my algorithms result in huge gains on daily backtests and results in huge losses on minute backtests. Is there some way to modify the code to trade like in a daily backtest when in a minute backtest or when live trading.

#buys and sells 3X ETFs

# Put any initialization logic here.  The context object will be passed to  
# the other methods in your algorithm.  
def initialize(context):  
    context.stocks=[sid(32272), sid(39214), sid(32269), sid(39215), sid(32270), sid(38533), sid(32271), sid(39216), sid(33209), sid(33208), sid(39217), sid(38564), sid(37515)]  
# Will be called on every trade event for the securities you specify.  
def handle_data(context, data):  
    for stock in context.stocks: #this applies all within it to the stocks in context.stocks  
        if stock in data:  
            order_target_percent(stock,0.07692307692)  

Since I could only attach one backtest, I put up the minute one because it takes a while. Sorry I don't have a longer backtest.

Thanks,
Nick

5 responses

Hi Nick,

In backtests, orders are submitted in one bar and are filled in the next bar. In daily mode your algorithm receives data once per data at market close, so an order submitted on Monday at 4PM will get filled on Tuesday at 4PM. In minute mode, an order submitted at 10:00AM will get filled at 10:01AM, where there is much less movement in the price.

Daily mode is used to get a feel for your strategy, and I would recommend to use minute mode to continue developing and fine-tuning the algo. Minute mode is a better simulation of live trading with the broker and paper trading, where the data is received minutely by the algorithm. You can use schedule_function to schedule times when you want the algo to trade.

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.

Hello,
I seem to be facing the same problem. Any tips on how best can we hope to mimic the performance achieved in daily mode while scheduling ?
schedule_function(trade, date_rules.every_day(), time_rules.market_open(minutes=390)) or
schedule_function(trade, date_rules.every_day(), time_rules.market_open(minutes=1))

If you want to trade at the open of each day you can do:

 schedule_function(trade, date_rules.every_day(), time_rules.market_open(minutes=1))  

and if you want to trade at the close of the day:

 schedule_function(trade, date_rules.every_day(), time_rules.market_close(minutes=1))  

What about trading VWAP throughout the day, is there functionality to do that in minute mode?

@David

It is not natively available in the backtester, only IB live trading. To simulate VWAP in the backtester, you will need to write custom order execution such as executing 5% of your intended order size every minute, use fixed slippage settings, and remove minimum trade costs.