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

Optimization Visualizer API

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.

Build Environment

You can create an Optimization Visualizer in a .NET development tool such as Visual Studio 2022. Create a class library project that targets .NET8, then reference the WealthLab.WPF library DLL that you'll find in the WL8 installation folder.

Note: If you are using Visual Studio 2022, it will need to be updated to at least version 17.8.6 to use .NET8.

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, making it available in appropriate locations of the WL8 user interface.

Visual Studio 2022 Build Environment

Accessing the Host (WL8) Environment

The IHost interface allows your extension to access information about the user's WealthLab environment. For example, the location of the user data folder, or obtaining a list of DataSets defined by the user. At any point in your extension's code base, you can access an instance of the IHost interface using the singleton class WLHost and its Instance property. Example:

//get user data folder
string folder = WLHost.Instance.DataFolder;

ResultViewerBase

OptimizationVisualizerBase is derived from the ResultViewerBase base class, defined in WealthLab.WPF. ResultViewerBase is derived from the WPF UserControl. ResultViewerBase contains additional members that can be useful when developing Visualizers. 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.

Open the XAML file and add an XMLNS reference to the WealthLab.WPF library. 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

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 update 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