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/

    Problem loading genericCSVdata

    General Code/Help
    3
    4
    1970
    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
      mahbubk9 last edited by

      Hi,
      Trying to load some csv data,

      if __name__ == '__main__':
          cerebro = bt.Cerebro()
          # Add a strategy
          cerebro.addstrategy(TestStrategy)
          
          
      
         
          # Datas are in a subfolder of the samples. Need to find where the script is
          # because it could have been called from anywhere
          modpath = os.path.dirname(os.path.abspath(sys.argv[0]))
          datapath = os.path.join(modpath, 'data/gbpusd 1min data.csv')
      
          # Create a Data Feed
          data = btfeeds.GenericCSVData(
          dataname= datapath,
      
          fromdate=datetime.datetime(2017, 1, 1),
          todate=datetime.datetime(2017,1 , 2),
      
          nullvalue=0.0,
      
          dtformat=('%d.%m.%Y %H:%M:%S.%f'),
      
          datetime=0,
          high=1,
          low=2,
          open=3,
          close=4,
          volume=5,
          openinterest=-1)
          
      
          
          
      
      
           
          print(data.head())
          print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
      
          cerebro.run()
      
          print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
      

      Getting Output:

      
      AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute 'head'
      

      Does it mean the data has not loaded? Where did I go wrong(i did load btfeeds, datetime etc in the begining).
      Thanks

      1 Reply Last reply Reply Quote 0
      • N
        Ninjaneer last edited by Ninjaneer

        Since no one else has commented yet, I'll take a stab at it...

        My first question is: "Is .head a valid attribute/method for GenericCSVData?" A quick search of the docs does not show anything, and I get the same error if I try it in my program. I suspect this is your problem. What are you trying to print?

        Second, can python/backtrader parse file names with spaces in them? I've never tried it, so I'm not sure.

        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators last edited by

          @mahbubk9 said in Problem loading genericCSVdata:

          print(data.head())

          @Ninjaneer is right on spot. What head() is supposed to mean is unknown but is for sure not part of the platform and not an attribute of the data feed, hence the error that exactly says that.

          @mahbubk9 said in Problem loading genericCSVdata:

          Does it mean the data has not loaded? Where did I go wrong(i did load btfeeds, datetime etc in the begining).

          Apparently it did actually load because there is no complain/exception indicating the contrary.

          @Ninjaneer said in Problem loading genericCSVdata:

          Second, can python/backtrader parse file names with spaces in them? I've never tried it, so I'm not sure.

          Change the separator parameter to the data feed to be a space. At least it's worth a try. See Docs - Data Feeds Reference

          1 Reply Last reply Reply Quote 0
          • M
            mahbubk9 last edited by

            Thanks for the clarification.

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