Class TradeStats
- Namespace
- Balsam
- Assembly
- Balsam.Backtester.dll
Encapsulates the results of a strategy simulation.
[ProtoContract]
[ProtoInclude(95, typeof(EquityCurveStats))]
public class TradeStats
- Inheritance
-
TradeStats
- Derived
- Inherited Members
- Extension Methods
Fields
excelMoney
A custom format string for currency values displayed in Excel.
protected const string excelMoney = "_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"
Field Value
Properties
AuditTrailId
Gets a globally unique identifier for this object.
public string AuditTrailId { get; set; }
Property Value
AvgBarsInLosers
Gets the average number of bars in losing trades.
public double AvgBarsInLosers { get; }
Property Value
AvgBarsInUnchanged
Gets the average number of bars in unchanged trades.
public double AvgBarsInUnchanged { get; }
Property Value
AvgBarsInWinners
Gets the average number of bars in winning trades.
public double AvgBarsInWinners { get; }
Property Value
AvgBarsPerTrade
Gets the average number of bars in all trades.
public double AvgBarsPerTrade { get; }
Property Value
AvgLosingTrade
Gets the average losing trade in dollars.
public double AvgLosingTrade { get; }
Property Value
AvgLosingTradePercent
Gets the average P&L of losing trades.
public double AvgLosingTradePercent { get; }
Property Value
AvgTrade
Gets the average P&L of all trades.
public double AvgTrade { get; }
Property Value
AvgTradePerContract
Gets the average P&L of all trades on a single contract basis.
public double AvgTradePerContract { get; }
Property Value
AvgTradePercent
Gets the average percent gain or loss for all trades.
public double AvgTradePercent { get; }
Property Value
AvgWinToAvgLoss
Gets the ratio of average winning trades to average losing trades.
public double AvgWinToAvgLoss { get; }
Property Value
AvgWinToAvgLossPercent
Gets the ratio of average winning trades percent gain to average losing trades percent loss.
public double AvgWinToAvgLossPercent { get; }
Property Value
AvgWinningTrade
Gets the average P&L of winning trades.
public double AvgWinningTrade { get; }
Property Value
AvgWinningTradePercent
Gets the average percent gain for winning trades.
public double AvgWinningTradePercent { get; }
Property Value
ClosedPnL
Gets the total P&L of all closed trades.
public double ClosedPnL { get; }
Property Value
ClosedTrades
Gets the number of closed trades.
public int ClosedTrades { get; }
Property Value
Commissions
Gets total commissions paid.
public double Commissions { get; }
Property Value
ElapsedTime
Gets the time it took to run the simulation (including money management if any).
public TimeSpan ElapsedTime { get; }
Property Value
Expectation
Gets the expectation.
public double Expectation { get; }
Property Value
ExpectationPercent
Gets the expectation calculated using AvgWinToAvgLossPercent
public double ExpectationPercent { get; }
Property Value
GeometricAvgTrade
Gets the geometric average trade.
public double GeometricAvgTrade { get; }
Property Value
GrossPnL
Gets the Open + Closed P&L gross of commissions and slippage.
public double GrossPnL { get; }
Property Value
IgnoreSpreads
Used internally in money manager reporting routines.
public bool IgnoreSpreads { get; set; }
Property Value
Kelly
Gets the Kelly criterion.
public double Kelly { get; }
Property Value
LargestLosingTrade
Gets the P&L of the largest losing trade.
public double LargestLosingTrade { get; }
Property Value
LargestLosingTradePercent
Gets the largest losing trade's percent loss.
public double LargestLosingTradePercent { get; }
Property Value
LargestWinningTrade
Gets the P&L of the largest winning trade.
public double LargestWinningTrade { get; }
Property Value
LargestWinningTradePercent
Gets the largest winning trade's percent gain.
public double LargestWinningTradePercent { get; }
Property Value
LongLosses
Gets the number of long trades that were losers.
public int LongLosses { get; }
Property Value
LongLossesPnL
Gets the total P&L of losing long trades.
public double LongLossesPnL { get; }
Property Value
LongPercentProfitable
Gets the percentage of profitable long trades.
public double LongPercentProfitable { get; }
Property Value
LongPnL
Gets the total P&L of all long trades.
public double LongPnL { get; }
Property Value
LongTrades
Gets the number of long trades.
public int LongTrades { get; }
Property Value
LongWins
Gets the number of winning long trades.
public int LongWins { get; }
Property Value
LongWinsPnL
Gets the total P&L of all winning long trades.
public double LongWinsPnL { get; }
Property Value
LosingPnL
Gets the total P&L all all losing trades.
public double LosingPnL { get; }
Property Value
LosingTrades
Gets the total number of losing trades.
public int LosingTrades { get; }
Property Value
MaxConsecutiveLosses
Gets the number of maximum consecutive losses.
public int MaxConsecutiveLosses { get; }
Property Value
MaxConsecutiveLossesPnL
Gets the P&L of the maximum consecutive losing streak.
public double MaxConsecutiveLossesPnL { get; }
Property Value
MaxConsecutiveWins
Gets the number of maximum consecutive wins.
public int MaxConsecutiveWins { get; }
Property Value
MaxConsecutiveWinsPnL
Gets the P&L of the maximum consecutive winning streak.
public double MaxConsecutiveWinsPnL { get; }
Property Value
MedianTradePercent
Gets the median percent gain or loss of all trades.
public double MedianTradePercent { get; }
Property Value
NetPnL
Gets the Open + Closed P&L.
public virtual double NetPnL { get; }
Property Value
OpenPnL
Gets the total P&L of all currently open trades.
public double OpenPnL { get; }
Property Value
OpenTrades
Gets the number of open trades.
public int OpenTrades { get; }
Property Value
Optimalf
Gets the optimal f value.
public double Optimalf { get; }
Property Value
OptimizationProperties
Gets optimization parameters in the form ParameterName1=value|ParameterName2=value|etc. or null if results were not from an optimization run.
public VariableDictionary OptimizationProperties { get; set; }
Property Value
PercentProfitable
Gets the percentage of trades that were profitable.
public double PercentProfitable { get; }
Property Value
ProfitFactor
Gets the profit factor, or absolute value of winning P&L to losing P&L.
public double ProfitFactor { get; }
Property Value
RollCommissions
Gets total commissions paid for rolls.
public double RollCommissions { get; }
Property Value
RollContractsTraded
Gets the total number of contracts rolled.
public double RollContractsTraded { get; }
Property Value
RollSlippage
Gets the total amount of slippage incurred on rolls.
public double RollSlippage { get; }
Property Value
Rolls
Gets the total number of rolls.
public int Rolls { get; }
Property Value
Runtime
Gets the timestamp when the results were run.
public DateTime Runtime { get; }
Property Value
ShortLosses
Gets the number of short trades that were losers.
public int ShortLosses { get; }
Property Value
ShortLossesPnL
Gets the total P&L of all losing short trades.
public double ShortLossesPnL { get; }
Property Value
ShortPercentProfitable
Gets the percentage of profitable short trades.
public double ShortPercentProfitable { get; }
Property Value
ShortPnL
Gets the total P&L of all short trades.
public double ShortPnL { get; }
Property Value
ShortTrades
Gets the number of short trades.
public int ShortTrades { get; }
Property Value
ShortWins
Gets the number of winning short trades.
public int ShortWins { get; }
Property Value
ShortWinsPnL
Gets the total P&L of all winning short trades.
public double ShortWinsPnL { get; }
Property Value
Slippage
Gets the total amount of slippage incurred.
public double Slippage { get; }
Property Value
StdDevTradePercent
Gets the standard deviation of all trades' percent returns.
public double StdDevTradePercent { get; }
Property Value
StopsHit
Gets or sets the number of closed positions for which the last exit was a stop order type. Can be useful in optimizations to see how many times a stop-loss is responsible for closing out a position. This can also be set by the user if more nuanced calculations are required.
public int StopsHit { get; set; }
Property Value
StopsHitPct
Gets the number of stop exits as a percent of total trades.
public double StopsHitPct { get; }
Property Value
StrategyNames
Gets/sets the name(s) of the strategy.
public string StrategyNames { get; set; }
Property Value
Symbols
Gets the symbol(s) on which the simulation was run.
public string Symbols { get; }
Property Value
TStat
Gets the t-statistic using percent return of the trades.
public double TStat { get; }
Property Value
TWR
Gets Terminal Wealth Relative, or the total gain from compounding all trades.
public double TWR { get; }
Property Value
Tag
Gets/sets a convenience field for the user to store any arbitrary object. Note this property is not serialized.
[ProtoIgnore]
public object Tag { get; set; }
Property Value
TargetsHit
Gets/sets the number of closed positions for which the last exit was a limit order type. Can be useful in optimizations to see how many trades were exited on a target. This can also be set by the user if more nuanced calculations are required.
public int TargetsHit { get; }
Property Value
TargetsHitPct
Gets the number of limit exits as a percent of total trades.
public double TargetsHitPct { get; }
Property Value
TotalContractsTraded
Gets the total number of contracts/shares in round turns. (i.e. entry side only).
public double TotalContractsTraded { get; }
Property Value
Trades
Gets the total number of trades.
public int Trades { get; }
Property Value
Turnover
Gets turnover.
public double Turnover { get; }
Property Value
UnchangedTrades
Gets the total number of unchanged trades.
public int UnchangedTrades { get; }
Property Value
WinningPnL
Gets the total P&L of all winning trades.
public double WinningPnL { get; }
Property Value
WinningTrades
Gets the number of winning trades.
public int WinningTrades { get; }
Property Value
Methods
Calculate(IEnumerable<Position>)
Calculates trade stats based on the specified list of positions.
public void Calculate(IEnumerable<Position> positions)
Parameters
positions
IEnumerable<Position>
Equals(TradeStats, TradeStats, double, bool, bool)
Returns true if all deterministic properties are equal.
public static bool Equals(TradeStats left, TradeStats right, double tolerance = 1E-10, bool strict = true, bool reportDifferences = false)
Parameters
left
TradeStatsright
TradeStatstolerance
doublestrict
boolWhen true, types must be identical. When false, the union of properties will be compared. This allows for different or derived TradeStat types to be compared.
reportDifferences
boolOutput differences to console.
Returns
GetSummary()
Returns a summary presentation of the trade stats suitable for printing to the console.
public string GetSummary()
Returns
OnCalculate(IEnumerable<Position>)
Trade stats calculations take place here.
protected virtual void OnCalculate(IEnumerable<Position> trades)
Parameters
trades
IEnumerable<Position>
ToString()
Returns a string representation of the trade stats.
public override string ToString()