For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

defining a feed. Error message: Unexpected keyword argument 'dataname' in constructor call"



  • Hey Guys,

    I am new to Backtrader and I am stucking now for more than 2 weeks on this F*** problem.. I don't know why the compiler gives me back an error every time.. So now to my Code.

    I wrote a simple GoldenCross.py Script. In this script there is definitely no error. Now I want to run the GoldenCross Script with mx run.py Script it looks like this:

    import pandas as pd 
    import backtrader as bt 
    from Strategien.GoldenCross import GoldenCross
    import datetime
    
    
    cerebro = bt.Cerebro()
    cerebro.broker.setcash(100000)
    
    
    pathIndex = "/Users/me/Desktop/allgemein/Visual Studio/Stock Data/Index EOD Data/^GSPC.csv"
    # read csv, parse date, use dates col as index
    stock_prices = pd.read_csv(pathIndex, index_col=[0], parse_dates=[0])
    
    print(stock_prices)
    # create data feed pandas df
    feed = bt.feeds.PandasData(dataname=stock_prices)
    # add feed
    cerebro.adddata(feed)
    
    cerebro.addstrategy(GoldenCross)
    cerebro.run()
     cerebro.plot(style='bar')
    
    
    

    Now my compiler gives me back this error message: "Unexpected keyword argument 'dataname' in constructor call" I now tried pretty much everything, but it doesn't work!! Why does the compiler underlines the "bt." in this line:

    feed = bt.feeds.PandasData(dataname=stock_prices)
    

    and say, that the argument "dataname" is wrong?? In every script I saw, everybody write it exactly like this... Please help me!



  • Switch to terminal window in your VS Code, type python your_script_name.py, and work with the errors returned by python. Skip what pylintreturns you.



  • Hey @ab_trader, if I type python run.py in the MacBook terminal, the terminal gives me back "can't open file 'run.py': [Errno 2] No such file or directory
    ". Baby that's, because on the MacBook on standard there is python 2.7, but I use python 3.8...

    I never used the terminal window for running a code before..



  • Terminal window should be open in the folder with the python script. Anyway, google how to run python script in VS Code.



  • @ab_trader Sorry I do not get what you want to say to me.. Do you know that's the problem in my case? My visual studio works fine and I already wrote a lot of other python scripts with it.. Why should I now run this sciript with the terminal? And why should running with the terminal solve my problem?



  • @ab_trader I can run the script in visual studio as well.. And than there comes the already named problem.. And the OUTPUT says: "AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Strateg' object has no attribute 'bt'"



  • @chhrissi2909 what @ab_trader tried to explain to you is that you would see your errors better when using a terminal or setup debugging in vscode or the dev environment you use. also he showed you your error when executing your script, since you run python in a wrong directory.
    There is an issue in your strategy, which causes your problems. You would just have better informations about what is going on in your code.

    Anyway, look for self.bt. ... code in your strategy and remove the self.


Log in to reply
 

});