24#ifndef quantlib_risk_statistics_h
25#define quantlib_risk_statistics_h
131 return regret(this->mean());
136 return std::sqrt(semiVariance());
146 return std::sqrt(downsideVariance());
154 std::pair<Real, Size> result = this->expectationValue(
156 Real d = (xi - target);
159 [=](
Real xi) ->
bool {
return xi < target; });
160 Real x = result.first;
161 Size N = result.second;
163 "samples under target <= 1, unsufficient");
164 return (N/(N-1.0))*x;
172 "percentile (" << centile <<
") out of range [0.9, 1.0)");
175 return std::max<Real>(this->percentile(centile), 0.0);
183 "percentile (" << centile <<
") out of range [0.9, 1.0)");
186 return -std::min<Real>(this->percentile(1.0-centile), 0.0);
193 "percentile (" << centile <<
") out of range [0.9, 1.0)");
195 QL_ENSURE(this->samples() != 0,
"empty sample set");
196 Real target = -valueAtRisk(centile);
197 std::pair<Real,Size> result =
198 this->expectationValue([ ](
Real xi) {
return xi; },
199 [=](
Real xi) {
return xi < target; });
200 Real x = result.first;
201 Size N = result.second;
202 QL_ENSURE(N != 0,
"no data below the target");
204 return -std::min<Real>(x, 0.0);
209 QL_ENSURE(this->samples() != 0,
"empty sample set");
210 return this->expectationValue([=](
Real x) ->
Real {
return x < target ? 1.0 : 0.0; }).first;
216 std::pair<Real,Size> result = this->expectationValue(
217 [=](
Real xi) ->
Real {
return target - xi; },
218 [=](
Real xi) {
return xi < target; });
219 Real x = result.first;
220 Size N = result.second;
221 QL_ENSURE(N != 0,
"no data below the target");
empirical-distribution risk measures
Real semiDeviation() const
Real downsideVariance() const
Real valueAtRisk(Real percentile) const
value-at-risk at a given percentile
Real potentialUpside(Real percentile) const
potential upside (the reciprocal of VAR) at a given percentile
Real averageShortfall(Real target) const
Real downsideDeviation() const
Real expectedShortfall(Real percentile) const
expected shortfall at a given percentile
Real shortfall(Real target) const
Real regret(Real target) const
Real semiVariance() const
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
statistics tool for gaussian-assumption risk measures
std::size_t Size
size of a container
GenericRiskStatistics< GaussianStatistics > RiskStatistics
default risk measures tool