BacktestSettings
Namespace: WealthLab.Backtest
Parent: Object

The BacktestSettings class contains information about how a backtest was conducted, including the benchmark symbol used, and whether cash interest and dividends were considered.

Members
BenchmarkSymbol
public string BenchmarkSymbol

The symbol to use for the comparison benchmark backtest, which is a buy & hold run that is displayed side by side with the backtest results for the Strategy.

Deprecated for Build 4+

  • Specify the Benchmark Symbol on a per-Strategy basis in the Strategy Settings.

CashInterestRate
public double CashInterestRate

The percentage amount of interest that simulated cash in the backtest should generate.


CollectDividends
public bool CollectDividends

If set to true, simulated dividends will be collected during the backtest. Dividends are calculated based on EventDataPoint instances in the BarHistory instances being tested, and data points with the Name "dividend" are considered. Deduping logic is in place to ensure that only one dividend per date is accounted for, even if multiple Event Data Providers that supply dividends are enabled.


CommissionAmount
public double CommissionAmount

Specifies the amount to use for backtest simulated commissions. Works in conjunction with the CommissionType property.


CommissionType
public CommissionTypes CommissionType

Specifies the commission type used in the backtest. Possible values are:

  • None
  • Flat - CommissionAmount specifies total commission per trade
  • PerShare - CommissionAmount specifies commission per share/contract traded

FuturesMode
public bool FuturesMode

If set to true, the backtest will be run in "futures mode", and take account of each symbol's Margin, PointValue, and Tick values when calculating gains and losses.


MarginInterestRate
public double MarginInterestRate

The percentage amount that simulated margin interest should be charged during the backtest.


RetainNSFPositions
public bool RetainNSFPositions

This setting overrides the Backtest Preference: Retain NSF Positions

If set to true, the Backtester will internally retain and continue to process positions for which there was insufficient capital to complete the simulated fill. This preserves the internal integrity of a Strategy, preventing it from potentially signaling new buy orders as an NSF position continues to be held until its eventual exit conditions are met. It also allows you to see exit signals for positions that might have been NSF in the simulation, but that you have actually filled in your live trading.

Set this to false to cause the Backtester to ignore NSF positions. This can reduce the overhead for certain Strategies that results in a faster backtest, but can also cause new buy signals to trigger at different places, depending on available simulated capital.

Example Code
using WealthLab.Backtest;
using System;
using WealthLab.Core;
using WealthLab.Indicators;
using System.Drawing;
using System.Collections.Generic;

namespace WealthScript
{
	public class MyStrategy : UserStrategyBase
	{
		//create indicators and other objects here, this is executed prior to the main trading loop
		public override void Initialize(BarHistory bars)
		{
			//override the Retain NSF Positions backtest setting
			BacktestSettings.RetainNSFPositions = false;

			//begin the backtest at bar 13
			StartIndex = 13;

			_sma1 = SMA.Series(bars.Close, 8);
			_sma2 = SMA.Series(bars.Close, 13);

			PlotIndicatorLine(_sma1, Color.Blue);
			PlotIndicatorLine(_sma2, Color.Red);
		}

		//execute the strategy rules here, this is executed once for each bar in the backtest history
		public override void Execute(BarHistory bars, int idx)
		{
			if (!HasOpenPosition(bars, PositionType.Long))
			{
				if (_sma1.CrossesOver(_sma2, idx))
					PlaceTrade(bars, TransactionType.Buy, OrderType.Market);

			}
			else
			{
				if (_sma1.CrossesUnder(_sma2, idx))
					PlaceTrade(bars, TransactionType.Sell, OrderType.Market);
			}
		}

		//declare private variables below
		IndicatorBase _sma1;
		IndicatorBase _sma2;

	}
}

RoundLots
public bool RoundLots

If set to true, Transaction Quantity will be rounded to the nearest 100 shares/contracts, or the nearest 10 if under 100.


UseMarginInBenchmark
public bool UseMarginInBenchmark

By default, the comparison benchmark buy and hold backtest does not employ margin. Set this to true to have it employ the same Margin value in the backtest's PositionSize property.


UseUSTRateAsInterest
public bool UseUSTRateAsInterest

If set to true, the CashInterest property will be ignored, and the percentage rate for simulated interest on cash will be determined by the yield of the US Treasury. The US Treasury period to use for this purpose is set in the YieldPeriod property.


VolumeLimit
public double VolumeLimit

If greater than zero, will limit the Quantity of a Transaction to that percentage of the entry bar's volume.


YieldPeriod
public YieldPeriods YieldPeriod

The period of US Treasury yield to use when UseUSTRateAsInterest is set to true. Possible values are:

  • OneMonth
  • ThreeMonth
  • SixMonth
  • OneYear
  • TwoYear
  • ThreeYear
  • FiveYear
  • SevenYear
  • TenYear
  • TwentyYear
  • ThirtyYear