For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Accessing analysers in a strategy

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


  • administrators

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

  • 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

    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?

  • administrators

    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.

Log in to reply