For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
How to check the legality of parameters before running the test?
-
I backtest a double moving average strategy and want to optimize the two parameter,
shortma
andlongma
with the following codestrategies = cerebro.optstrategy(DoubleMA, shortma=range(5,30,5),longma=range(15, 50, 1)
Obviously,
shortma
shall be small thanlongma
, otherwise the strategy is meaningless. How should i add some code to check the legality of parameters in the__init__
, once the parameters is invalid, the strategy go thestop
. -
This is covered by raising a exception during
__init__
. See Docs - Exceptionsimport backtrader as bt class Strategy(bt.Strategy): def __init__(self): if something_goes_wrong(): raise bt.StrategySkipError