Navigation

    Backtrader Community

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

    Newbie to backtrader - CSV Data feed

    General Code/Help
    2
    2
    867
    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.
    • Q
      Quy Bao Le last edited by

      Hi all,

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

      My CSV data is as below
      0_1515230837063_bf511cde-946b-401c-b558-9a872b004c45-image.png

      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')
      print(data.getfeed())

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

      P 1 Reply Last reply Reply Quote 0
      • P
        Paska Houso @Quy Bao Le last edited by

        @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.

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }