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



  • 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



  • @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.



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


Log in to reply
 

});