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/

    Error extending pandas datafeed example

    Indicators/Strategies/Analyzers
    2
    3
    49
    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.
    • lorrp1
      lorrp1 last edited by

      Hello, im trying to use a custom dataframe with columns:

      Open          High           Low         Close    volume  quote_asset_volume  number_of_trades  \ taker_buy_base_asset_volume  \taker_buy_quote_asset_volume  p0  p1  p2
      

      i have tried with: (also tried with different name of columns but the result is the same:)

      class PandasData(feed.PandasData):
          params = (
              ('datetime', None),
              ('open', -1),
              ('high', -1),
              ('low', -1),
              ('close', -1),
              ('volume', -1),
              ('quote_asset_volume', -1),
              ('number_of_trades', -1),
              ('taker_buy_base_asset_volume', -1),
              ('taker_buy_quote_asset_volume', -1),
              ('p0', -1),
              ('p1', -1),
              ('p2', -1)
          )
      
      data0 = feed.PandasData(dataname=testVF)
      cerebro.adddata(data0)
      

      im getting:

      'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute 'p0'
      

      i have tried using: self.close = self.data.l.p0 (in the strategy) and

      lines = ('quote_asset_volume', 'number_of_trades', 'taker_buy_base_asset_volume', 'taker_buy_quote_asset_volume', 'p0')
      

      (found here https://community.backtrader.com/topic/1777/struggling-to-implement-custom-pandas-data-feed/10),

      but i cant manage to get p0 to work.
      also i have not found any reference in the documentation on how to get multiple columns in the strategy:
      (for example in pandas id use

      .iloc[x:x1]
      

      i have tried with just data[x:y] but it gives problem and return just 1 column like data[0]

      lorrp1 1 Reply Last reply Reply Quote 0
      • lorrp1
        lorrp1 @lorrp1 last edited by

        @lorrp1
        trying with:

        data1 = PandasDataa(dataname=testV[0:100])
        #print (data0)
        cerebro.adddata(data1)
        

        and:

        class PandasDataa(feed.DataBase):
        
            lines = ('quote_asset_volume', 'number_of_trades', 'taker_buy_base_asset_volume', 'taker_buy_quote_asset_volume', 'p0', 'p1', 'p2')
            params = (
                ('datetime', 0), #tried all with either -1 or the column index in the dataframe
                ('open', 1),
                ('high', 2),
                ('low', 3), 
                ('close', 4),
                ('volume', 5),
            )
        

        or removing the lines = {}
        return

        671         for i in range(start, end):
        --> 672             dst[i] = src[i + ago]
          673 
          674 
        
        IndexError: array index out of range
        

        or

        AttributeError: 'Plot_OldSync' object has no attribute 'mpyplot'
        

        so now its not even able to get the open/close/high/low like before

        1 Reply Last reply Reply Quote 0
        • run-out
          run-out last edited by

          I"m having a bit of a hard time following you. But try this format out.

          import backtrader as bt
          
          class CustomPandasLoader(bt.feeds.PandasData):
              lines = (
                  'quote_asset_volume',
                  'number_of_trades',
                  'taker_buy_base_asset_volume',
                  'taker_buy_quote_asset_volume',
                  'p0',
                  'p1',
                  'p2',
              )
              params = (
                  ('quote_asset_volume', -1),
                  ('number_of_trades', -1),
                  ('taker_buy_base_asset_volume', -1),
                  ('taker_buy_quote_asset_volume', -1),
                  ('p0', -1),
                  ('p1', -1),
                  ('p2', -1)
              )
              datafields = bt.feeds.PandasData.datafields + (
                  [
                      'quote_asset_volume',
                      'number_of_trades',
                      'taker_buy_base_asset_volume',
                      'taker_buy_quote_asset_volume',
                      'p0',
                      'p1',
                      'p2',
                  ]
              )
              
          data = CustomPandasLoader(
                  dataname=yourdataframe
              )
          cerebro.adddata(data)
          
          1 Reply Last reply Reply Quote 1
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
          $(document).ready(function () { app.coldLoad(); }); }