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/

    resampling Pandas dataframe

    General Code/Help
    2
    5
    3817
    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.
    • Brad Lloyd
      Brad Lloyd last edited by

      not sure if anyone else has had trouble with loading data from a pandas dataframe and then using cerebro.resample, but we did. The dataframe for minute data loads find and then when I go to pass the dataframte to cerebro.resample I get nan values. if I use a csv it loads and resamples with no problems

      so we ended up using pandas own resample feature which works just fine

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

        If you can share an example it can for sure be looked into.

        Directly resampling with pandas is of course ok. The resampling in backtrader is there to keep the code the same across (for example) backtesting data and live data.

        1 Reply Last reply Reply Quote 0
        • Brad Lloyd
          Brad Lloyd last edited by backtrader

          not sure how to get the formatted code to paste

          startdate = datetime.datetime(2012, 1, 1)
          enddate = datetime.datetime(2013, 1, 3)
          def get_mstar_data(sym, startdate, enddate):
              s = startdate.year
              e = enddate.year
              df = None
              for i in range(s, e + 1):
                  for filename in glob.glob("%s/%d/%s*_1min.gz" % (m_star_cbot_path, i, sym)):
                      filedf = _create_df(filename)
                      filedf = filedf.ix[startdate:enddate]
                      print (len(filedf.index))
                      df = filedf if df is None else df.append(filedf)
          
          
          
              return mstar(
                  fromdate=startdate,
                  todate=enddate,
                  dataname=df,
                  name=sym,
                  datetime=None
          
              )
          
          
          data = get_mstar_data('ZC0Y', startdate, enddate):
          
          cerebro.adddata(data)
          cerebro.resampledata(data, name=ZC0Y15m, timeframe=bt.Timeframe.Minutes, compression=15)
          
          1 Reply Last reply Reply Quote 0
          • Brad Lloyd
            Brad Lloyd last edited by backtrader

            note we solved it by creating a new cerebro class that lets us do the following

            cerebro.add_feeds(startdate, enddate, portfolio_symbols, conflations)
            
            1 Reply Last reply Reply Quote 0
            • B
              backtrader administrators last edited by

              The code is clear but the actual problem you faced (at least on this side) is not yet clear.

              To format the code use the markdown conventions. The following will do:

              • Indent everything 4 spaces
              • Code contained in a block with opening and closing lines with: ```

              When you are writing a message there is a Compose ? link on the top right corner of the editing area. That will guide you to the full reference (which is here: commonmark.org)

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