Backtrader Community

    • 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/

    Only 2 decimal places precision in stock trading backtest ?

    General Discussion
    4
    8
    714
    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.
    • S
      Saikee Wong last edited by

      If my understanding is correct, seems the backtrader round the data to 2 decimal place. which may be OK for US stocks. But HK stocks has 3 decimal places.

      Also, in yahoo data, after split, the historical data is adjusted which could result in may decimal place. Rounding to 2 decimals results in wrong backtest result.

      Am I right ?

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

        @Saikee-Wong said in Only 2 decimal places precision in stock trading backtest ?:

        Am I right ?

        I don;t think that bt limits decimal places. Why do you think so?

        • 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
        • run-out
          run-out last edited by

          I don't think this is correct. Where are you getting this notion from?

          RunBacktest.com

          1 Reply Last reply Reply Quote 0
          • S
            Saikee Wong last edited by

            I generated some test data to be backtested, the data are small values with 0.xxxxxxx

            In my trade strategy, in the next: method, I used self.data_close.get(size=N_days, ago=-0) to get the close prices for last few days, printed the return value, found that the values return are only 2 decimal places, not the original value with over 2 decimal places.

            Also, in the plot, I found the price is always plotted snapping to 0.01 increment.

            1 Reply Last reply Reply Quote 0
            • run-out
              run-out last edited by

              Could you add your code to this thread? We'll have a look for you.

              RunBacktest.com

              1 Reply Last reply Reply Quote 0
              • S
                Saikee Wong last edited by

                Having used the code for years, it messes up like spaghetti.

                In an attempt to dig a simplified version to post to here, I found the simplified code does not snap the price. After compare and test between the two set of codes, eventually figured out the problem comes from data feed method.

                In fetching data, if I use

                data0 = bt.feeds.YahooFinanceCSVData(...)

                the values will be snapped to 2 decimal places during execution.

                If I change it to

                data0 = bt.feeds.GenericCSVData(...)

                it maintain all the precision throughout.

                Thank you all for the response to enlighten me !

                1 Reply Last reply Reply Quote 0
                • Afonso Schulz Albrecht
                  Afonso Schulz Albrecht last edited by

                  Is there any answer? Having the same problem.

                  1 Reply Last reply Reply Quote 0
                  • Afonso Schulz Albrecht
                    Afonso Schulz Albrecht last edited by

                    answer found, apologies. New here and comments can't be deleted :(

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