Duration of backtests

Hello,
I'm new to the platform and am wondering if the backtests usually take a long time. Currently I have a strategy of 30 Long and 30 Short which changes every month, exits and rebalances. I buy on the first available trading day of the month. Backtesting a years worth of data takes about 2 hours, is this normal? Any help would be great!

Comments

  • ptunneyptunney Posts: 246
    edited April 2019

    The product was initially written as an intraday trading simulator and so is not tuned to run rapidly for daily (or monthly) backtests.
    As most of our internal trading is done on an intraday basis and thus fully executed and exited by the end of each day, the system is designed to be at its most efficient when a backtest is parallelized. So every day can run independently in parallel. However, all multiday strategies, by their nature, have to be run serially, the previous date has to complete before the next date can run. Hence backtesting systems designed for 'that' purpose are they are developed to run simply on daily bar data, in memory and thus very rapidly for that type of model.

    However, there are a number of things you could do to speed things up.
    First, if you are not using any intraday or complicated callbacks then make sure you set the backtest to fast mode (ie you are only using minute bar call backs, no timers, no trades, no quotes, no news etc). Fast is the default mode if you have not upgraded to Elite.
    If you know the dates that you want to rebalance on, put a list in is_symbol_qualified, if it is not one of those dates then return False for all symbols. That way it will rapidly skip past the other dates.

    from cloudquant.interfaces import Strategy
    
    class Backtest_date_check(Strategy):
        @classmethod
        def is_symbol_qualified(cls, symbol, md, service, account): 
            if symbol =="SPY":
                if service.time_to_string(service.system_time, format="%Y-%m-%d") in ["2019-01-02","2019-02-01","2019-03-01"]:
                    print "GO!"
                    return True
            return False
    
        def on_start(self, md, order, service, account):
            print "hello"
    

    You can run just on SPY as your qualified symbols and add your extra symbols into backtesting_symbols. You could then potentially get it down to one single callback per day (using just on_start), and do all your rebalancing in that one call back.

    Other than that I would need more detail on what exactly you are trying to do and how you are going about it. Feel free to email feedback@cloudquant.com for more private assistance.

  • tf591404tf591404 Posts: 10

    Thanks! It has sped up a bit thanks to your thoughts on dealing with symbols. Seems like their is no way around the on_minute_bar function as it is called for the whole trading day for all tickers involved. Also if the simulation takes longer than 4 hours will it be cut off?

  • ptunneyptunney Posts: 246

    Longer than 2 hours and it will be cut off...
    Try service.clear_event_triggers() in on_start then add back only the ones you want. Also, if what you are doing is once per month you can do it in on_timer or just in on_start, and run it 9:10 to 9:45 each day (if you are planning to do nothing else for the rest of the day).
    If you need to add back in events then you will need to add event to your import (see the red warning at the top of this docs page https://app.cloudquant.com/#/glossary/145).

  • @tf591404 what I found working most efficiently from SWE point of view is to put most of my logic inside on_strategy_start that is only called once a day, and do all the calculations there, then use on_start for each ticker to execute the trades. That in addition to the very helpful suggestion of having a very limited trading window using start_time and end_time (I also do that), combined with "fast" and "multiday". HTH

  • ptunneyptunney Posts: 246

    Yes @kc975943 even if your model trades both the open and the close you can still effectively put the backtester to sleep from 9:50 to 15:40 when submitting the backtest, thus skipping the processing of a large amount of the intraday trading.

Sign In or Register to comment.