Anaconda Python and Backtrader



  • Dear Sir / Madam,

    I'm new to Python and Backtrader. I just installed Python by installing the anaconda.

    When I try to run "btrun" of backtrader, following message show up, appreciate if you can advise if anything wrong with my installation.

    Traceback (most recent call last):
    File "c:\users\charl\anaconda3\lib\runpy.py", line 184, in run_module_as_main
    "main", mod_spec)
    File "c:\users\charl\anaconda3\lib\runpy.py", line 85, in run_code
    exec(code, run_globals)
    File "C:\Users\charl\Anaconda3\Scripts\btrun.exe_main
    .py", line 5, in <module>
    File "c:\users\charl\anaconda3\lib\site-packages\backtrader\btrun_init
    .py", line 24, in <module>
    from .btrun import btrun
    File "c:\users\charl\anaconda3\lib\site-packages\backtrader\btrun\btrun.py", line 41, in <module>
    ibdata=bt.feeds.IBData,
    AttributeError: module 'backtrader.feeds' has no attribute 'IBData'


  • administrators

    • How are things being executed? (inside some environment? (because of runpy.py)

    • What is being executed? (arguments ...)



  • Hi, I just key in "btrun" under windows command prompt and the error mentioned appears. I also try "btrun --help" but still same situation


  • administrators

    The author seemed to be the only one using btrun and IBData needs to have Ibpy installed. Your quickest options:

    It will be in the next release



  • OK. Thanks.
    I works now.

    Appreciate if more information can be put to the documentation so a newbie can understand more regarding the installation requirement, especially the one with no experience in python.


  • administrators

    @ccjasia It is a mistake in the implementation of btrun. There should have no need for you to install anything (unless you were planning to connec to IB) It seems 99.9% of the world doesn't use btrun



  • Hi Administrator,

    Thanks for your reply.
    As I'm new to Python and Backtrader, what I would like to do is to focus on backtesting instead of setting up infrastructure. The previous issue is resovled by install the Ipy.

    My Target

    1. Learn Python so I can make use of Python to code my strategy
    2. Make use of BackTrader as my platform for backtesting

    Now, I've coded as simple strategy and run using "btrun", while it shows following errors. Appreciate if you can shed some light on this issue. In case btrun is not the appropriate tool to run the strategy, please advise which tool should be used instead. Thanks a lot !

    P.S. I install python via Anaconda

    g:\cd\Invest\Learn\TTCF\homework\TradingStrategy\Backtest\BackTrader\9HLCvs9O>btrun --data HSIhistdataTest.csv --strategy MyModuleORG.py
    Traceback (most recent call last):
    File "c:\users\charl\anaconda3\lib\runpy.py", line 184, in _run_module_as_main
    "main", mod_spec)
    File "c:\users\charl\anaconda3\lib\runpy.py", line 85, in run_code
    exec(code, run_globals)
    File "C:\Users\charl\Anaconda3\Scripts\btrun.exe_main
    .py", line 9, in <module>
    File "c:\users\charl\anaconda3\lib\site-packages\backtrader\btrun\btrun.py", line 119, in btrun
    runsts = cerebro.run()
    File "c:\users\charl\anaconda3\lib\site-packages\backtrader\cerebro.py", line 809, in run
    runstrat = self.runstrategies(iterstrat)
    File "c:\users\charl\anaconda3\lib\site-packages\backtrader\cerebro.py", line 872, in runstrategies
    data.preload()
    File "c:\users\charl\anaconda3\lib\site-packages\backtrader\feed.py", line 616, in preload
    while self.load():
    File "c:\users\charl\anaconda3\lib\site-packages\backtrader\feed.py", line 411, in load
    _loadret = self._load()
    File "c:\users\charl\anaconda3\lib\site-packages\backtrader\feed.py", line 638, in _load
    return self._loadline(linetokens)
    File "c:\users\charl\anaconda3\lib\site-packages\backtrader\feeds\btcsv.py", line 44, in _loadline
    y = int(dttxt[0:4])
    ValueError: invalid literal for int() with base 10: '14/0'


  • administrators

    Hi,

    If your number 1 goal is:

    Learn Python so I can make use of Python to code my strategy

    You shouldn't probably be using btrun which is meant to abstract things and won't help with learning.

    Non code reports are difficult to look into. In your case the last lines give an insight:

    File "c:\users\charl\anaconda3\lib\site-packages\backtrader\feeds\btcsv.py", line 44, in _loadline
    y = int(dttxt[0:4])
    ValueError: invalid literal for int() with base 10: '14/0'

    You are loading a csv data with the BactraderCSVData data feed and the field which is being encountered is 14/0 which cannot be parsed.

    If that csv file is ok you best options:

    • Use GenericCSVData (see here) and configure the fields according to reality
    • Load it with pandas.read_csv and then use a PandasData (see here)data feed also configuring the fields

    But if you are learning I would recommend focusing on easy and tested samples (and the quickstart), rather than feeding in your own data sources.


Log in to reply
 

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