Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
numericlgmmultilegoptionengine.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#pragma once
20
24
25#include <ql/instruments/nonstandardswaption.hpp>
26#include <ql/instruments/swaption.hpp>
27#include <ql/methods/finitedifferences/solvers/fdmbackwardsolver.hpp>
28#include <ql/pricingengines/genericmodelengine.hpp>
29
30namespace QuantExt {
31
33public:
34 NumericLgmMultiLegOptionEngineBase(const QuantLib::ext::shared_ptr<LgmBackwardSolver>& solver,
35 const Handle<YieldTermStructure>& discountCurve = Handle<YieldTermStructure>(),
36 const Size americanExerciseTimeStepsPerYear = 24);
37
38 static bool instrumentIsHandled(const MultiLegOption& m, std::vector<std::string>& messages);
39
40protected:
41 static bool instrumentIsHandled(const std::vector<Leg>& legs, const std::vector<bool>& payer,
42 const std::vector<Currency>& currency, const QuantLib::ext::shared_ptr<Exercise>& exercise,
43 const Settlement::Type& settlementType, const Settlement::Method& settlementMethod,
44 std::vector<std::string>& messages);
45
46 struct CashflowInfo {
47 bool isPartOfUnderlying(const Real optionTime) const;
48 bool canBeEstimated(const Real optionTime) const;
49 bool mustBeEstimated(const Real optionTime) const;
50 Real requiredSimulationTime() const;
51 Real couponRatio(const Real time) const;
52 RandomVariable pv(const LgmVectorised& lgm, const Real t, const RandomVariable& state,
53 const Handle<YieldTermStructure>& discountCurve) const;
54 Real couponStartTime_ = Null<Real>(); // filled for classes derived from Coupon
55 Real couponEndTime_ = Null<Real>(); // filled for classes derived from Coupon
56 Real belongsToUnderlyingMaxTime_ = Null<Real>(); // this is always filled
57 Real maxEstimationTime_ = Null<Real>(); // either this or exactEstimationTime is filled
58 Real exactEstimationTime_ = Null<Real>(); // ...
59 std::function<RandomVariable(const LgmVectorised&, const Real, const RandomVariable&,
60 const Handle<YieldTermStructure>&)>
61 calculator_; // always a valid function
62 };
63
64 CashflowInfo buildCashflowInfo(const Size i, const Size j) const;
65
66 void calculate() const;
67
68 // inputs set in ctor
69 QuantLib::ext::shared_ptr<LgmBackwardSolver> solver_;
70 Handle<YieldTermStructure> discountCurve_;
72
73 // inputs set by derived classes
74 mutable std::vector<Leg> legs_;
75 mutable std::vector<bool> payer_;
76 mutable std::vector<Currency> currency_;
77 mutable QuantLib::ext::shared_ptr<Exercise> exercise_;
78 mutable Settlement::Type settlementType_;
79 mutable Settlement::Method settlementMethod_;
80
81 // outputs
82 mutable Real npv_, underlyingNpv_;
83 mutable std::map<std::string, boost::any> additionalResults_;
84};
85
87 : public QuantLib::GenericEngine<MultiLegOption::arguments, MultiLegOption::results>,
89public:
90 NumericLgmMultiLegOptionEngine(const QuantLib::ext::shared_ptr<LinearGaussMarkovModel>& model, const Real sy, const Size ny,
91 const Real sx, const Size nx,
92 const Handle<YieldTermStructure>& discountCurve = Handle<YieldTermStructure>(),
93 const Size americanExerciseTimeStepsPerYear = 24);
94
95 NumericLgmMultiLegOptionEngine(const QuantLib::ext::shared_ptr<LinearGaussMarkovModel>& model, const Real maxTime = 50.0,
96 const QuantLib::FdmSchemeDesc scheme = QuantLib::FdmSchemeDesc::Douglas(),
97 const Size stateGridPoints = 64, const Size timeStepsPerYear = 24,
98 const Real mesherEpsilon = 1E-4,
99 const Handle<YieldTermStructure>& discountCurve = Handle<YieldTermStructure>(),
100 const Size americanExerciseTimeStepsPerYear = 24);
101
102 void calculate() const override;
103};
104
105class NumericLgmSwaptionEngine : public QuantLib::GenericEngine<Swaption::arguments, Swaption::results>,
107public:
108 NumericLgmSwaptionEngine(const QuantLib::ext::shared_ptr<LinearGaussMarkovModel>& model, const Real sy, const Size ny,
109 const Real sx, const Size nx,
110 const Handle<YieldTermStructure>& discountCurve = Handle<YieldTermStructure>(),
111 const Size americanExerciseTimeStepsPerYear = 24);
112
113 NumericLgmSwaptionEngine(const QuantLib::ext::shared_ptr<LinearGaussMarkovModel>& model, const Real maxTime = 50.0,
114 const QuantLib::FdmSchemeDesc scheme = QuantLib::FdmSchemeDesc::Douglas(),
115 const Size stateGridPoints = 64, const Size timeStepsPerYear = 24,
116 const Real mesherEpsilon = 1E-4,
117 const Handle<YieldTermStructure>& discountCurve = Handle<YieldTermStructure>(),
118 const Size americanExerciseTimeStepsPerYear = 24);
119
120 void calculate() const override;
121};
122
124 : public QuantLib::GenericEngine<NonstandardSwaption::arguments, NonstandardSwaption::results>,
126public:
127 NumericLgmNonstandardSwaptionEngine(const QuantLib::ext::shared_ptr<LinearGaussMarkovModel>& model, const Real sy,
128 const Size ny, const Real sx, const Size nx,
129 const Handle<YieldTermStructure>& discountCurve = Handle<YieldTermStructure>(),
130 const Size americanExerciseTimeStepsPerYear = 24);
131
132 NumericLgmNonstandardSwaptionEngine(const QuantLib::ext::shared_ptr<LinearGaussMarkovModel>& model,
133 const Real maxTime = 50.0,
134 const QuantLib::FdmSchemeDesc scheme = QuantLib::FdmSchemeDesc::Douglas(),
135 const Size stateGridPoints = 64, const Size timeStepsPerYear = 24,
136 const Real mesherEpsilon = 1E-4,
137 const Handle<YieldTermStructure>& discountCurve = Handle<YieldTermStructure>(),
138 const Size americanExerciseTimeStepsPerYear = 24);
139
140 void calculate() const override;
141};
142
143} // namespace QuantExt
QuantLib::ext::shared_ptr< LgmBackwardSolver > solver_
CashflowInfo buildCashflowInfo(const Size i, const Size j) const
static bool instrumentIsHandled(const MultiLegOption &m, std::vector< std::string > &messages)
interface for LGM1F backward solver
vectorised lgm model calculations
multi leg option instrument
JY INF index sigma component.
std::function< RandomVariable(const LgmVectorised &, const Real, const RandomVariable &, const Handle< YieldTermStructure > &)> calculator_
RandomVariable pv(const LgmVectorised &lgm, const Real t, const RandomVariable &state, const Handle< YieldTermStructure > &discountCurve) const