Customize backtest reports
Change the default template
Backtest reports are customizable by creating or modifying Excel templates. By default, the money manager will look for a file named MoneyManagementTemplate.xltx in the Templates folder. To use a different template, set the MoneyManager.Options.Template
property or override the default by changing the SettingsManager.MoneyManagementTemplate
property.
var mm = new FixedFractional() { PercentToRisk = 0.001 };
mm.Options.Template = @"Templates\ComparisonTemplate.xltx";
mm.Options.Template = @"C:\temp\MyCoolTemplate.xltx"; //absolute paths are fine too
mm.DataStore = Balsam.Data.DataStore.Load(@"c:\temp\simpleSma.bds");
mm.RunSimulation();
Create a custom template
Templates contain a hidden worksheet called '_Data' where raw performance statistics are dumped by the backtester. After running a backtest using a built-in template, unhide the _Data worksheet in Excel to see what fields are available. To create you own custom 'Performance Stats` worksheet, use Excel lookup formulas to pull the desired values from the _Data worksheet and format them for display. Be sure to save your creation as an Excel template (file type .xltx). Change your default settings to use this new template going forward.
Custom performance stats
You can also extend the PerformanceStats
class to support custom performance metrics. For example, if we wanted to report the correlation of our system's returns to a benchmark we could create a custom performance stats class and override the OnCalculate()
method.
class CustomPerformanceStats : PerformanceStats
{
public double CorrelationToBenchmark
{
get;
private set;
}
protected override void OnCalculate(TimeSeries equityCurve)
{
base.OnCalculate(equityCurve);
var benchmark = TimeSeries.Load(@"c:\data\benchmark.csv"); //this assumes Date,Close format
CorrelationToBenchmark = Indicators.Correlation(benchmark.PercentChange(), GetDailyReturns());
}
}
Next we need to inform the money manager assigned to our strategy to use this custom class by setting the Options.PerformanceStats
property.
strat.MoneyManager.Options.PerformanceStats = typeof(CustomPerformanceStats);
Alternatively, we could set the SettingsManager.PerformanceStats
property which acts as the default when money managers are created. If you'd like to make this change permanent, call SettingsManager.Save()
. Remember to add the saved settings.xml file to your Visual Studio project and copy it to the output directory so the backtester can find it at runtime.
SettingsManager.PerformanceStats = typeof(CustomPerformanceStats);
SettingsManager.Save();
When we run the backtest, the CorrelationToBenchmark
value will be output to the hidden _Data worksheet. To display this stat on the "Performance Stats" worksheet you will also need to create a new custom template or modify an existing one. See custom template above for instructions.