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



  • Hi everyone,

    I am new to backtrader and the forum. After looking at several platforms I came back to backtester.
    I am not a professional programmer. However I attempted to import csv data and plot it which fails with AttributeError: 'Plot_OldSync' object has no attribute 'mpyplot'

    Can someone point me to the right direction? pudb debugging didn't get me further.

    EDIT: setting todate and fromdate to the same values for both data, does not help.

    Thanks in advance,
    Daniel

    import datetime                                                                                                                                                                       
    import backtrader as bt                                                                                                                                                               
    import backtrader.feeds as btfeeds                                                                                                                                                    
    import os                                                                                                                                                                             
    import sys                                                                                                                                                                            
                                                                                                                                                                                          
                                                                                                                                                                                          
    class GdaxCSVLHOC(btfeeds.GenericCSVData):                                                                                                                                            
        """                                                                                                                                                                               
        bundle loading of gdax CSV files                                                                                                                                                  
                                                                                                                                                                                          
        pass dataname as parameter with the name of the CSV file                                                                                                                          
        """                                                                                                                                                                               
        params = (                                                                                                                                                                        
            # reversed=True takes into account that the CSV data has already been reversed                                                                                                
            #  and has the standard expected date ascending order                                                                                                                         
            ('reverse', False),                                                                                                                                                           
            ('headers', True),                                                                                                                                                            
            ('separator', ","),                                                                                                                                                           
            # defaults to min                                                                                                                                                             
            #fromdate=datetime.datetime(2000, 1, 1),                                                                                                                                      
            # defaults to max                                                                                                                                                             
            #todate=datetime.datetime(2000, 12, 31),                                                                                                                                      
            ('nullvalue', 0.0),                                                                                                                                                           
            # Format used to parse the datetime CSV field                                                                                                                                 
            ('dtformate', '%Y-%m-%d %H:%M:%S'),                                                                                                                                           
            # Format used to parse the time CSV field if "present"                                                                                                                        
            #('tmformat', )                                                                                                                                                               
            #Fields order                                                                                                                                                                 
            ('datetime', 0),                                                                                                                                                              
            ('high', 2),                                                                                                                                                                  
            ('low', 1),                                                                                                                                                                   
            ('open', 3),                                                                                                                                                                  
            ('close', 4),                                                                                                                                                                 
            ('volume', 5),                                                                                                                                                                
            ('openinterest', -1)                                                                                                                                                          
        )                            
    
    if __name__ == '__main__':                                                                                                                                                            
                                                                                                                                                                                          
        # Create a cerebro entity                                                                                                                                                         
        cerebro = bt.Cerebro()                                                                                                                                                            
                                                                                                                                                                                          
        # Data is in an extra folder                                                                                                                                                      
        modpath = os.path.dirname(os.path.abspath(sys.argv[0]))                                                                                                                           
        datapath = os.path.join(modpath, '..', 'data')                                                                                                                                    
                                                                                                                                                                                          
        eth_eur = GdaxCSVLHOC(dataname = os.path.join(datapath, 'ETH-EUR_gdax.csv'),                                                                                                      
                                      # Do not pass values before this date                                                                                                               
                                      fromdate=datetime.datetime(2017, 6, 3),                                                                                                            
                                      # Do not pass values after this date                                                                                                                
                                      todate=datetime.datetime(2017, 8, 10)                                                                                                               
        )                                                                                                                                                                                 
        eth_usd = GdaxCSVLHOC(dataname = os.path.join(datapath, 'ETH-USD_gdax.csv'),                                                                                                      
                                      # Do not pass values before this date                                                                                                               
                                      fromdate=datetime.datetime(2017, 6, 3),                                                                                                             
                                      # Do not pass values after this date                                                                                                                
                                      todate=datetime.datetime(2017, 8, 10)                                                                                                               
        )                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                          
        cerebro.adddata(eth_eur)                                                                                                                                                          
        cerebro.adddata(eth_usd)                                                                                                                                                          
        cerebro.run()                                                                                                                                                                     
        cerebro.plot()                 
    
    

    I am running this in an up to date virtualenv. Backtrace:

    (venv) [noisy:~/devel/planet-trader]: python strategies/bt_strat_gdax_csv.py 
    Traceback (most recent call last):
      File "strategies/bt_strat_gdax_csv.py", line 76, in <module>
        cerebro.plot()
      File "/home/daniel/devel/planet-trader/venv/lib/python2.7/site-packages/backtrader/cerebro.py", line 943, in plot
        plotter.show()
      File "/home/daniel/devel/planet-trader/venv/lib/python2.7/site-packages/backtrader/plot/plot.py", line 777, in show
        self.mpyplot.show()
    AttributeError: 'Plot_OldSync' object has no attribute 'mpyplot'
    

    Python 2.7.13
    my pip packages:

    backtrader==1.9.54.122                                                                                                                                                                
    certifi==2017.7.27.1                                                                                                                                                                  
    chardet==3.0.4                                                                                                                                                                        
    cycler==0.10.0                                                                                                                                                                        
    DateTime==4.2                                                                                                                                                                         
    functools32==3.2.3.post2                                                                                                                                                              
    idna==2.5                                                                                                                                                                             
    matplotlib==2.0.2                                                                                                                                                                     
    numpy==1.13.0                                                                                                                                                                         
    pyparsing==2.2.0                                                                                                                                                                      
    python-dateutil==2.6.0                                                                                                                                                                
    pytz==2017.2                                                                                                                                                                          
    requests==2.18.3                                                                                                                                                                      
    six==1.10.0                                                                                                                                                                           
    subprocess32==3.2.7                                                                                                                                                                   
    urllib3==1.22                                                                                                                                                                         
    zope.interface==4.4.2 
    


  • Hi

    try to update to a recent version of backtrader or try to add a strategy.

    The plot method will exit without a strategy before creating the mpyplot object, which is being tried to be shown in the show method later

    HTH
    Daniel



  • Hi dasch,

    Thanks! I did a pip install --upgrade backtrader in my virtualenv which helped! I was sure I already did that but was apparently not true. This now gives me an IndexError I will look into that.

    best,
    Daniel


  • administrators

    Notwithstanding that it is unclear if you added an strategy, the addition of the data feeds is missing the specifics about timeframe and compression.

    Cryptocurrency traders tend apparently to look at timeframes smaller than 1-day which is the default when adding a timeframe.

    See: Community - FAQ


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.