36 typedef std::vector<ext::function<
Real(
Real)> > VF_R;
37 typedef std::vector<ext::function<
Real(Array)> > VF_A;
38 typedef std::vector<std::vector<Size> > VV;
43 explicit MonomialFct(
Size order):
order_(order) {}
44 inline Real operator()(
const Real x)
const {
58 explicit MultiDimFct(VF_R
b) :
b_(std::move(
b)) {
61 inline Real operator()(
const Array& a)
const {
62 #if defined(QL_EXTRA_SAFETY_CHECKS)
66 for(
Size i=1; i<
b_.size(); ++i)
75 void check_tuples(
const VV&
v,
Size dim,
Size order) {
76 for (
const auto& i :
v) {
77 QL_REQUIRE(dim == i.size(),
"wrong tuple size");
78 QL_REQUIRE(order == std::accumulate(i.begin(), i.end(), 0UL),
"wrong tuple order");
83 VV next_order_tuples(
const VV&
v) {
84 const Size order = std::accumulate(
v[0].begin(),
v[0].end(), 0UL);
85 const Size dim =
v[0].size();
87 check_tuples(
v, dim, order);
90 std::set<std::vector<Size> > tuples;
92 for(
Size i=0; i<dim; ++i) {
94 for (
const auto& j :
v) {
101 VV ret(tuples.begin(), tuples.end());
111 for (
Size i=0; i<=order; ++i) {
114 ret[i] = MonomialFct(i);
153 QL_FAIL(
"unknown regression type");
166 VF_R term(dim, pathBasis[0]);
167 ret.emplace_back(MultiDimFct(term));
169 VV tuples(1, std::vector<Size>(dim));
171 for(
Size i=1; i<=order; ++i) {
172 tuples = next_order_tuples(tuples);
175 for (
auto& tuple : tuples) {
176 for(
Size k=0; k<dim; ++k)
177 term[k] = pathBasis[tuple[k]];
178 ret.emplace_back(MultiDimFct(term));
Gauss-Chebyshev polynomial (second kind)
Gauss-Chebyshev polynomial.
Gauss-Hermite polynomial.
Gauss hyperbolic polynomial.
Gauss-Laguerre polynomial.
Gauss-Legendre polynomial.
Real weightedValue(Size i, Real x) const
static std::vector< ext::function< Real(Real)> > pathBasisSystem(Size order, PolynomialType type)
static std::vector< ext::function< Real(Array)> > multiPathBasisSystem(Size dim, Size order, PolynomialType type)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
ext::function< Real(Real)> b
Integral of a 1-dimensional function using the Gauss quadratures.
std::size_t Size
size of a container
utility classes for Longstaff-Schwartz early-exercise Monte Carlo
ext::shared_ptr< BlackVolTermStructure > v