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

Newbie to backtrader - CSV Data feed

  • Hi all,

    I tried to feed data from CSV but it didn't work

    My CSV data is as below

    My code is

    import datetime
    import backtrader.feeds as btfeeds
    class MyOHLC(btfeeds.GenericCSVData):
    params = (
    ('fromdate', datetime.datetime(2017, 12, 1)),
    ('todate', datetime.datetime(2017, 12, 31)),
    ('nullvalue', 0.0),
    ('dtformat', ('%Y-%m-%d')),
    ('tmformat', ('%H.%M.%S')),
    ('datetime', 1),
    ('open', 2),
    ('high', 3),
    ('low', 4),
    ('close', 5),
    ('volume', 6),
    ('openinterest', -1)
    data = MyOHLC(dataname='E:\Data\HPG.csv')

    The result is always None.
    Somebody please help.
    Thanks a lot

  • @quy-bao-le said in Newbie to backtrader - CSV Data feed:

    ('dtformat', ('%Y-%m-%d'))

    To start with ... that won't for sure match the (not fully displayed) column for datetime which has this format: %Y%m%d and possibly more content after that.

    To continue with:

    • An Excel table is not CSV. Your intention is clear, but it would be better if you showed the actual CSV data (a couple of lines suffice)

    • You can read the remark at the top ... and format your code easily (that will make it easier for others to read and help)

    • A complete sample (as small as possible) is always a lot more helpful than out of context snippets.

Log in to reply