Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
RandomVariableLsmBasisSystem Class Reference

#include <qle/math/randomvariablelsmbasissystem.hpp>

+ Collaboration diagram for RandomVariableLsmBasisSystem:

Static Public Member Functions

static std::vector< std::function< RandomVariable(const RandomVariable &)> > pathBasisSystem (Size order, QuantLib::LsmBasisSystem::PolynomialType type)
 
static std::vector< std::function< RandomVariable(const std::vector< const RandomVariable * > &)> > multiPathBasisSystem (Size dim, Size order, QuantLib::LsmBasisSystem::PolynomialType type)
 
static Real size (Size dim, Size order)
 

Detailed Description

Definition at line 34 of file randomvariablelsmbasissystem.hpp.

Member Function Documentation

◆ pathBasisSystem()

VF_R pathBasisSystem ( Size  order,
QuantLib::LsmBasisSystem::PolynomialType  type 
)
static

Definition at line 141 of file randomvariablelsmbasissystem.cpp.

141 {
142 VF_R ret(order + 1);
143 for (Size i = 0; i <= order; ++i) {
144 switch (type) {
145 case QuantLib::LsmBasisSystem::Monomial:
146 ret[i] = MonomialFct(i);
147 break;
148 case QuantLib::LsmBasisSystem::Laguerre: {
149 GaussLaguerrePolynomial p;
150 ret[i] = [=](RandomVariable x) {
151 for (std::size_t i = 0; i < x.size(); ++i) {
152 x.set(i, p.weightedValue(i, x[i]));
153 }
154 return x;
155 };
156 } break;
157 case QuantLib::LsmBasisSystem::Hermite: {
158 GaussHermitePolynomial p;
159 ret[i] = [=](RandomVariable x) {
160 for (std::size_t i = 0; i < x.size(); ++i) {
161 x.set(i, p.weightedValue(i, x[i]));
162 }
163 return x;
164 };
165 } break;
166 case QuantLib::LsmBasisSystem::Hyperbolic: {
167 GaussHyperbolicPolynomial p;
168 ret[i] = [=](RandomVariable x) {
169 for (std::size_t i = 0; i < x.size(); ++i) {
170 x.set(i, p.weightedValue(i, x[i]));
171 }
172 return x;
173 };
174 } break;
175 case QuantLib::LsmBasisSystem::Legendre: {
176 GaussLegendrePolynomial p;
177 ret[i] = [=](RandomVariable x) {
178 for (std::size_t i = 0; i < x.size(); ++i) {
179 x.set(i, p.weightedValue(i, x[i]));
180 }
181 return x;
182 };
183 } break;
184 case QuantLib::LsmBasisSystem::Chebyshev: {
185 GaussChebyshevPolynomial p;
186 ret[i] = [=](RandomVariable x) {
187 for (std::size_t i = 0; i < x.size(); ++i) {
188 x.set(i, p.weightedValue(i, x[i]));
189 }
190 return x;
191 };
192 } break;
193 case QuantLib::LsmBasisSystem::Chebyshev2nd: {
194 GaussChebyshev2ndPolynomial p;
195 ret[i] = [=](RandomVariable x) {
196 for (std::size_t i = 0; i < x.size(); ++i) {
197 x.set(i, p.weightedValue(i, x[i]));
198 }
199 return x;
200 };
201 } break;
202 default:
203 QL_FAIL("unknown regression type");
204 }
205 }
206 return ret;
207}
+ Here is the caller graph for this function:

◆ multiPathBasisSystem()

VF_A multiPathBasisSystem ( Size  dim,
Size  order,
QuantLib::LsmBasisSystem::PolynomialType  type 
)
static

Definition at line 209 of file randomvariablelsmbasissystem.cpp.

210 {
211 QL_REQUIRE(dim > 0, "zero dimension");
212 // get single factor basis
213 VF_R pathBasis = pathBasisSystem(order, type);
214 VF_A ret;
215 // 0-th order term
216 VF_R term(dim, pathBasis[0]);
217 ret.push_back(MultiDimFct(term));
218 // start with all 0 tuple
219 VV tuples(1, std::vector<Size>(dim));
220 // add multi-factor terms
221 for (Size i = 1; i <= order; ++i) {
222 tuples = next_order_tuples(tuples);
223 // now we have all tuples of order i
224 // for each tuple add the corresponding term
225 for (Size j = 0; j < tuples.size(); ++j) {
226 for (Size k = 0; k < dim; ++k)
227 term[k] = pathBasis[tuples[j][k]];
228 ret.push_back(MultiDimFct(term));
229 }
230 }
231 return ret;
232}
static std::vector< std::function< RandomVariable(const RandomVariable &)> > pathBasisSystem(Size order, QuantLib::LsmBasisSystem::PolynomialType type)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

Real size ( Size  dim,
Size  order 
)
static

Definition at line 234 of file randomvariablelsmbasissystem.cpp.

234 {
235 // see e.g. proposition 3 in https://murphmath.wordpress.com/2012/08/22/counting-monomials/
236 return boost::math::binomial_coefficient<Real>(
237 dim + order, order,
238 boost::math::policies::make_policy(
239 boost::math::policies::overflow_error<boost::math::policies::ignore_error>()));
240}
+ Here is the caller graph for this function: