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/

    Daily Absolute PnL For A Strategy

    Indicators/Strategies/Analyzers
    analyzer
    2
    3
    470
    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.
    • A
      aceBox last edited by

      Hello,

      Is there a way to get the absolute daily PnL for a strategy? I am aware of the Time Return analyzer, but it calculates the returns on the beginning of a timeframe. What I require is, say if I am testing a strategy from Jun 1, 2019 to Sep 1, 2019, then I want to get daily profit / loss (in absolute sense rather than a percent return) as well as cumulative profit / loss for this time period. Is there a direct way to do this, without having to calculate the same via Time Return?

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

        I believe that TimeReturn analyzer with the timeframe parameter set to TimeFrame.Days will calculate daily returns in %s. So at first glance the easiest way will be just to repeat TimeReturn analyzer code with the small change:

        now

        self.rets[self.dtkey] = (self._value / self._value_start) - 1.0
        

        need

        self.rets[self.dtkey] = self._value - self._value_start
        
        • 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
        A 1 Reply Last reply Reply Quote 1
        • A
          aceBox @ab_trader last edited by

          @ab_trader Thanks. So apparently, inheriting TimeReturn would be the only elegant way to go forward. I implemented that and it works perfectly.

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