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

Numerical FD solver for the LGM model. More...

#include <qle/models/lgmfdsolver.hpp>

+ Inheritance diagram for LgmFdSolver:
+ Collaboration diagram for LgmFdSolver:

Public Member Functions

 LgmFdSolver (const QuantLib::ext::shared_ptr< LinearGaussMarkovModel > &model, const Real maxTime=50.0, const QuantLib::FdmSchemeDesc scheme=QuantLib::FdmSchemeDesc::Douglas(), const Size stateGridPoints=64, const Size timeStepsPerYear=24, const Real mesherEpsilon=1E-4)
 
Size gridSize () const override
 
RandomVariable stateGrid (const Real t) const override
 
RandomVariable rollback (const RandomVariable &v, const Real t1, const Real t0, Size steps=Null< Size >()) const override
 
const QuantLib::ext::shared_ptr< LinearGaussMarkovModel > & model () const override
 
- Public Member Functions inherited from LgmBackwardSolver
virtual ~LgmBackwardSolver ()
 
virtual Size gridSize () const =0
 
virtual RandomVariable stateGrid (const Real t) const =0
 
virtual RandomVariable rollback (const RandomVariable &v, const Real t1, const Real t0, Size steps=Null< Size >()) const =0
 
virtual const QuantLib::ext::shared_ptr< LinearGaussMarkovModel > & model () const =0
 

Private Attributes

QuantLib::ext::shared_ptr< LinearGaussMarkovModelmodel_
 
Real maxTime_
 
QuantLib::FdmSchemeDesc scheme_
 
Size stateGridPoints_
 
Size timeStepsPerYear_
 
Real mesherEpsilon_
 
QuantLib::ext::shared_ptr< FdmMesher > mesher_
 
QuantLib::ext::shared_ptr< FdmLinearOpCompositeoperator_
 
QuantLib::ext::shared_ptr< FdmBackwardSolver > solver_
 
RandomVariable mesherLocations_
 

Detailed Description

Numerical FD solver for the LGM model.

Definition at line 36 of file lgmfdsolver.hpp.

Constructor & Destructor Documentation

◆ LgmFdSolver()

LgmFdSolver ( const QuantLib::ext::shared_ptr< LinearGaussMarkovModel > &  model,
const Real  maxTime = 50.0,
const QuantLib::FdmSchemeDesc  scheme = QuantLib::FdmSchemeDesc::Douglas(),
const Size  stateGridPoints = 64,
const Size  timeStepsPerYear = 24,
const Real  mesherEpsilon = 1E-4 
)

Definition at line 28 of file lgmfdsolver.cpp.

31 : model_(model), maxTime_(maxTime), scheme_(scheme), stateGridPoints_(stateGridPoints),
32 timeStepsPerYear_(timeStepsPerYear), mesherEpsilon_(mesherEpsilon) {
33 mesher_ = QuantLib::ext::make_shared<FdmMesherComposite>(QuantLib::ext::make_shared<FdmSimpleProcess1dMesher>(
34 stateGridPoints, QuantLib::ext::dynamic_pointer_cast<StochasticProcess1D>(model->stateProcess()), maxTime_,
36 mesherLocations_ = RandomVariable(mesher_->locations(0));
37 operator_ = QuantLib::ext::make_shared<QuantExt::FdmLgmOp>(
38 mesher_, QuantLib::ext::dynamic_pointer_cast<StochasticProcess1D>(model->stateProcess()));
39 solver_ = QuantLib::ext::make_shared<FdmBackwardSolver>(
40 operator_, std::vector<QuantLib::ext::shared_ptr<BoundaryCondition<FdmLinearOp>>>(), nullptr, scheme_);
41}
QuantLib::ext::shared_ptr< FdmLinearOpComposite > operator_
Definition: lgmfdsolver.hpp:57
const QuantLib::ext::shared_ptr< LinearGaussMarkovModel > & model() const override
Definition: lgmfdsolver.cpp:47
QuantLib::ext::shared_ptr< FdmBackwardSolver > solver_
Definition: lgmfdsolver.hpp:58
QuantLib::ext::shared_ptr< FdmMesher > mesher_
Definition: lgmfdsolver.hpp:56
QuantLib::FdmSchemeDesc scheme_
Definition: lgmfdsolver.hpp:51
QuantLib::ext::shared_ptr< LinearGaussMarkovModel > model_
Definition: lgmfdsolver.hpp:49
RandomVariable mesherLocations_
Definition: lgmfdsolver.hpp:60
+ Here is the call graph for this function:

Member Function Documentation

◆ gridSize()

Size gridSize ( ) const
overridevirtual

Implements LgmBackwardSolver.

Definition at line 43 of file lgmfdsolver.cpp.

43{ return stateGridPoints_; }
+ Here is the caller graph for this function:

◆ stateGrid()

RandomVariable stateGrid ( const Real  t) const
overridevirtual

Implements LgmBackwardSolver.

Definition at line 45 of file lgmfdsolver.cpp.

45{ return mesherLocations_; }

◆ rollback()

RandomVariable rollback ( const RandomVariable v,
const Real  t1,
const Real  t0,
Size  steps = Null<Size>() 
) const
overridevirtual

Implements LgmBackwardSolver.

Definition at line 49 of file lgmfdsolver.cpp.

49 {
50 if (QuantLib::close_enough(t0, t1) || v.deterministic())
51 return v;
52 QL_REQUIRE(t0 < t1, "LgmCFdSolver::rollback(): t0 (" << t0 << ") < t1 (" << t1 << ") required.");
53 if (steps == Null<Size>())
54 steps = std::max<Size>(1, static_cast<Size>(static_cast<double>(timeStepsPerYear_) * (t1 - t0) + 0.5));
55 Array workingArray(v.size());
56 v.copyToArray(workingArray);
57 solver_->rollback(workingArray, t1, t0, steps, 0);
58 if (QuantLib::close_enough(t0, 0.0)) {
59 Array x = mesher_->locations(0);
60 MonotonicCubicNaturalSpline interpolation(x.begin(), x.end(), workingArray.begin());
61 interpolation.enableExtrapolation();
62 return RandomVariable(gridSize(), interpolation(0.0));
63 } else {
64 return RandomVariable(workingArray);
65 }
66}
Size gridSize() const override
Definition: lgmfdsolver.cpp:43
std::vector< Size > steps
+ Here is the call graph for this function:

◆ model()

const QuantLib::ext::shared_ptr< LinearGaussMarkovModel > & model ( ) const
overridevirtual

Implements LgmBackwardSolver.

Definition at line 47 of file lgmfdsolver.cpp.

47{ return model_; }
+ Here is the caller graph for this function:

Member Data Documentation

◆ model_

QuantLib::ext::shared_ptr<LinearGaussMarkovModel> model_
private

Definition at line 49 of file lgmfdsolver.hpp.

◆ maxTime_

Real maxTime_
private

Definition at line 50 of file lgmfdsolver.hpp.

◆ scheme_

QuantLib::FdmSchemeDesc scheme_
private

Definition at line 51 of file lgmfdsolver.hpp.

◆ stateGridPoints_

Size stateGridPoints_
private

Definition at line 52 of file lgmfdsolver.hpp.

◆ timeStepsPerYear_

Size timeStepsPerYear_
private

Definition at line 53 of file lgmfdsolver.hpp.

◆ mesherEpsilon_

Real mesherEpsilon_
private

Definition at line 54 of file lgmfdsolver.hpp.

◆ mesher_

QuantLib::ext::shared_ptr<FdmMesher> mesher_
mutableprivate

Definition at line 56 of file lgmfdsolver.hpp.

◆ operator_

QuantLib::ext::shared_ptr<FdmLinearOpComposite> operator_
mutableprivate

Definition at line 57 of file lgmfdsolver.hpp.

◆ solver_

QuantLib::ext::shared_ptr<FdmBackwardSolver> solver_
mutableprivate

Definition at line 58 of file lgmfdsolver.hpp.

◆ mesherLocations_

RandomVariable mesherLocations_
private

Definition at line 60 of file lgmfdsolver.hpp.