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

StrategySkipError exception

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

    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

    for stratcls, sargs, skwargs in iterstrat:
                sargs = self.datas + list(sargs)
                    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).


  • administrators

    @vladisld said in StrategySkipError exception:

    The documentation

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

Log in to reply