@@ -185,9 +185,8 @@ RandomVariable getRebatePv(const LgmVectorised& lgm, const Real t, const RandomV
185185}
186186
187187NumericLgmMultiLegOptionEngineBase::NumericLgmMultiLegOptionEngineBase (
188- const boost::shared_ptr<LinearGaussMarkovModel>& model, const Real sy, const Size ny, const Real sx, const Size nx,
189- const Handle<YieldTermStructure>& discountCurve)
190- : LgmConvolutionSolver2(model, sy, ny, sx, nx), discountCurve_(discountCurve) {}
188+ const boost::shared_ptr<LgmBackwardSolver>& solver, const Handle<YieldTermStructure>& discountCurve)
189+ : solver_(solver), discountCurve_(discountCurve) {}
191190
192191void NumericLgmMultiLegOptionEngineBase::calculate () const {
193192
@@ -198,7 +197,7 @@ void NumericLgmMultiLegOptionEngineBase::calculate() const {
198197 TODO we should add exercise data to indicate past exercises and value outstanding cash settlement amounts,
199198 or - possibly (?) - the physical underlying in that we exercised into? Or would that be a separate trade? */
200199
201- Date refDate = model ()->parametrization ()->termStructure ()->referenceDate ();
200+ Date refDate = solver_-> model ()->parametrization ()->termStructure ()->referenceDate ();
202201
203202 /* we might have to handle an exercise with rebate, init a variable for that (null if not applicable) */
204203
@@ -279,23 +278,23 @@ void NumericLgmMultiLegOptionEngineBase::calculate() const {
279278
280279 /* Step backwards through simulation dates and compute the option npv */
281280
282- LgmVectorised lgm (model ()->parametrization ());
281+ LgmVectorised lgm (solver_-> model ()->parametrization ());
283282
284283 // the current option npv that we roll back through the grid
285- RandomVariable optionNpv (gridSize (), 0.0 );
284+ RandomVariable optionNpv (solver_-> gridSize (), 0.0 );
286285 // cashflow npvs that are part of the latest exercise into option
287- RandomVariable underlyingNpv1 (gridSize (), 0.0 );
286+ RandomVariable underlyingNpv1 (solver_-> gridSize (), 0.0 );
288287 // cashflow npvs that are estimated, but not yet part of the latest exercise into option
289288 std::map<std::pair<Size, Size>, RandomVariable> underlyingNpv2;
290289
291290 for (auto it = simulationDates.rbegin (); it != simulationDates.rend (); ++it) {
292291
293- Real t_from = model ()->parametrization ()->termStructure ()->timeFromReference (*it);
292+ Real t_from = solver_-> model ()->parametrization ()->termStructure ()->timeFromReference (*it);
294293 Real t_to = (it != std::next (simulationDates.rend (), -1 ))
295- ? model ()->parametrization ()->termStructure ()->timeFromReference (*std::next (it, 1 ))
294+ ? solver_-> model ()->parametrization ()->termStructure ()->timeFromReference (*std::next (it, 1 ))
296295 : t_from;
297296
298- RandomVariable state = stateGrid (t_from);
297+ RandomVariable state = solver_-> stateGrid (t_from);
299298
300299 auto option = optionDates.find (*it);
301300 auto cashflow = cashflowDates.find (*it);
@@ -305,7 +304,7 @@ void NumericLgmMultiLegOptionEngineBase::calculate() const {
305304 if (cashflow != cashflowDates.end ()) {
306305 for (auto const & cf : cashflow->second ) {
307306 auto tmp = getUnderlyingCashflowPv (lgm, t_from, state, discountCurve_, legs_[cf.first ][cf.second ]) *
308- RandomVariable (gridSize (), payer_[cf.first ]);
307+ RandomVariable (solver_-> gridSize (), payer_[cf.first ]);
309308 auto it = underlyingNpv2.find (cf);
310309 if (it != underlyingNpv2.end ())
311310 it->second += tmp;
@@ -334,11 +333,11 @@ void NumericLgmMultiLegOptionEngineBase::calculate() const {
334333 // rollback
335334
336335 if (t_from != t_to) {
337- underlyingNpv1 = rollback (underlyingNpv1, t_from, t_to);
336+ underlyingNpv1 = solver_-> rollback (underlyingNpv1, t_from, t_to);
338337 for (auto & c : underlyingNpv2) {
339- c.second = rollback (c.second , t_from, t_to);
338+ c.second = solver_-> rollback (c.second , t_from, t_to);
340339 }
341- optionNpv = rollback (optionNpv, t_from, t_to);
340+ optionNpv = solver_-> rollback (optionNpv, t_from, t_to);
342341 }
343342 }
344343
@@ -350,7 +349,7 @@ void NumericLgmMultiLegOptionEngineBase::calculate() const {
350349 underlyingNpv_ += c.second .at (0 );
351350 }
352351
353- additionalResults_ = getAdditionalResultsMap (model ()->getCalibrationInfo ());
352+ additionalResults_ = getAdditionalResultsMap (solver_-> model ()->getCalibrationInfo ());
354353
355354 if (rebatedExercise) {
356355 for (Size i = 0 ; i < rebatedExercise->dates ().size (); ++i) {
@@ -366,8 +365,9 @@ NumericLgmMultiLegOptionEngine::NumericLgmMultiLegOptionEngine(const boost::shar
366365 const Real sy, const Size ny, const Real sx,
367366 const Size nx,
368367 const Handle<YieldTermStructure>& discountCurve)
369- : NumericLgmMultiLegOptionEngineBase(model, sy, ny, sx, nx, discountCurve) {
370- registerWith (LgmConvolutionSolver2::model ());
368+ : NumericLgmMultiLegOptionEngineBase(boost::make_shared<LgmConvolutionSolver2>(model, sy, ny, sx, nx),
369+ discountCurve) {
370+ registerWith (solver_->model ());
371371 registerWith (discountCurve_);
372372}
373373
@@ -390,8 +390,9 @@ void NumericLgmMultiLegOptionEngine::calculate() const {
390390NumericLgmSwaptionEngine::NumericLgmSwaptionEngine (const boost::shared_ptr<LinearGaussMarkovModel>& model,
391391 const Real sy, const Size ny, const Real sx, const Size nx,
392392 const Handle<YieldTermStructure>& discountCurve)
393- : NumericLgmMultiLegOptionEngineBase(model, sy, ny, sx, nx, discountCurve) {
394- registerWith (LgmConvolutionSolver2::model ());
393+ : NumericLgmMultiLegOptionEngineBase(boost::make_shared<LgmConvolutionSolver2>(model, sy, ny, sx, nx),
394+ discountCurve) {
395+ registerWith (solver_->model ());
395396 registerWith (discountCurve_);
396397}
397398
@@ -413,8 +414,9 @@ void NumericLgmSwaptionEngine::calculate() const {
413414NumericLgmNonstandardSwaptionEngine::NumericLgmNonstandardSwaptionEngine (
414415 const boost::shared_ptr<LinearGaussMarkovModel>& model, const Real sy, const Size ny, const Real sx, const Size nx,
415416 const Handle<YieldTermStructure>& discountCurve)
416- : NumericLgmMultiLegOptionEngineBase(model, sy, ny, sx, nx, discountCurve) {
417- registerWith (LgmConvolutionSolver2::model ());
417+ : NumericLgmMultiLegOptionEngineBase(boost::make_shared<LgmConvolutionSolver2>(model, sy, ny, sx, nx),
418+ discountCurve) {
419+ registerWith (solver_->model ());
418420 registerWith (discountCurve_);
419421}
420422
0 commit comments