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/

    Define which specific method you want to inherit from strategy.

    General Code/Help
    1
    1
    18
    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.
    • B
      BorutF last edited by

      I want to inherit some functions in my strategy from a parent class (BaseStrategy).

      Let's use this example:

      def notify_cashvalue(self, cash, value):
              if value < starting_cash * self.terminate_threshold:
                  self.log(f'Stopping strategy at due drop below {self.terminate_threshold * 100}% of initial cash.')
                  self.cerebro.runstop()
      

      This would be the function inside BaseStrategy and my actual strategy would inherit. This function requires that the terminate_threshold is defined in the child strategy. This could be a nuisance if I want to inherit the BaseStrategy, but I don't want that particular method. I know I could rewrite notify_cashvalue, however I would prefer to add the methods I want inherit instead of removing them. I want to customly compose the strategy instead of inheriting everything.

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