Skip to content

Commit f90c364

Browse files
pcaspersjenkins
authored andcommitted
QPR-11618 allow for optional number of steps
1 parent c781a0b commit f90c364

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

QuantExt/qle/models/lgmfdsolver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ RandomVariable LgmFdSolver::stateGrid() const { return mesherLocations_; }
4545

4646
const boost::shared_ptr<LinearGaussMarkovModel>& LgmFdSolver::model() const { return model_; }
4747

48-
RandomVariable LgmFdSolver::rollback(const RandomVariable& v, const Real t1, const Real t0) const {
49-
Size steps = std::max<Size>(1, static_cast<Size>(static_cast<double>(timeStepsPerYear_) * (t1 - t0) + 0.5));
48+
RandomVariable LgmFdSolver::rollback(const RandomVariable& v, const Real t1, const Real t0, const Size steps) const {
49+
if (steps == Null<Size>())
50+
steps = std::max<Size>(1, static_cast<Size>(static_cast<double>(timeStepsPerYear_) * (t1 - t0) + 0.5));
5051
Array workingArray(v.size());
5152
v.copyToArray(workingArray);
5253
solver_->rollback(workingArray, t1, t0, steps, 0);

QuantExt/qle/models/lgmfdsolver.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace QuantExt {
3535
//! Numerical FD solver for the LGM model
3636
class LgmFdSolver {
3737
public:
38-
LgmFdSolver(const boost::shared_ptr<LinearGaussMarkovModel>& model, const Real maxTime,
38+
LgmFdSolver(const boost::shared_ptr<LinearGaussMarkovModel>& model, const Real maxTime = 50.0,
3939
const Size stateGridPoints = 64, const Size timeStepsPerYear = 24, const Real mesherEpsilon = 1E-4);
4040

4141
/* get grid size */
@@ -44,8 +44,10 @@ class LgmFdSolver {
4444
/* get discretised states grid */
4545
RandomVariable stateGrid() const;
4646

47-
/* roll back an deflated NPV array from t1 to t0 */
48-
RandomVariable rollback(const RandomVariable& v, const Real t1, const Real t0) const;
47+
/* roll back an deflated NPV array from t1 to t0 using the given number of steps or,
48+
if that is not given, the time steps per year specified in the constructor */
49+
RandomVariable rollback(const RandomVariable& v, const Real t1, const Real t0,
50+
const Size steps = Null<Size>()) const;
4951

5052
/* the underlying model */
5153
const boost::shared_ptr<LinearGaussMarkovModel>& model() const;

0 commit comments

Comments
 (0)