QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
gaussianorthogonalpolynomial.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2005 Klaus Spanderen
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
24#include <ql/math/integrals/gaussianorthogonalpolynomial.hpp>
25#include <ql/math/distributions/gammadistribution.hpp>
26#include <ql/math/comparison.hpp>
27#include <ql/errors.hpp>
28#include <cmath>
29
30namespace QuantLib {
31
33 if (n > 1) {
34 return (x-alpha(n-1)) * value(n-1, x)
35 - beta(n-1) * value(n-2, x);
36 }
37 else if (n == 1) {
38 return x-alpha(0);
39 }
40
41 return 1;
42 }
43
45 return std::sqrt(w(x))*value(n, x);
46 }
47
48
50 : s_(s) {
51 QL_REQUIRE(s > -1.0, "s must be bigger than -1");
52 }
53
55 return std::exp(GammaFunction().logValue(s_+1));
56 }
57
59 return 2*i+1+s_;
60 }
61
63 return i*(i+s_);
64 }
65
67 return std::pow(x, s_)*std::exp(-x);
68 }
69
70
72 : mu_(mu) {
73 QL_REQUIRE(mu > -0.5, "mu must be bigger than -0.5");
74 }
75
77 return std::exp(GammaFunction().logValue(mu_+0.5));
78 }
79
81 return 0.0;
82 }
83
85 return (i % 2) != 0U ? Real(i / 2.0 + mu_) : Real(i / 2.0);
86 }
87
89 return std::pow(std::fabs(x), 2*mu_)*std::exp(-x*x);
90 }
91
93 : alpha_(alpha), beta_ (beta) {
94 QL_REQUIRE(alpha_+beta_ > -2.0,"alpha+beta must be bigger than -2");
95 QL_REQUIRE(alpha_ > -1.0,"alpha must be bigger than -1");
96 QL_REQUIRE(beta_ > -1.0,"beta must be bigger than -1");
97 }
98
100 return std::pow(2.0, alpha_+beta_+1)
101 * std::exp( GammaFunction().logValue(alpha_+1)
102 +GammaFunction().logValue(beta_ +1)
103 -GammaFunction().logValue(alpha_+beta_+2));
104 }
105
107 Real num = beta_*beta_ - alpha_*alpha_;
108 Real denom = (2.0*i+alpha_+beta_)*(2.0*i+alpha_+beta_+2);
109
110 if (close_enough(denom,0.0)) {
111 if (!close_enough(num,0.0)) {
112 QL_FAIL("can't compute a_k for jacobi integration\n");
113 }
114 else {
115 // l'Hospital
116 num = 2*beta_;
117 denom= 2*(2.0*i+alpha_+beta_+1);
118
119 QL_ASSERT(!close_enough(denom,0.0), "can't compute a_k for jacobi integration\n");
120 }
121 }
122
123 return num / denom;
124 }
125
127 Real num = 4.0*i*(i+alpha_)*(i+beta_)*(i+alpha_+beta_);
128 Real denom = (2.0*i+alpha_+beta_)*(2.0*i+alpha_+beta_)
129 * ((2.0*i+alpha_+beta_)*(2.0*i+alpha_+beta_)-1);
130
131 if (close_enough(denom,0.0)) {
132 if (!close_enough(num,0.0)) {
133 QL_FAIL("can't compute b_k for jacobi integration\n");
134 } else {
135 // l'Hospital
136 num = 4.0*i*(i+beta_)* (2.0*i+2*alpha_+beta_);
137 denom= 2.0*(2.0*i+alpha_+beta_);
138 denom*=denom-1;
139 QL_ASSERT(!close_enough(denom,0.0), "can't compute b_k for jacobi integration\n");
140 }
141 }
142 return num / denom;
143 }
144
146 return std::pow(1-x, alpha_)*std::pow(1+x, beta_);
147 }
148
149
151 : GaussJacobiPolynomial(0.0, 0.0) {
152 }
153
155 : GaussJacobiPolynomial(0.5, 0.5) {
156 }
157
159 : GaussJacobiPolynomial(-0.5, -0.5) {
160 }
161
163 : GaussJacobiPolynomial(lambda-0.5, lambda-0.5){
164 }
165
167 return M_PI;
168 }
169
171 return 0.0;
172 }
173
175 return i != 0U ? M_PI_2 * M_PI_2 * i * i : M_PI;
176 }
177
179 return 1/std::cosh(x);
180 }
181
182}
183
Gamma function class.
virtual Real alpha(Size i) const =0
virtual Real beta(Size i) const =0
virtual Real w(Real x) const =0
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
bool close_enough(const Quantity &m1, const Quantity &m2, Size n)
Definition: quantity.cpp:182