For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

importing 4 hour interval csv data



  • Re: 4 hour time intervals

    Hi All,

    Sorry to resurrect an old topic but it is exactly what I am looking for

    My understanding the compression is only to create (in this case) 4 hour data from smaller time frame data.

    What if my raw/original data is 4 hour data. How can keep the time frame after importing?

    Thanks so much in advance

    Regards

    darwin


  • administrators

    Same as done in the thread you reference:

    @kreut said in 4 hour time intervals:

    @ab_trader Definitely a step in the right direction! I've updated my code:

    data = btfeeds.GenericCSVData(
        dataname='ada.csv',
        fromdate=datetime.datetime(2000, 1, 1),
        todate=datetime.datetime(2018, 12, 31),
        timeframe=bt.TimeFrame.Minutes, compression=240,
        nullvalue=0.0,
        dtformat=('%Y-%m-%d %H:%M:%S'),
        datetime=0,
        high=1,
        low=2,
        open=3,
        close=4,
        volume=-1,
        openinterest=-1
    )
    


  • @backtrader

    Dear Administrators, thanks for your response
    I have read that thread before but I could not get it working and got confused at the same time.
    The related codes seem to be the "timeframe=bt.TimeFrame.Minutes, compression=240"
    From the wording and trials that I've done, I can only understand it as resampling minutes data into 4 hour data hence the 240 (4 hour = 240 minutes).

    But what I am trying to do is that the raw csv data is 4 hour data from the very beginning. How to import it and keep the time/hour data? I cannot use minutes data because they are not available from the broker that I am using.

    Thanks again for the response and hopefully there is more to come

    regards

    darwin


  • administrators

    Sorry you are confused. That code is loading a data feed and stating that it is made of price bars, with each bar representing 240-Minutes (i.e.: 4-hours)

    It is doing exactly what you asked for.

    There is no resampling in that code. Data feeds do not resample anything. For how resampling is done see: Docs - Data Resampling

    @darwinps said in importing 4 hour interval csv data:

    How to import it and keep the time/hour data?

    You show absolutely no code, no data, so nobody can know what you are doing and why it isn't working



  • @backtrader

    Hi Administrators,

    Thanks for your reply. I still haven't got it working as expected yet but at least now I am sure I am at the right direction. I am sure I can get it.

    Thanks again

    darwin



  • @backtrader

    Dear All,

    I figured it out. I had the datetime only: <datetime>, <open>, <so forth> instead of <datetime>, <time>, <open>,<so forth>
    Thanks again

    regards
    darwin