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/

    struggling to resample csv file

    General Code/Help
    3
    5
    102
    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.
    • A
      AALLI last edited by

      this is my code :

      data = bt.feeds.GenericCSVData(
          dataname='USDJPY_H1.csv',
       
          fromdate=datetime.datetime(2014, 4, 2),    
          todate=datetime.datetime(2014, 4, 4),
      
          nullvalue=0.0,  
      
          dateformat='%Y-%m-%d %H:%M:%S',
      
          datetime=0,   
          time=-1,    
          open=1,    
          high=2,    
          low=3,    
          close=4,    
          adjclose=5,    
          volume=6,    
          openinterest=-1, 
      
          timeframe=bt.TimeFrame.Minutes, compression=60)
      

      and this is a part of my cvs file

          Date,Open,High,Low,Close,AdjClose,Volume
          
          2014-04-02 16:00:00 103.819	103.821	103.745	103.767	1854
          
          2014-04-02 17:00:00	103.767	103.839	103.732	103.775	1777
          
          2014-04-02 18:00:00	103.776	103.794	103.734	103.747	1072
          
          2014-04-02 19:00:00	103.749	103.867	103.748	103.852	1837
          
          2014-04-02 20:00:00	103.851	103.882	103.826	103.881	985
          
          2014-04-02 21:00:00	103.882	103.894	103.846	103.865	577  
      

      Im getting this error : raise ValueError("unconverted data remains: %s" %
      ValueError: unconverted data remains: 103.819 103.821 103.745 103.767 1854

      can anyone tell me whats wrong?

      D 1 Reply Last reply Reply Quote 0
      • D
        dasch @AALLI last edited by

        @aalli you may want to define the seperator for your csv data by providing the separator param.

        data = bt.feeds.GenericCSVData(
            dataname='USDJPY_H1.csv',
         
            fromdate=datetime.datetime(2014, 4, 2),    
            todate=datetime.datetime(2014, 4, 4),
        
            nullvalue=0.0,  
        
            dateformat='%Y-%m-%d %H:%M:%S',
        
            datetime=0,   
            time=-1,    
            open=1,    
            high=2,    
            low=3,    
            close=4,    
            adjclose=5,    
            volume=6,    
            openinterest=-1, 
            seperator='\t',
            timeframe=bt.TimeFrame.Minutes, compression=60)
        A 2 Replies Last reply Reply Quote 1
        • A
          AALLI @dasch last edited by

          @dasch how about I put in a class?

          1 Reply Last reply Reply Quote 0
          • A
            AALLI @dasch last edited by

            @dasch thanks I tried this but it didnt work

            vladisld 1 Reply Last reply Reply Quote 0
            • vladisld
              vladisld @AALLI last edited by

              @aalli If the separator is set to tab or space, the date and time will become a separate columns. In this case the dtformat and tmformat need to be specified as well as datetime and time columns should have valid column indexes.

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