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/

    StrategySkipError exception

    General Code/Help
    2
    2
    52
    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.
    • vladisld
      vladisld last edited by

      The documentation mentions that the StrategySkipError exception could be raised during the 'birth' to avoid backtesting the strategy, quoting:

      Note
      
      A strategy can be interrupted during birth by raising a StrategySkipError exception from the module backtrader.errors
      
      This will avoid going through the strategy during a backtesting. See the section Exceptions
      

      where the 'birth' phase is represented by the 'start' method:

      Birth: start
      
      The world (cerebro) tells the strategy is time to start kicking. A default empty method exists.
      

      However, looking at the code, the StrategySkipError is only handled during the strategy construction (i.e. Conception stage) in cerebro.py

      for stratcls, sargs, skwargs in iterstrat:
                  sargs = self.datas + list(sargs)
                  try:
                      strat = stratcls(*sargs, **skwargs)
                  except bt.errors.StrategySkipError:
                      continue  # do not add strategy to the mix
      

      Am I wrong?

      IMHO it could be beneficial to support raising the StrategySkipError during the 'start' method or even during 'next' method call.

      One scenario is where the live strategy may check if its cached state is in sync with the actual broker's position on startup.

      Another scenario is if strategy would like to be skipped in case it was started on non-trading days ( in order to save the machine up time for example, or save some CPU or log burden in multi strategy scenarios).

      Thanks
      Vlad

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

        @vladisld said in StrategySkipError exception:

        The documentation

        Docs - Exceptions - https://www.backtrader.com/docu/exceptions/

        That's the specific documentation for the exception and it clearly shows it is done during __init__

        @vladisld said in StrategySkipError exception:

        Am I wrong?

        No, it is shown in the docs.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }