QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
claytoncopularng.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2010 Hachemi Benyahia
5 Copyright (C) 2010 DeriveXperts SAS
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
25#ifndef quantlib_clayton_copula_rng_hpp
26#define quantlib_clayton_copula_rng_hpp
27
28#include <ql/methods/montecarlo/sample.hpp>
29#include <ql/errors.hpp>
30#include <vector>
31
32namespace QuantLib {
33
35 template <class RNG>
37 public:
39 typedef RNG urng_type;
40 explicit ClaytonCopulaRng(const RNG& uniformGenerator,Real theta);
41 sample_type next() const;
42 private:
45 };
46
47 template <class RNG>
49 : uniformGenerator_(ug), theta_(th) {
50 QL_REQUIRE(th >= -1.0,
51 "theta (" << th << ") must be greater or equal to -1");
52 QL_REQUIRE(th != 0.0,
53 "theta (" << th << ") must be different from 0");
54 }
55
56 template <class RNG>
59 typename RNG::sample_type v1 = uniformGenerator_.next();
60 typename RNG::sample_type v2 = uniformGenerator_.next();
61 Real u1 = v1.value;
62 Real u2 = std::pow(std::pow(v1.value,-theta_)*(std::pow(v2.value,-theta_/(theta_+1.0))-1.0)+1.0,-1.0/theta_);
63 std::vector<Real> u;
64 u.push_back(u1);
65 u.push_back(u2);
66 return sample_type(u,v1.weight*v2.weight);
67 }
68
69}
70
71
72#endif
Clayton copula random-number generator.
ClaytonCopulaRng(const RNG &uniformGenerator, Real theta)
Sample< std::vector< Real > > sample_type
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
weighted sample
Definition: sample.hpp:35