Clone our Wealth-Lab 8 Extension Demo project on GitHub to get a head start in developing your own Extensions!

Optimization Visualizer API

Updated for WL8

This document details the API for building Optimization Visualizer Extensions for Wealth-Lab 8. An Optimization Visualizer occupies a tab in the Optimization Results section of the Strategy window's Optimization section, and lets you present the results of an optimization in a particular way.

You can create an Optimization Visualizer in a .NET development tool such as Visual Studio, or Visual Studio Code. Create a class library project that targets .NET6, then references the WealthLab.Core and the WealthLab.WPF library DLLs that you'll find in the WL8 installation folder.

Your Optimization Visualizer will be a class in this library that descends from OptimizationVisualizerBase, which is defined in the WealthLab.WPF library, in the WealthLab.WPF namespace. After you implement and build your library, simply copy the resulting assembly DLL into the WL8 installation folder. The next time WL8 starts up, it will discover your Optimization Visualizer, and a tab for it will appear after an optimization is completed.

Create Class Library in Visual Studio

ResultViewerBase

Although your Optimization Visualizer will derive from OptimizationVisualizerBase, OptimizationVisualizerBase itself derives from another class called ResultViewerBase. ResultViewerBase derives directly from WPF's UserControl, and it gives your class some additional members. See the ResultViewerBase reference for details on this class. In particular, the ViewerName and GlyphResource properties control the text and image that appear in the Visualizer's tab in WL8.

Creating the Files in Visual Studio

To get started, it's best to create a new UserControl in Visual Studio, which generates the boilerplate XAML and CS classes. Next, change the CS file so that your class derives from OptimizationVisualizerBase instead of UserControl. You'll need to add WealthLab.WPF to the using clause. Now, go to the XAML file, add an XMLNS directive to bring in the WealthLab.WPF library, and change the base class in the XAML from UserControl to OptimizationVisualizerBase. Here an example of what part of such a XAML file will look like:

enter image description here

Accessing the WL8 Host Environment

Use the WLHost.Instance property to access various aspects of the WL8 environment. See the API reference for the IHost interface for details.

Type of Optimization Supported

public virtual bool ForStandardOptimizations

You can build an Optimization Visualizer for either standard optimizations, or for walk-forward (WFO) optimizations. Return true here for standard, and false for WFO.

Visualizing Optimization Results

public virtual void Clear()

WL8 calls this method right at the start of an optimization. You should clear out any previous visual information in your Optimization Visualizer.

public List<string> MetricNames

Returns a list of the performance metrics that the user had selected when the optimization was started. These are the metrics that are returned in the OptimizationResult instances that are stored in the resulting StrategyOptimizer instance's Results property.

public OptimizerBase OptimizationMethod

Returns the instance of the OptimizerBase-derived class that was selected at the start of the optimization.

Visualizing Standard Optimizations

public virtual void Populate(StrategyOptimizer stratOpt)

This method is called when an optimization is completed and your OV needs to visualize the results. The StrategyOptimizer instance passed in stratOpt contains any of the required information about the optimization. Most importantly, it contains the Results property, which is an instance of the OptimizationResultList class (derived from List<OptimizationResult>.) The Results property allows you to examine the OptimizationResult instances in order to visualize them.

public StrategyOptimizer StrategyOptimizer

Returns the StrategyOptimizer instance that conducted the optimization.

public virtual bool SupportsInterimUpdates

Return true if your OV supports interim updates. That is, it can updates its visualization based on partial updates of the optimization.

public virtual void InterimPopulate(StrategyOptimizer stratOpt, List<OptimizationResult> newResults)

WL8 will call this method if your OV indicated it supports interim updates by returning true for its SupportsInterimUpdates property. Your OV is passed a list of new OptimizationResult instances that it can integrate with its existing visualization.

public virtual void PopulateWithTheseValues(OptimizationResult or)

Certain Optimization Visualizers allow the user to push a selected run's values into the other Optimization Visualizers. When this occurs, WL8 calls this method. You should update the visual information, if appropriate, so that is reflects the run passed in the or parameter.

Visualizing Walk-Forward Optimizations

public virtual void PopulateWFO(WFOOptimizer wfoOpt)

This method is called when a Walk-Forward optimization is completed and your OV needs to visualize the results. The WFOOptimizer instance passed in wfoOpt contains any of the required information about the optimization.

public WFOOptimizer WFOOptimizer

Returns the WFOOptimizer instance that conducted the optimization.

Interacting with the Strategy Window

public IOptimizationHost ParentOptimizationWindow

This property returns an instance of the IOptimizationHost interface, which contains properties and methods that allow you to interact with the optimization section of the Strategy window hosting your Optimization Visualizer. This instance contains a property called StrategyHost which returns an instance of the IStrategyHost interface, providing additional hooks into the Strategy window.

protected void SaveParameterDefaults(OptimizationResult or, FrameworkElement confirmElement = null)

Call this method to cause the Strategy window to set the Strategy Parameters default values to the values in the specified instance of OptimizationResult (or parameter). You can optionally pass a FrameworkElement instance (confirmElement parameter) that will cause an animated confirmation to appear over that element.

One example of where this is done is in the Optimization Tabular Visualizer. A right click menu allows to the user to set the Strategy parameter defaults to the values of the selected optimization run. Optimization Visualizer API