Class RiskStatisticsExtensions
The empirical risk measures (semi-variance, regret, value-at-risk, expected shortfall, …), from the samples of a
statistics tool that keeps them: QuantLib's GenericRiskStatistics<S>, which derives from its type
parameter, as C# 14 extension members over any IEmpiricalStatistics.
public static class RiskStatisticsExtensions
- Inheritance
-
RiskStatisticsExtensions
- Inherited Members
Remarks
QuantLib's RiskStatistics, GenericRiskStatistics<GaussianStatistics>, and its
Statistics typedef are GeneralStatistics with these members and those of
GaussianStatisticsExtensions.
ExpectedShortfall<TStat>(TStat, double) where no sample lies below the value-at-risk's level reads the level itself, 0 with no loss and the value-at-risk where the tail is an atom at that level, where QuantLib refuses "no data below the target": a documented divergence.
Methods
AverageShortfall<TStat>(TStat, double)
The averaged shortfallness, E[t − x | x < t].
public static double AverageShortfall<TStat>(this TStat stats, double target) where TStat : notnull, IEmpiricalStatistics
Parameters
statsTStattargetdoubleThe target.
Returns
- double
The average shortfall.
Type Parameters
TStat
Exceptions
- NanoQLException
No sample lies below the target.
DownsideDeviation<TStat>(TStat)
The downside deviation, the square root of the downside variance.
public static double DownsideDeviation<TStat>(this TStat stats) where TStat : notnull, IEmpiricalStatistics
Parameters
statsTStat
Returns
- double
The downside deviation.
Type Parameters
TStat
Exceptions
- NanoQLException
There are fewer than two negative samples.
DownsideVariance<TStat>(TStat)
The variance of observations below 0, N/(N − 1) E[x² | x < 0].
public static double DownsideVariance<TStat>(this TStat stats) where TStat : notnull, IEmpiricalStatistics
Parameters
statsTStat
Returns
- double
The downside variance.
Type Parameters
TStat
Exceptions
- NanoQLException
There are fewer than two negative samples.
ExpectedShortfall<TStat>(TStat, double)
The expected shortfall at a percentile: the expected loss where the loss exceeds the value-at-risk, E[x | x < VaR(p)], the average of observations below the percentile, also known as conditional value-at-risk (Artzner, Delbaen, Eber and Heath, "Coherent measures of risk", Mathematical Finance 9, 1999); capped at 0 and negated.
public static double ExpectedShortfall<TStat>(this TStat stats, double percentile) where TStat : notnull, IEmpiricalStatistics
Parameters
statsTStatpercentiledoubleThe percentile, in [0.9, 1).
Returns
- double
The expected shortfall; where no sample lies below the value-at-risk's level, that level capped and negated: 0 with no loss, the value-at-risk where the tail is an atom at that level (a divergence: QuantLib refuses).
Type Parameters
TStat
Exceptions
- ArgumentOutOfRangeException
percentileis outside [0.9, 1).- NanoQLException
There's no sample.
PotentialUpside<TStat>(TStat, double)
The potential upside (the reciprocal of value-at-risk) at a percentile, floored at 0.
public static double PotentialUpside<TStat>(this TStat stats, double percentile) where TStat : notnull, IEmpiricalStatistics
Parameters
statsTStatpercentiledoubleThe percentile, in [0.9, 1).
Returns
- double
The potential upside.
Type Parameters
TStat
Exceptions
- ArgumentOutOfRangeException
percentileis outside [0.9, 1).
Regret<TStat>(TStat, double)
The variance of observations below a target, N/(N − 1) E[(x − t)² | x < t] (Dembo and Freeman, "The Rules Of Risk", Wiley, 2001).
public static double Regret<TStat>(this TStat stats, double target) where TStat : notnull, IEmpiricalStatistics
Parameters
statsTStattargetdoubleThe target.
Returns
- double
The regret.
Type Parameters
TStat
Exceptions
- NanoQLException
There are fewer than two samples below the target.
SemiDeviation<TStat>(TStat)
The semi-deviation, the square root of the semi-variance.
public static double SemiDeviation<TStat>(this TStat stats) where TStat : notnull, IEmpiricalStatistics
Parameters
statsTStat
Returns
- double
The semi-deviation.
Type Parameters
TStat
Exceptions
- NanoQLException
There are fewer than two samples below the mean.
SemiVariance<TStat>(TStat)
The variance of observations below the mean, N/(N − 1) E[(x − ⟨x⟩)² | x < ⟨x⟩] (Markowitz, 1959).
public static double SemiVariance<TStat>(this TStat stats) where TStat : notnull, IEmpiricalStatistics
Parameters
statsTStat
Returns
- double
The semi-variance.
Type Parameters
TStat
Exceptions
- NanoQLException
There are fewer than two samples below the mean.
Shortfall<TStat>(TStat, double)
The probability of missing a target, E[Θ | (−∞, ∞)], where Θ(x) is 1 for x < t and 0 for x ≥ t.
public static double Shortfall<TStat>(this TStat stats, double target) where TStat : notnull, IEmpiricalStatistics
Parameters
statsTStattargetdoubleThe target.
Returns
- double
The shortfall.
Type Parameters
TStat
Exceptions
- NanoQLException
There's no sample.
ValueAtRisk<TStat>(TStat, double)
The value-at-risk at a percentile: the (1 − percentile)-th percentile, capped at 0 and negated.
public static double ValueAtRisk<TStat>(this TStat stats, double percentile) where TStat : notnull, IEmpiricalStatistics
Parameters
statsTStatpercentiledoubleThe percentile, in [0.9, 1).
Returns
- double
The value-at-risk.
Type Parameters
TStat
Exceptions
- ArgumentOutOfRangeException
percentileis outside [0.9, 1).