Backtrader Community

    • 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/

    Anaconda Python and Backtrader

    General Code/Help
    4
    8
    4957
    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.
    • C
      ccjasia last edited by

      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'

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

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

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

        1 Reply Last reply Reply Quote 0
        • C
          ccjasia last edited by

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

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

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

            • Either install Ibpy see here

            • Or use the just pushed commit from the the backtrader repository: 191af260ca3da911b561d94a8c9f7f4798fe4a4d

            It will be in the next release

            1 Reply Last reply Reply Quote 0
            • C
              ccjasia last edited by

              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.

              B 1 Reply Last reply Reply Quote 0
              • B
                backtrader administrators @ccjasia last edited by

                @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

                1 Reply Last reply Reply Quote 0
                • C
                  ccjasia last edited by

                  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'

                  1 Reply Last reply Reply Quote 0
                  • B
                    backtrader administrators last edited by

                    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.

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