QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
inversecumulativersg.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003, 2004 Ferdinando Ametrano
5 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
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_inversecumulative_rsg_h
26#define quantlib_inversecumulative_rsg_h
27
28#include <ql/methods/montecarlo/sample.hpp>
29#include <utility>
30#include <vector>
31
32namespace QuantLib {
33
35
56 template <class USG, class IC>
58 public:
60 explicit InverseCumulativeRsg(USG uniformSequenceGenerator);
61 InverseCumulativeRsg(USG uniformSequenceGenerator, const IC& inverseCumulative);
63 const sample_type& nextSequence() const;
64 const sample_type& lastSequence() const { return x_; }
65 Size dimension() const { return dimension_; }
66 private:
69 mutable sample_type x_;
70 IC ICD_;
71 };
72
73 template <class USG, class IC>
75 : uniformSequenceGenerator_(std::move(usg)), dimension_(uniformSequenceGenerator_.dimension()),
76 x_(std::vector<Real>(dimension_), 1.0) {}
77
78 template <class USG, class IC>
80 : uniformSequenceGenerator_(std::move(usg)), dimension_(uniformSequenceGenerator_.dimension()),
81 x_(std::vector<Real>(dimension_), 1.0), ICD_(inverseCum) {}
82
83 template <class USG, class IC>
86 typename USG::sample_type sample =
87 uniformSequenceGenerator_.nextSequence();
88 x_.weight = sample.weight;
89 for (Size i = 0; i < dimension_; i++) {
90 x_.value[i] = ICD_(sample.value[i]);
91 }
92 return x_;
93 }
94
95}
96
97
98#endif
Inverse cumulative random sequence generator.
InverseCumulativeRsg(USG uniformSequenceGenerator, const IC &inverseCumulative)
InverseCumulativeRsg(USG uniformSequenceGenerator)
const sample_type & lastSequence() const
const sample_type & nextSequence() const
returns next sample from the inverse cumulative distribution
Sample< std::vector< Real > > sample_type
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.
weighted sample
Definition: sample.hpp:35