Algotopian is starting. Let it be the future of backtrader. Check it out! https://www.algotopian.com
For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

How to read date and time when they are in same column using GenericCSVData



  • Hi,

    I have CSV file in following format providing hourly data.

    Timestamp,Open,High,Low,Close,Volume,Volume (Currency),Weighted Price
    9/7/2017 0:00,4605.81,4609.8,4534.29,4539.97,342.08,1563456.99,4570.39
    9/7/2017 1:00,4539.95,4571.16,4480,4507.51,532.02,2405813.27,4522.06
    

    I don't have separate time column, both date and time are in column 0. But I need to be able to read hours.

    I am using following code:

    data = bt.feeds.GenericCSVData(
            dataname=datapath,
            datetime=0,
            open=1,
            high=2,
            low=3,
            close=4,
            volume=5,
            openinterest=-1,
            fromdate=datetime(2017,10,9),
            todate=datetime(2017,10,12),
            separator=',',
            dtformat=('%m/%d/%Y %H:%M')
    
    

    It compiles and works without a problem, but I am not able to read the hour in next() method of strategy.
    It can read date, but not the hour.

    Could you please advise on how to read the hour back when I need it,
    for example I want to print date and hour of the day in logs ?

    Thanks


  • administrators


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.