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/

    Accessing analysers in a strategy

    Indicators/Strategies/Analyzers
    2
    4
    551
    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.
    • L
      livecat last edited by

      Hi, are there any examples anywhere of using an analyser within a strategy that can reference? I'd like to print analyser results from the stratagys' stop() method when running Cerebro.optstrategy.

      Thanks

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

        There is an attribute holding all analyzers, which you can access via self or the strategy instance. At any time.

        • https://cookbook.backtrader.com/documentation/analyzers/analyzers/
        1 Reply Last reply Reply Quote 0
        • L
          livecat last edited by

          Thanks for that. I had read that but couldn't quite get to grips with the correct way of accessing an analysers' final value from within the strategy, since the stop method of the analyser needs be called before rets contains any value. eg.

          ipdb> self.analyzers.mysharpe.rets
          OrderedDict()

          ipdb> self.analyzers.mysharpe.stop()

          ipdb> self.analyzers.mysharpe.rets
          OrderedDict([('sharperatio', 0.0018162347783349845)])

          But self.analyzers.mysharpe.stop() only gets called after self.stop()

          So I guess my question is: Is there a recommended way to do what I'm trying to do that I have completely missed?
          Best.

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

            Because Strategy.stop() is a place where the strategy could still (in theory) do something which affects what an analyzer sees.

            For analyzers which calculate things during next it's a good point, for analyzers which wait until everything is complete, you will have to fetch it afterwards.

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