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

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
    ZZZ,2017-08-22,0.01,0.01,0.01,0.01,0.0,0.0,1.0,0.01,0.01,0.01,0.01,0.0
    ZZZ,2017-08-23,0.01,0.01,0.01,0.01,0.0,0.0,1.0,0.01,0.01,0.01,0.01,0.0
    ZZZ,2017-08-24,0.01,0.01,0.01,0.01,0.0,0.0,1.0,0.01,0.01,0.01,0.01,0.0
    ZZZ,2017-08-25,0.01,0.01,0.01,0.01,0.0,0.0,1.0,0.01,0.01,0.01,0.01,0.0
    ZZZ,2017-08-28,0.01,0.01,0.01,0.01,0.0,0.0,1.0,0.01,0.01,0.01,0.01,0.0
    ZZZ,2017-08-29,0.01,0.01,0.01,0.01,0.0,0.0,1.0,0.01,0.01,0.01,0.01,0.0
    ZZZ,2017-08-30,0.01,0.01,0.01,0.01,0.0,0.0,1.0,0.01,0.01,0.01,0.01,0.0
    ZZZ,2017-08-31,0.01,0.01,0.01,0.01,0.0,0.0,1.0,0.01,0.01,0.01,0.01,0.0
    ZZZ,2017-09-01,0.01,0.01,0.01,0.01,0.0,0.0,1.0,0.01,0.01,0.01,0.01,0.0
    ZZZ,2017-09-05,0.01,0.01,0.01,0.01,100.0,0.0,1.0,0.01,0.01,0.01,0.01,100.0
    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")
    c.adddata(f)
    <backtrader.feeds.quandl.QuandlCSV object at 0x10ef236a0>

    c.run()
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/anaconda3/lib/python3.7/site-packages/backtrader/cerebro.py", line 1127, in run
    runstrat = self.runstrategies(iterstrat)
    File "/anaconda3/lib/python3.7/site-packages/backtrader/cerebro.py", line 1212, in runstrategies
    data.preload()
    File "/anaconda3/lib/python3.7/site-packages/backtrader/feed.py", line 688, in preload
    while self.load():
    File "/anaconda3/lib/python3.7/site-packages/backtrader/feed.py", line 479, in load
    _loadret = self._load()
    File "/anaconda3/lib/python3.7/site-packages/backtrader/feed.py", line 710, in _load
    return self._loadline(linetokens)
    File "/anaconda3/lib/python3.7/site-packages/backtrader/feeds/quandl.py", 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.