Parent: Object
A helper class that provides a simplified way to run Strategy backtests and optimizations programmatically. StrategyRunner can be used from a WealthLab Extension or directly from Strategy code.
Before running a backtest or optimization, configure its data source, scale, data range, position sizing, backtest settings, and benchmark as required.
StrategyRunner implements IOptimizationHost and IOptimizerHost so that it can host and execute a StrategyOptimizer programmatically.
Determines the BacktestSettings to use for backtests and optimizations.
The default value is BacktestSettings.Instance.
Specifies a BarHistory instance to use for the benchmark backtest. Benchmark performance is used when calculating certain performance metrics such as Alpha and Beta. If this property is null or empty, StrategyRunner attempts to load benchmark data using the symbol specified in BenchmarkSymbol.
Specifies the symbol to use for the benchmark backtest.
If BenchmarkData is null or empty, StrategyRunner attempts to load historical data for this symbol using the configured Scale and DataRange.
The default value is "SPY".
Contains the BarHistory instances to use as the source data for a backtest or optimization. You can populate this property directly when you already have the historical data you want StrategyRunner to use. If Data is null or empty, StrategyRunner attempts to obtain historical data from DataSet first, followed by Symbols.
Determines the historical data range to use when StrategyRunner loads data. The default range is the most recent 10 years.
Specifies a DataSet to use as the source of historical data. If Data is null or empty and this property is assigned, StrategyRunner loads historical data for the DataSet's symbols using the configured Scale and DataRange. If no data can be obtained from the DataSet, StrategyRunner next attempts to load the symbols contained in Symbols.
Performs an optimization using the Optimization Method specified by name in optMethod.
There are two overloads. The first specifies the Strategy by its saved Strategy name in stratName. The second accepts a Strategy instance in s.
Before calling this method, configure the StrategyRunner's data source, scale, range, position sizing, backtest settings, and benchmark as required.
The optional runComplete parameter can specify an OptimizationRunComplete delegate. StrategyRunner calls this delegate after each optimization run completes. The callback receives the completed OptimizationResult and a double containing the estimated percentage of the overall optimization that has completed.
The optional optParamValues parameter is a List of objects containing values for the selected Optimizer's Parameters. The values correspond by index to the Parameters exposed by the Optimizer.
Strategy parameters that are disabled for optimization remain disabled when the optimization is executed through StrategyRunner.
Returns an OptimizationResultList containing the results of the optimization runs.
Determines the PositionSize to use for backtests and optimizations. The default position size is 10% of equity.
Runs a Strategy backtest and returns the resulting Backtester instance. The first overload accepts the name of a saved WealthLab Strategy. StrategyRunner locates the Strategy, creates an executable instance, and runs the backtest. The second overload accepts an already compiled StrategyBase instance in sb. The optional s parameter specifies the Strategy associated with the compiled instance, while em specifies the StrategyExecutionMode. Before executing the Strategy, StrategyRunner obtains the required historical and benchmark data and creates a Backtester using the configured PositionSize and BacktestSettings. After the Strategy backtest completes, StrategyRunner performs the benchmark backtest and assigns the results to the Backtester's BenchmarkBacktestResults property. You can examine the returned Backtester, including its Metrics property, to obtain the performance results of the backtest.
Determines the historical data scale, or frequency, to use when StrategyRunner loads data.
The default value is HistoryScale.Daily.
For intraday scales, StrategyRunner uses the scale's pre/post-market filtering setting when requesting historical data.
Contains symbols that StrategyRunner can use as the source of historical data. If Data is null or empty and no usable data is obtained from DataSet, StrategyRunner attempts to load historical data for the symbols contained in this list using the configured Scale and DataRange.
Returns the Backtester containing the benchmark results used during the current optimization.
Returns the currently selected ScoreCard metric names used during the optimization.
Returns the Strategy Parameters that are eligible for optimization.
Returns the OptimizerBase instance being used for the current optimization.
Returns the StrategyOptimizer instance being used for the current optimization.