For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:
2019-10-02: The community is currently in read-only mode

Bulk loading tickers

  • Hi, I'm new to backtrader and trying to load a full set of ticker history via QuandlCSV. It appears to assume one ticker per file. Is there something I'm missing? I can't see anything relevant in the docs. My shell output is below.

    Jamess-MBP:bt $ tail EOD_quandl.csv
    Jamess-MBP:bt $ python
    Python 3.7.0 (default, Jun 28 2018, 07:39:16)
    [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
    Type "help", "copyright", "credits" or "license" for more information.

    import backtrader as bt
    c = bt.cerebro.Cerebro()
    f = bt.feeds.QuandlCSV(dataname="./EOD_quandl.csv")
    <backtrader.feeds.quandl.QuandlCSV object at 0x10ef236a0>
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/anaconda3/lib/python3.7/site-packages/backtrader/", line 1127, in run
    runstrat = self.runstrategies(iterstrat)
    File "/anaconda3/lib/python3.7/site-packages/backtrader/", line 1212, in runstrategies
    File "/anaconda3/lib/python3.7/site-packages/backtrader/", line 688, in preload
    while self.load():
    File "/anaconda3/lib/python3.7/site-packages/backtrader/", line 479, in load
    _loadret = self._load()
    File "/anaconda3/lib/python3.7/site-packages/backtrader/", line 710, in _load
    return self._loadline(linetokens)
    File "/anaconda3/lib/python3.7/site-packages/backtrader/feeds/", line 99, in _loadline
    dt = date(int(dttxt[0:4]), int(dttxt[5:7]), int(dttxt[8:10]))
    ValueError: invalid literal for int() with base 10: 'A'

  • administrators

    @asjem said in Bulk loading tickers:

    It appears to assume one ticker per file

    It's not an assumption. It doesn't even assume you have a ticker name in your csv file.

  • @backtrader thanks, let me rephrase the question. Can I load that format (ticker as first column) with QuandlCSV, or do I need to do something bespoke?

  • administrators

    @asjem said in Bulk loading tickers:

    @backtrader thanks, let me rephrase the question. Can I load that format (ticker as first column) with QuandlCSV, or do I need to do something bespoke?

    If that format has several tickers, which is what you seem to imply in your first comment, the best approach would be to:

    • Load the csv with pandas and the method read_csv

    • For each ticker you want as a data feed: slice using the the ticker name

    • Load the slice with PandasData

      Docs - PandasData

  • @backtrader Thanks for the quick reply! I'll try that work around. Just a bit surprised it isn't supported by default since its a very common format to start with. Thanks

  • administrators

    backtrader isn't pandas. The data feeds are a completely different abstraction.

Log in to reply