Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. punajunior
    3. Posts
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    P
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 5
    • Best 0
    • Groups 0

    Posts made by punajunior

    • RE: Could not convert string to float: '2021-04-09' when loading from another CSV file

      @davidavr
      head "12 Apr 2021 _Raw.csv" <- this doesnt work.
      so I just use texteditor to open my csv , so it goes like below
      53729095-dd5a-43a1-a098-86cf6bdeb36f-image.png

      Date should be second column thus i am using "1" and i've also set the dtformat to match but it prompted the below
      408df639-944c-4e28-ad7b-3eea5c9de6d0-image.png

      posted in General Code/Help
      P
      punajunior
    • RE: Could not convert string to float: '2021-04-09' when loading from another CSV file

      @punajunior

      if i updated back to "%Y-%m-%d" it gives me the same error couldnt covert string to float.
      452c8623-0167-4112-b066-653c5c51c397-image.png

      posted in General Code/Help
      P
      punajunior
    • RE: Could not convert string to float: '2021-04-09' when loading from another CSV file

      @davidavr
      So i printed my DF , my date column format is "%Y-%m-%d"
      9ce0d07b-c5b2-4b68-8f46-009f0437fae4-image.png

      I also tried changing the Dtformat to "%m/%d/%Y" but it gives me the same error
      9bd0e661-9478-4623-a3f9-0c2fcdc265f2-image.png

      posted in General Code/Help
      P
      punajunior
    • RE: Could not convert string to float: '2021-04-09' when loading from another CSV file

      @rajanprabu

      Thanks , so my csv compose of below

      83f42b44-27ea-4385-aa7b-245c7650ba48-image.png

      posted in General Code/Help
      P
      punajunior
    • Could not convert string to float: '2021-04-09' when loading from another CSV file

      As the title suggests, I am having problems loading raw csv into my code. It is giving ValueError, but I don't know why. I tried to turn my date column in numbers and it still gives me the same error
      Here is my code:
      if name == 'main':
      cerebro = bt.Cerebro()
      cerebro.addstrategy(TestStrategy)
      cerebro.broker.setcommission(commission=0.001)

      # Create a Data Feed
      data = bt.feeds.GenericCSVData(
          dataname='12 Apr 2021 _Raw.csv',
          fromdate=datetime.datetime(2021, 1, 1),
          todate=datetime.datetime(2021, 4, 5),
          nullvalue = 0.0,
          dtformat=('%Y-%m-%d'),
          datetime = 1,
          )
      
      print(data)
      cerebro.adddata(data)
      cerebro.broker.setcash(100000.0)
      print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
      cerebro.run()
      print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
      cerebro.plot()
      

      Any help is appreciated. Thank you so much!

      posted in General Code/Help
      P
      punajunior
    • 1 / 1