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/

    how to add data more quickly?

    General Code/Help
    1
    1
    51
    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.
    • K
      kang suheon last edited by

      I wanna test one strategy with multiple stock data and multiple time frame. So, I add multiple stock data as below.

      '''

      dataframe = pd.read_pickle(datapath+'daily_total.pickle')
      
      for i in items['code']: #3099
          dataframe = dataframe[dataframe['code'] == i]
      
          data_1 = bt.feeds.PandasData(dataname=dataframe,
                                       datetime='new_date',
                                       volume='vol')
      
          # Add the Data Feed to Cerebro
          cerebro.adddata(data_1)
          tframes = dict(
              daily=bt.TimeFrame.Days,
              weekly=bt.TimeFrame.Weeks,
              monthly=bt.TimeFrame.Months)
      
          cerebro.resampledata(data_1,
                               timeframe=tframes['weekly'],
                               compression=args.compression,)
      
          cerebro.resampledata(data_1,
                               timeframe=tframes['monthly'],
                               compression=args.compression
                               )
      

      '''

      and my strategy code is as below
      '''

      def next(self):
          if not self.position: # not in the market
              for i in range(len(self.datas)//3):
      
                  if cond_A and cond_B and cond_C and cond_D:
                      close = self.datas[i].close[0]
      
                      size = 1
      
                      self.buy(size=size)
      
                      self.log('BUY CREATE, %.2f' % self.datas[i].close[0])
      

      '''

      1. Is it right way to test?

      2. If it's right, how can i reduce execution time? I tried to add data in parallel, but it's fail.. (cerebro couldn't be rightly executed in parallel)
        I think, i can reduce time in (1) add data, (2) strategy(backtest).

      thank you for your watching. have a nice day!

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