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/

    Extending Datafeeds GenericCSV Attribute Error

    Indicators/Strategies/Analyzers
    2
    3
    211
    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.
    • kian hong Tan
      kian hong Tan last edited by

      Re: Extending Datafeeds GenericCSV Attribute Error

      @Osofuego @Michael172

      Hi guys, I ran into similar error and I couldn't solve it despite checking all similar queries and read the documentation on Extending a Datafeed. I wanted to add VWAP to the data feed. I have also checked this out - https://community.backtrader.com/topic/1584/extending-a-datafeed/3 , still I dont know how aliasing works. Appreciate if anyone here can guide me on this. Many thanks.

      Error Msg:

      ---------------------------------------------------------------------------
      AttributeError                            Traceback (most recent call last)
      <ipython-input-6-7b3e612ced80> in <module>
          328         params = (('vwap', 7),)
          329 
      --> 330     data = bt.feeds.GenericCSV_w_VWAP(
          331     dataname= os.path.join(directory,'BTCUSDT-15m.csv'),
          332 
      
      AttributeError: module 'backtrader.feeds' has no attribute 'GenericCSV_w_VWAP'
      

      My code:

      if __name__ == '__main__':
          cerebro = bt.Cerebro()
          
          cerebro.addstrategy(HmaCross)
      
          class GenericCSV_w_VWAP(GenericCSVData):
              lines = ('vwap',)
              params = (('vwap', 7),)
          
          data = bt.feeds.GenericCSV_w_VWAP(
          dataname= os.path.join(directory,'BTCUSDT-15m.csv'),
      
          fromdate=datetime.datetime(2020, 7, 1),
          todate=datetime.datetime(2020, 9, 1),
              
          nullvalue=0.0, 
          
          timeframe=bt.TimeFrame.Minutes,              
          compression=15,                             
          dtformat=('%Y-%m-%d %H:%M:%S'),  
          datetime=0,
          time=-1,
          high=2,
          low=3,
          open=1,
          close=4,
          volume=5,
          openinterest=-1,
          vwap=7
          )
          
          cerebro.adddata(data)         
      

      Source CSV Data:

      185c7542-0575-4a82-b664-d949deae0ca6-image.png

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        @kian-hong-Tan said in Extending Datafeeds GenericCSV Attribute Error:

        data = bt.feeds.GenericCSV_w_VWAP(

        please try just:

        data = GenericCSV_w_VWAP( 
        ...
        

        also, please check your dtformat specification.

        1 Reply Last reply Reply Quote 2
        • kian hong Tan
          kian hong Tan last edited by

          @vladisld thanks, it works now. I have also changed the date format. :)

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