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/

    Developing Own pnl & pnlcomm calculation

    General Code/Help
    3
    6
    1571
    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.
    • Michael Scofield
      Michael Scofield last edited by

      Hi all. I want to ask how to develop my own pnl & pnlcomm calculation. Should I inheritance the Trade class and override the "update" method, or there is other way to do so? And after I developed my own calculation how to apply this to the platform?
      Please give me some hints, thank you!

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

        The calculation of profit/loss and commissions is not in the Trade. This simply uses the reported values to update itself.

        How profit/loss and comissions are calculated is controlled by commission schemes. You can supply your own (for all assets or for assets individually) See

        • Commissions: Stocks vs Futures
        • Extending Commissions
        • User Defined Commissions

        See also this independent blog:

        • Backtest Rookies - Code Snippet: Stamp Duty Commission Scheme
        1 Reply Last reply Reply Quote 0
        • Richard O'Regan
          Richard O'Regan last edited by Richard O'Regan

          Hi backtrader, I'm just reading docs/code to understand your answer to Michael as I have similar question.. I think this is correct.

          Ok, so the code he'd need to override is here: 0_1504218522659_Untitled.png

          I'd like to use R multiples in the pnl instead or raw values. ( If this needs a separate post let me know. But I'm guessing I'd be in the same boat as Micheal?)
          Thanks for all your dedication.

          You can take the man out of the army, but you can't take the army out of the man.

          1 Reply Last reply Reply Quote 0
          • Michael Scofield
            Michael Scofield last edited by

            Thank you guys @Richard O'Regan @backtrader !

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

              Yes, that would be it. You later add it with: addcommissioninfo(comminfo, name) where name defaults to None to be the default for all assets.

              If the name matches the name of an asset it will be specifically applied to that asset.

              See: Docs - Broker for the reference

              Richard O'Regan 1 Reply Last reply Reply Quote 0
              • Richard O'Regan
                Richard O'Regan @backtrader last edited by

                @backtrader ahh got it, thanks for adding that. @Michael-Scofield no problem mate:)

                You can take the man out of the army, but you can't take the army out of the man.

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