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/

    ValueError: day is out of range for month

    General Code/Help
    1
    1
    17
    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.
    • samueltg92
      samueltg92 last edited by

      Hello, I am getting this ValueError after setting the CSV data using the code below:


        File "/mnt/c/Users/samue/Documents/ALGORITHMIC-TRADING-PROJECTS/backtesting strategies/Backtrader/MA_RSI_15m/main.py", line 9, in <module>
          fromdate = datetime.datetime(9,4,2004),
      ValueError: day is out of range for month
      

      Code:

      import backtrader as bt
      import datetime as datetime
      import pandas as pd
      
      
      cerebro = bt.Cerebro()
      
      data = bt.feeds.GenericCSVData(dataname= '/mnt/c/Users/samue/Documents/ALGORITHMIC-TRADING-PROJECTS/backtesting strategies/data_sets/EURUSD_Candlestick_15_M_BID_09.04.2004-04.04.2022.csv',
                                     name = 'EUR-USD 15min',
                                     fromdate = datetime.datetime(9, 4, 2004),
                                     todate = datetime.datetime(4, 4, 2022),
                                     timeframe = bt.TimeFrame.Minutes,
                                     compression = 15,
                                     datetime = 0,
                                     open = 1,
                                     high = 2,
                                     low = 3,
                                     close = 4,
                                     volume = 5,
                                     openinterest = -1,
                                     dtformat = '%d.%m.%Y' '%H:%M:%S'
                                     )
      
      
      cerebro.adddata(data)
      cerebro.broker.setcash(100.0)
      
      get_value = cerebro.broker.getvalue()
      print(f'Starting value: {get_value}')
      
      cerebro.run()
      
      print(f'Final value: {get_value}')
      
      

      Data used:

      58865e2d-ee35-4dbb-92bc-166eb5f7564e-image.png

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