Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Why is backtesting speed very slow?

    General Code/Help
    3
    7
    2386
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z
      Zeroc last edited by

      This is my code :

      class SmaCross(bt.SignalStrategy):
          def __init__(self):
              sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
      
      cerebro = bt.Cerebro()
      cerebro.addstrategy(SmaCross)
      
      dataframe = pd.read_csv(r'D:\aaa.csv', index_col=0, parse_dates=True)
      print(dataframe)
      
      dataframe['openinterest'] = 0
      data = bt.feeds.PandasData(dataname=dataframe,
                              fromdate = datetime(2015, 1, 1),
                              todate = datetime(2016, 12, 31)
                              )
      cerebro.adddata(data)
      start = datetime.now()
      cerebro.run()
      stop = datetime.now()
      print(stop-start)
      cerebro.plot()
      

      The total processing time is 15 mins 50 sec ,
      What settings should I make to speedup ?

      Thanks.

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @Zeroc last edited by

        @zeroc said in Why is backtesting speed very slow?:

        What settings should I make to speedup ?

        • Probably you want to reduce your dataset to the actual data you are processing

        If not, then Python is the wrong choice for you.

        Z 1 Reply Last reply Reply Quote 0
        • Z
          Zeroc @backtrader last edited by

          @backtrader
          Thanks reply ,
          I find this thread how-to-speed-up-backtest

          the dataset he used is 6 months , and he takes 96 seconds to run , but my dataset is one years and taks 15 mins . that's crazy...

          I don't know what caused this difference in time.

          B 1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators @Zeroc last edited by

            @zeroc said in Why is backtesting speed very slow?:

            the dataset he used is 6 months , and he takes 96 seconds to run , but my dataset is one years

            To start with you have a start and end dates which are 2 years apart and not 1 year.

            @zeroc said in Why is backtesting speed very slow?:

            data = bt.feeds.PandasData(dataname=dataframe,
                                    fromdate = datetime(2015, 1, 1),
                                    todate = datetime(2016, 12, 31)
                                    )
            

            But the fact that those dates are 2 years apart doesn't mean that the actual source dataset may not contain 100 years.

            Furthermore, even if your dataset is 2 years long, it may contain 1-second bars, which doesn't yield the same numbers of bars as if you have 1-day

            Running through 2 years of daily bars is a decent computer with 2 simple moving averages takes well under 1 minute.

            greg nwosu 1 Reply Last reply Reply Quote 0
            • greg nwosu
              greg nwosu @backtrader last edited by

              @backtrader i think its the plotting, i experience very slow performance when producing plots

              1 Reply Last reply Reply Quote 0
              • B
                backtrader administrators last edited by

                1. backtrader is not a charting platform and charting is only meant as a visual feedback/aid.
                2. matplotlib: https://matplotlib.org/
                greg nwosu 1 Reply Last reply Reply Quote 0
                • greg nwosu
                  greg nwosu @backtrader last edited by

                  @backtrader sorry i LOVE backtrader, im not really experiencing performance issues anymore, made backtrader run with python=3.7.3 , instead of python 3.5 as recommended on the compatibility list. And now my plotting is fine.

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors