QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
frankcopularng.hpp
Go to the documentation of this file.
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
21/*! \file frankcopularng.hpp
22 \brief Frank copula random-number generator
23*/
24
25#ifndef quantlib_frank_copula_rng_hpp
26#define quantlib_frank_copula_rng_hpp
27
29#include <ql/errors.hpp>
30#include <vector>
31
32namespace QuantLib {
33
34 //! Frank copula random-number generator
35 template <class RNG>
37 public:
39 typedef RNG urng_type;
40 explicit FrankCopulaRng(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 != 0.0,
51 "theta (" << th << ") must be different from 0");
52 }
53
54 template <class RNG>
57 typename RNG::sample_type v1 = uniformGenerator_.next();
58 typename RNG::sample_type v2 = uniformGenerator_.next();
59 Real u1 = v1.value;
60 Real u2 = (-1.0/theta_)*std::log(1.0+(v2.value*(1.0-std::exp(-theta_)))/(v2.value*(std::exp(-theta_*v1.value)-1.0)-std::exp(-theta_*v1.value)));
61 std::vector<Real> u;
62 u.push_back(u1);
63 u.push_back(u2);
64 return sample_type(u,v1.weight*v2.weight);
65 }
66
67}
68
69
70#endif
Frank copula random-number generator.
sample_type next() const
FrankCopulaRng(const RNG &uniformGenerator, Real theta)
Sample< std::vector< Real > > sample_type
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
Real theta
Definition: any.hpp:35
weighted sample
weighted sample
Definition: sample.hpp:35