API documentation, members, signatures, and C# examples.
Search the framework
Find classes, members, and documentation.
NamespaceWealthLab.Backtest
Parent
Object
Contains the information saved from a WealthLab optimization run, including the Strategy, Optimizer, position sizing, backtest settings, optimization parameters, and generated results.
SavedOptimizationResults supports standard, Walk-Forward Optimization (WFO), and Symbol-by-Symbol optimization runs.
The parameterless constructor creates an empty SavedOptimizationResults instance.
The second constructor initializes the instance from Strategys and Optimizer opt. It captures the Strategy's optimized parameters, PositionSize, benchmark, symbol or DataSet settings, scale, data range, and BacktestSettings, along with the Optimizer and its Parameters.
The third constructor additionally assigns the specified WFOOptimizer and sets RunType to OptimizationRunType.WFO.
public static SavedOptimizationResults Parse(string s)
Creates and returns a SavedOptimizationResults instance from a string previously generated by Persist.
Parse restores the Strategy and Optimizer by their saved names using StrategyFactory and OptimizerFactory, restores their Parameters and settings, and reconstructs the PositionSize, HistoryScale, DataRange, and BacktestSettings.
For WFO results, the method also recreates and parses the WFOOptimizer.
For Symbol-by-Symbol results, it recreates the SymBySym Dictionary and its OptimizationResultList values.
Parse also applies several restored settings back to the Strategy instance, including PositionSize, Benchmark, SingleSymbol mode, Symbol, DataSetName, Scale, and DataRange.
An ArgumentException is thrown if the saved Strategy or Optimizer cannot be found.
C# example
using System.IO;
using WealthLab.Backtest;
using WealthLab.Core;
namespace WealthScript
{
public class SavedOptimizationExample : UserStrategyBase
{
public override void Initialize(BarHistory bars)
{
string folder = Path.Join(
WLHost.Instance.DataFolder,
"SavedOptimizations");
string[] files =
Directory.GetFiles(folder, "*.WL9Opt");
if (files.Length == 0)
return;
string persisted =
File.ReadAllText(files[0]);
SavedOptimizationResults saved =
SavedOptimizationResults.Parse(persisted);
WriteToDebugLog(
"Run type: " + saved.RunType);
WriteToDebugLog(
"Results: " + saved.Results.Count);
WriteToDebugLog(
"Complete: " + saved.IsComplete);
}
public override void Execute(BarHistory bars, int idx)
{
}
}
}
Returns an encoded string containing the SavedOptimizationResults configuration and results.
The persisted information includes:
RunType
Results
IsComplete
Strategy qualified name
Strategy Parameters
Optimizer name, Parameters, and internal state
PositionSize
BenchmarkSymbol
SingleSymbol mode
Symbol
DataSetName
HistoryScale
DataRange
BacktestSettings
For WFO runs, the WFOOptimizer state is also persisted.
For Symbol-by-Symbol runs, the symbol keys and corresponding OptimizationResultList values in SymBySym are also persisted.
The returned string can later be passed to Parse to recreate the SavedOptimizationResults instance.
Indicates whether the saved optimization run completed normally.
A false value can indicate that the saved run represents an incomplete or paused optimization.
Gets or sets the Parameters associated with Optimizer.
When a SavedOptimizationResults instance is parsed, this property references the Optimizer's restored ParameterList.
Gets or sets the OptimizationResultList containing the optimization results.
For standard and WFO optimization runs, this property contains the primary set of results.
A new SavedOptimizationResults instance initializes Results to an empty OptimizationResultList.
Gets or sets the Strategy Parameters captured when the optimization results were saved.
These Parameters preserve the optimization state used for the run, including which Parameters were enabled for optimization.
public Dictionary<string, OptimizationResultList> SymBySym
Gets or sets the Symbol-by-Symbol optimization results.
The Dictionary key is the symbol and the corresponding value is that symbol's OptimizationResultList.
This property is used when RunType is OptimizationRunType.SymbolBySymbol.
A new SavedOptimizationResults instance initializes SymBySym to an empty Dictionary.
Gets or sets the WFOOptimizer associated with the saved results.
This property is used when RunType is OptimizationRunType.WFO.
The default value is null.
Need help with this API?
Ask the community or explore custom development services.