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

Backtesting 1 minute data



  • Hello - I've been able to successfully backtest 1 day and 1 hour data and for some reason when I try to backtest on 1 minute data no trades get executed when the backtest completes. I'm loading the appropriate CSV file with GenericCSVData for each test and not using the resampling feature provided by BackTrader. I'm assuming this should theoretically work for 1 min or 5 min.. The data looks like the following:

    1 hour
    2017-01-27 00:00:00+00:00,1.07246,1.06928,1.06791,1.06576,107892.0

    1 min
    2017-01-27 22:59:00+00:00,1.06954,1.06928,1.06948,1.0691,10.0

    and the dtformat is set as:
    dtformat=('%Y-%m-%d %H:%M:%S+00:00')

    Any suggestions?

    Thanks


  • administrators

    The platform executes trades even with isolated ticks. Unfortunately the information provided above is insufficient to say why you may not be executing.

    Long shot: you should always tell the platform which timeframe and compression the data feed has by specifying both during data feed creation.



  • Thanks, it working now on 1 min data - BackTrader is simply awesome!



  • @Z03 can you please post one example how use intraday timeframes? thx


  • administrators

    Without knowing what you may be looking for, using intraday timeframes is not different from daily timeframes. In the question above, the problem is that the creation of the data feed was not specifying the timeframe and compression parameters. As such the platform uses the defaults (timeframe=bt.TimeFrame.Days)

    See this Blog - Timers post. The intraday script uses de 5-minutes data sample available in the sources.

    An excerpt where the parameters are specified

        # Data feed kwargs
        kwargs = dict(
            timeframe=bt.TimeFrame.Minutes,
            compression=5,
            sessionstart=datetime.time(9, 0),
            sessionend=datetime.time(17, 30),
        )
    


  • I have a data in this format:
    0_1525027485683_d97c344c-2ffd-4e38-8548-3f2f7deacaf2-image.png .......................................................................................................
    .......................................................................................................
    0_1525027512657_756db977-d870-483c-9502-81b0b6d1184e-image.png
    I am using this method but although trying of different type of parameters as "fromdate,todate and reverse" the printed dataset is not changing

    data = bt.feeds.GenericCSVData(
    dataname='data.csv',
    datetime=0,
    fromdate=datetime.datetime(2017, 12, 28),
    timeframe=bt.TimeFrame.Minutes,
    dtformat=('%d-%m-%Y %H:%M'),
    open=1,
    high=2,
    low=3,
    close=4,
    volume=5,
    openinterest=-1,
    reverse=True)

    Printed Result:
    Starting Portfolio Value: 100000.00
    2018-04-27, Close, 996.50
    2018-04-27, Close, 994.90
    2018-04-27, Close, 998.15
    ...........................................
    2017-12-28, Close, 920.80
    2017-12-28, Close, 920.90
    2017-12-28, Close, 920.20
    2017-12-28, Close, 923.25
    2017-12-28, Close, 923.20
    Final Portfolio Value: 100000.00

    I want the data as usual upside down.


  • administrators

    @ry93 said in Backtesting 1 minute data:

    reverse

    reverse is not a parameter of GenericCSVData -See Docs - Data Feeds Reference

    @ry93 said in Backtesting 1 minute data:

    I want the data as usual upside down.

    Don't know exactly what the upside is in this case. The data has to be chronologically ordered from oldest to newest. As it happens in real life. The file with your data is read line by line.

    You will have to reverse the data before passing it to the platform.



  • @backtrader Thanks I got it.



  • @backtrader How to read dataset in following cases:

    1. When there is no time column:
      Date,Open,High,Low,Close,Volume
      12/29/2000,30.87,31.31,28.69,29.06,31655500
      12/28/2000,30.56,31.12,30.37,31.06,25055600
      12/27/2000,30.37,31.06,29.37,30.69,26441700

    2. When time is in separate column:
      "Date","Time","O","H","L","C","U","D"
      01/02/2006,1530,2821.10,2836.70,2804.00,2819.80,0,0
      01/03/2006,1530,2823.00,2872.00,2815.10,2868.70,0,0
      01/04/2006,1530,2885.00,2896.00,2873.30,2890.40,0,0
      01/05/2006,1530,2892.30,2895.80,2868.00,2886.00,0,0

    For "1" case I am trying in this way but is it not working:
    bt.feeds.GenericCSVData(
    dataname='orcl-2000.csv',
    fromdate=datetime.datetime(2000,12,29),
    dtformat=('%m/%d/%y'),
    datetime=0,
    open=1,
    high=2,
    low=3,
    close=4,
    volume=5,
    openinterest=-1)

    It is giving me this error:
    data_string[found.end():])
    ValueError: unconverted data remains: 00