21#include <ql/math/distributions/normaldistribution.hpp>
26 const Size ny,
const Real
sx,
const Size nx)
27 : model_(model), nx_(static_cast<int>(nx)) {
32 mx_ =
static_cast<int>(floor(
sx *
static_cast<Real
>(nx)) + 0.5);
33 my_ =
static_cast<int>(floor(
sy *
static_cast<Real
>(ny)) + 0.5);
36 h_ = 1.0 /
static_cast<Real
>(ny);
39 CumulativeNormalDistribution N;
42 y_.resize(2 *
my_ + 1);
43 w_.resize(2 *
my_ + 1);
44 for (
int i = 0; i <= 2 *
my_; i++) {
46 if (i == 0 || i == 2 *
my_)
54 QL_REQUIRE(
w_[i] > -1.0E-10,
"LgmConvolutionSolver: negative w (" <<
w_[i] <<
") at i=" << i);
61 if (QuantLib::close_enough(t, 0.0))
64 Real dx = std::sqrt(
model_->parametrization()->zeta(t)) /
static_cast<Real
>(
nx_);
65 for (
int k = 0; k <= 2 *
mx_; ++k) {
74 QL_REQUIRE(t0 < t1,
"LgmConvolutionSolver2::rollback(): t0 (" << t0 <<
") < t1 (" << t1 <<
") required.");
75 Real sigma = std::sqrt(
model_->parametrization()->zeta(t1));
76 Real dx = sigma /
static_cast<Real
>(
nx_);
77 if (QuantLib::close_enough(t0, 0.0)) {
80 for (
int i = 0; i <= 2 *
my_; i++) {
82 Real kp =
y_[i] * sigma / dx +
mx_;
84 int kk = int(floor(kp));
89 (kk < 0 ? v[0] : (kk + 1 > 2 *
mx_ ? v[2 *
mx_] : (kp - kk) * v[kk + 1] + (1.0 + kk - kp) * v[kk]));
96 Real std = std::sqrt(
model_->parametrization()->zeta(t1) -
model_->parametrization()->zeta(t0));
97 Real dx2 = std::sqrt(
model_->parametrization()->zeta(t0)) /
static_cast<Real
>(
nx_);
98 for (
int k = 0; k <= 2 *
mx_; k++) {
99 for (
int i = 0; i <= 2 *
my_; i++) {
101 Real kp = (dx2 * (k -
mx_) +
y_[i] * std) / dx +
mx_;
103 int kk = int(floor(kp));
106 value.
set(k, value[k] +
w_[i] * (kk < 0 ? v[0]
109 : (kp - kk) * v[kk + 1] + (1.0 + kk - kp) * v[kk])));
RandomVariable rollback(const RandomVariable &v, const Real t1, const Real t0, Size steps=Null< Size >()) const override
RandomVariable stateGrid(const Real t) const override
QuantLib::ext::shared_ptr< LinearGaussMarkovModel > model_
LgmConvolutionSolver2(const QuantLib::ext::shared_ptr< LinearGaussMarkovModel > &model, const Real sy, const Size ny, const Real sx, const Size nx)
numeric convolution solver for the LGM model using RandoMVariable
JY INF index sigma component.
bool deterministic() const
void set(const Size i, const Real v)