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/

    handle missing data

    General Discussion
    4
    11
    2807
    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.
    • H
      hobart-liu last edited by hobart-liu

      Many thanks to author, this is a great tool that really release me from writing my own backtest framework!

      I am new to this tool. I am not sure whether this is stupid question, but I have been searching for a while, and finally decide come here for help.

      My problem is, I have two data feeds, one of them doesn't have trade data during, say 2015-11-02 ~ 2015-11-11. So when I try to run my strategy from 2015-11-1 to 2015-12-1, the system only feed my strategy with data start from 2015-11-12. I guess this is because one of my dataset has missing value.

      I know we can use forward fill to fill the missing value, but my neural network will probably not able to handle this way of filling. I shall give a clear signal to my strategy that between 2015-11-02 and 2015-11-11, the data is missing, so that I can skip this stock in my NN.

      What I expected is, the system shall feed my strategy from 2015-11-1, because one stock do has trading data...
      Thanks in advance. (If needed, I can post my code and result. )

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        Put trading logic in the prenext() function as well as in the next(). This should help.

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        H 1 Reply Last reply Reply Quote 0
        • H
          hobart-liu @ab_trader last edited by

          @ab_trader Does that mean, I shall use pretext() instead of next() in my strategy?

          A 1 Reply Last reply Reply Quote 0
          • A
            ab_trader @hobart-liu last edited by ab_trader

            @hobart-liu nope, prenext() is called before next(). You need to call trading logic in both functions. But in the prenext() you'll need to check the availability of data.

            Backtrader goes thru all datafeeds bar by bar. Until all datafeeds have values and all indicators have values it calls prenext(). After it calls next().

            • If my answer helped, hit reputation up arrow at lower right corner of the post.
            • Python Debugging With Pdb
            • New to python and bt - check this out
            1 Reply Last reply Reply Quote 0
            • spyamine
              spyamine last edited by

              but how can we disable this behaviour. if the data is available run if not wait until the data is available.

              Also how can we handle survivor ship bias. since there is stock that will come to live in a period then other that will die in the meantime.

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

                @spyamine said in handle missing data:

                but how can we disable this behaviour. if the data is available run if not wait until the data is available.

                You have access to prenext. That's the behavior.

                @spyamine said in handle missing data:

                Also how can we handle survivor ship bia

                You cannot. It's not the platform to do that.

                1 Reply Last reply Reply Quote 0
                • spyamine
                  spyamine last edited by

                  How can we imagine adding a support for survivor ship bias? is there any trick to use. Because it seems that backtesting do not start until the latest stock has the data available for it.

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

                    @spyamine said in handle missing data:

                    Because it seems that backtesting do not start until the latest stock has the data available for it.

                    backtesting starts when all data feeds and indicators have gone through its minimum warm-up period. Which in the trivial case of a data feed is 1.

                    @ab_trader said in handle missing data:

                    @hobart-liu nope, prenext() is called before next(). You need to call trading logic in both functions. But in the prenext() you'll need to check the availability of data.
                    Backtrader goes thru all datafeeds bar by bar. Until all datafeeds have values and all indicators have values it calls prenext(). After it calls next().

                    1 Reply Last reply Reply Quote 0
                    • spyamine
                      spyamine last edited by

                      ok how to check if the data is available ?

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

                        See: Docs - Platform Concepts specifically the section about the length of Lines objects.

                        This has been discussed several times.

                        1 Reply Last reply Reply Quote 0
                        • spyamine
                          spyamine last edited by

                          Many thanks and thank you for your patience

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