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/

    Backtesting 1 minute data

    General Discussion
    6
    10
    12172
    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.
    • Z
      Z03 last edited by Z03

      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

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

        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.

        1 Reply Last reply Reply Quote 0
        • Z
          Z03 last edited by

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

          phxz 1 Reply Last reply Reply Quote 0
          • phxz
            phxz @Z03 last edited by

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

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

              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),
                  )
              
              1 Reply Last reply Reply Quote 1
              • R
                RY93 last edited by RY93

                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.

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

                  @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.

                  R 2 Replies Last reply Reply Quote 1
                  • R
                    RY 93 @backtrader last edited by

                    @backtrader Thanks I got it.

                    1 Reply Last reply Reply Quote 0
                    • R
                      RY 93 @backtrader last edited by

                      @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

                      1 Reply Last reply Reply Quote 0
                      • ?
                        A Former User last edited by

                        I was trying to backtest a 5 minute data feed and this didn't completely clarify it so I'll just leave here what I ended up doing to have as reference. My data is in the following format:
                        alt text
                        time,open,high,low,close,volume. And it goes from 2018-12-19 09:35:00. The datetime format is '%Y-%m-%d %H:%M:%S'.

                        I was trying to do it like this

                        data = bt.feeds.GenericCSVData(
                            dataname=datapath,
                            timeframe=bt.TimeFrame.Minutes,
                            compression=5,
                            sessionstart=datetime.datetime(2018, 12, 19, 9, 35, 0),
                            sessionend=datetime.datetime(2019, 5, 22, 16, 30, 0),
                            datetime=0,
                            open=1,
                            high=2,
                            low=3,
                            close=4,
                            volume=5,
                        )
                        

                        and I was getting an IndexError: list index out of range. Doing it like this solved the problem:

                        data = bt.feeds.GenericCSVData(
                                dataname=datapath,
                                timeframe=bt.TimeFrame.Minutes,
                                compression=1, # The data is already at 5 minute intervals
                                fromdate=datetime.datetime(2018, 12, 20, 9, 30),
                                todate=datetime.datetime(2019, 5, 22, 16, 30),
                                sessionstart=datetime.time(9, 30),
                                sessionend=datetime.time(16, 30),
                                dtformat='%Y-%m-%d %H:%M:%S',
                                datetime=0,
                                time=-1,
                                open=1,
                                high=2,
                                low=3,
                                close=4,
                                volume=5,
                                openinterest=-1,
                                headers=1,
                                separator=",",
                                reverse=True
                            )
                            data.addfilter(bt.filters.SessionFilter(data))
                            cerebro.adddata(data)
                        
                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors