Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
stoplightbounds.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Quaternion Risk Management Ltd.
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*!
20 \file qle/math/stoplightbounds.hpp
21 \brief compute stop light bounds for overlapping and correlated PL
22 */
23
24#pragma once
25
26#include <ql/math/matrix.hpp>
27#include <ql/math/matrixutilities/pseudosqrt.hpp>
28#include <ql/types.hpp>
29
30#include <vector>
31
32namespace QuantExt {
33using QuantLib::Matrix;
34using QuantLib::Null;
35using QuantLib::Real;
36using QuantLib::SalvagingAlgorithm;
37using QuantLib::Size;
38
39/*! Computes the maximum number of exceptions n such that the probability of having less or equal to
40 n exceptions is less than p for a given vector of stop light levels (0.95 = green, 0.9999 = red
41 in the Basel approach). An overlapping PL over a given period is considered, possibly also several
42 portfolios with correlated PL. If the parameter exceptions m is not null, cumProb is set to the
43 probability of having less of equal to m exceptions (this is not affecting the return value).
44*/
45std::vector<Size> stopLightBounds(const std::vector<Real>& stopLightP, const Size observations,
46 const Size numberOfDays = 10, const Real p = 0.99, const Size numberOfPortfolios = 1,
47 const Matrix& correlation = Matrix(1, 1, 1.0), const Size samples = 1500000,
48 const Size seed = 42,
49 const SalvagingAlgorithm::Type salvaging = SalvagingAlgorithm::Spectral,
50 const Size exceptions = Null<Size>(), Real* cumProb = nullptr);
51
52/* Uses pretabulated values, throws if no suitable values are tabulated (single portfolio case only) */
53std::vector<Size> stopLightBoundsTabulated(const std::vector<Real>& stopLightP, const Size observations,
54 const Size numberOfDays = 10, const Real p = 0.99);
55
56/* Same as above, but for non-overlapping and independent observations */
57std::vector<Size> stopLightBounds(const std::vector<Real>& stopLightP, const Size observations, const Real p,
58 const Size exceptions = Null<Size>(), Real* cumProb = nullptr);
59
60/* Generate table of stop light bounds (observations_k, (b_1,k, b_2,k, ..., b_n,k) for a given vector of threshold
61 probabilities {stopLightP[1], ..., stopLightP[n]} and a given vector of observations */
62std::vector<std::pair<Size, std::vector<Size>>>
63generateStopLightBoundTable(const std::vector<Size>& observations, const std::vector<Real>& stopLightP,
64 const Size samples, const Size seed, const Size numberOfDays = 10, const Real p = 0.99);
65
66} // namespace QuantExt
std::vector< Size > stopLightBoundsTabulated(const std::vector< Real > &stopLightP, const Size observations, const Size numberOfDays, const Real p)
std::vector< std::pair< Size, std::vector< Size > > > generateStopLightBoundTable(const std::vector< Size > &observations, const std::vector< Real > &stopLightP, const Size samples, const Size seed, const Size numberOfDays, const Real p)
std::vector< Size > stopLightBounds(const std::vector< Real > &stopLightP, const Size observations, const Size numberOfDays, const Real p, const Size numberOfPortfolios, const Matrix &correlation, const Size samples, const Size seed, const SalvagingAlgorithm::Type salvaging, const Size exceptions, Real *cumProb)