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/

    Data feeds error for local csv file in basic code with out strategy

    General Code/Help
    3
    5
    161
    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.
    • M
      max.kat last edited by

      Hi guys,

      I am trying to build first code but getting errors every time i try to connect data feeds, I tried different data feed methods and tried many other ways to connect but getting some or other kind of error every time, nothing seems to work. please help!

      mentioned two methods I am trying to use in the code.

      Code:

      import backtrader as bt
      import os
      import sys
      import datetime

      cerebro = bt.Cerebro()

      #Method 1: YahooFinanceCSVData
      modpath = os.path.dirname(os.path.abspath(sys.argv[0]))
      datapath = os.path.join(modpath, 'C:/Users/admin/xx/xx2/xx.csv')
      data = bt.feeds.YahooFinanceCSVData(dataname=datapath, reverse=False)

      #Method 2: GenericCSVData
      data = bt.feeds.GenericCSVData (dataname='filename.csv', dtformat=1)

      cerebro.adddata(data)

      cerebro.run()

      cerebro.plot()
      <end>

      Data file's first string:
      1623809640000,40124.02000000,40129.70000000,40100.00000000,40107.65000000,12.53749700,1623809699999,502950.08549781,339,4.72578400,189573.50347000,0

      Error:
      Method 1:
      ValueError: month must be in 1..12

      Method 2:
      OSError: [Errno 22] Invalid argument

      1 Reply Last reply Reply Quote 0
      • R
        rishabmah5 last edited by

        If you just need the default stock data with Open, High, Low, and Close, then you can just use the following code.

        data = bt.feeds.PandasData(dataname=yf.download("SPY", '2015-07-06', '2021-07-01', auto_adjust=False))
        

        You can change the date and ticker to whatever suits you.

        M 1 Reply Last reply Reply Quote 0
        • M
          max.kat @rishabmah5 last edited by

          @rishabmah5 need to work on the file with given format of, opendatetime, OHLC, Volume, closingdatetime, aggregate-closeprice, openinterest, :(

          run-out 1 Reply Last reply Reply Quote 0
          • run-out
            run-out @max.kat last edited by

            @max-kat We need more information about your data file. Can you add in the first few rows including the header row? If no header, please provide details of each column separately .

            RunBacktest.com

            M 1 Reply Last reply Reply Quote 0
            • M
              max.kat @run-out last edited by

              @run-out when i open it in excel it is in one column with coma separated values without headers,

              used this code to download the file from binance,

              import config, csv

              from binance.client import Client

              client = Client(config.API_KEY, config.SECRET_KEY)

              candles = client.get_historical_klines("BTCBUSD", Client.KLINE_INTERVAL_1MINUTE, "365 day ago UTC")

              csvfile = open('1min.csv', 'w', newline='')
              Klinewriter = csv.writer(csvfile,delimiter=',')

              for candlestick in candles:

              Klinewriter.writerow(candlestick)
              

              csvfile.close()

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