QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
gaussiancopulapolicy.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2014 Jose Aparicio
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#ifndef quantlib_gaussian_copula_policy_hpp
21#define quantlib_gaussian_copula_policy_hpp
22
23#include <ql/math/distributions/normaldistribution.hpp>
24#include <vector>
25#include <numeric>
26#include <algorithm>
27
28namespace QuantLib {
29
33 /* This is the only case that would have allowed the policy to be static,
34 but other copulas will need parameters and initialization.*/
36
37 typedef int initTraits;
38
40 const std::vector<std::vector<Real> >& factorWeights =
41 std::vector<std::vector<Real> >(),
42 const initTraits& dummy = int())
43 : numFactors_(factorWeights.size() + factorWeights[0].size())
44 {
45 /* check factors in LM are normalized. */
46 for (const auto& factorWeight : factorWeights) {
47 Real factorsNorm = std::inner_product(factorWeight.begin(), factorWeight.end(),
48 factorWeight.begin(), Real(0.));
49 QL_REQUIRE(factorsNorm < 1.,
50 "Non normal random factor combination.");
51 }
52 /* check factor matrix is squared .......... */
53 }
54
59 Size numFactors() const {
60 return numFactors_;
61 }
62
65 return initTraits();
66 }
67
71 Probability cumulativeY(Real val, Size iVariable) const {
72 return cumulative_(val);
73 }
76 return cumulative_(z);
77 }
85 Probability density(const std::vector<Real>& m) const {
86 return std::accumulate(m.begin(), m.end(), Real(1.),
87 [&](Real x, Real y) -> Real { return x*density_(y); });
88 }
95 }
101 }
107 }
109 //to use this (by default) version, the generator must be a uniform one.
110 std::vector<Real> allFactorCumulInverter(const std::vector<Real>& probs) const {
111 std::vector<Real> result;
112 result.resize(probs.size());
113 std::transform(probs.begin(), probs.end(), result.begin(),
114 [&](Real p){ return InverseCumulativeNormal::standard_value(p); });
115 return result;
116 }
117 private:
119 // no op =
122 };
123
124}
125
126#endif
Cumulative normal distribution function.
Normal distribution function.
QL_REAL Real
real number
Definition: types.hpp:50
Real Probability
probability
Definition: types.hpp:82
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
static const NormalDistribution density_
GaussianCopulaPolicy(const std::vector< std::vector< Real > > &factorWeights=std::vector< std::vector< Real > >(), const initTraits &dummy=int())
static const CumulativeNormalDistribution cumulative_
Real inverseCumulativeY(Probability p, Size iVariable) const
Real inverseCumulativeDensity(Probability p, Size iFactor) const
Probability density(const std::vector< Real > &m) const
initTraits getInitTraits() const
returns a copy of the initialization arguments
Probability cumulativeY(Real val, Size iVariable) const
std::vector< Real > allFactorCumulInverter(const std::vector< Real > &probs) const
Probability cumulativeZ(Real z) const
Cumulative probability of the idiosyncratic factors (all the same)
Real inverseCumulativeZ(Probability p) const