Performance Visualizer API
Updated for WL8
This document details the API for building Performance Visualizer Extensions for Wealth-Lab 8. A Performance Visualizer occupies a tab in the Backtest Results section of the Strategy window, and lets you present the results of a backtest in a particular way.
You can create a Performance 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 Performance Visualizer will be a class in this library that descends from VisualizerBase, 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 Performance Visualizer, and a tab for it will appear after a backtest is completed.
Although your Performance Visualizer will derive from VisualizerBase, VisualizerBase 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 VisualizerBase 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 VisualizerBase. Here an example of what part of such a XAML file will look like:
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.
Visualizers for Specific Strategy Types
public virtual bool AllowForStrategyType(StrategyTypes st)
You can optionally override this property to specify which Strategy type(s) are supported by your Visualizer. If a Strategy of an unsupported type is opened, your Visualizer will not be added as a tab in the backtest results section of the Strategy window. The StrategyTypes enum contains the following values:
Visualizing Backtest Results
public virtual void Initialize()
Override this method to implement any one-time initialization that your Visualizer requires.
public virtual void Populate(Backtester backtester, Backtester backtesterBenchmark)
Override this method to implement the visualization of a backtest. You are passed two instances of the Backtester class. The first instance, backtester, contains the results of the Strategy backtest. The second instance, backtesterBenchmark, contains the results of the benchmark backtest, which is a buy & hold run on the benchmark symbol.
Consult the Backtester class reference for a list of the various properties available that describe the backtest results. Most notably the Metrics property, which exposes all of the performance metrics that are generated by WL8 ScoreCards.
public Backtester Backtester
Returns the instance of the Backtester that contains the Strategy performance results.
public Backtester BacktesterBenchmark
Returns the instance of the Backtester that contains the benchmark buy & hold results.
Interacting with the Strategy Window
public IStrategyHost ParentStrategyWindow
This property returns an instance of the IStrategyHost interface, which contains properties and methods that allow you to interact with the Strategy window hosting your Visualizer. You can, for example, cause the Strategy window to chart a specific symbol.