24#ifndef quantext_lgm_model_hpp
25#define quantext_lgm_model_hpp
32#include <ql/math/comparison.hpp>
33#include <ql/math/distributions/normaldistribution.hpp>
34#include <ql/math/integrals/integral.hpp>
35#include <ql/math/integrals/simpsonintegral.hpp>
36#include <ql/stochasticprocess.hpp>
52 const bool evaluateBankAccount =
true,
53 const QuantLib::ext::shared_ptr<Integrator>& integrator = QuantLib::ext::make_shared<SimpsonIntegral>(1.0E-8,
61 Size
n()
const override;
62 Size
m()
const override;
63 Size
n_aux()
const override;
64 Size
m_aux()
const override;
65 QuantLib::ext::shared_ptr<StochasticProcess>
stateProcess()
const override;
67 QuantLib::Real
discountBond(
const QuantLib::Time t,
const QuantLib::Time T,
const QuantLib::Array& x,
68 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve =
69 Handle<YieldTermStructure>())
const override;
72 numeraire(
const QuantLib::Time t,
const QuantLib::Array& x,
73 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve = Handle<YieldTermStructure>(),
74 const QuantLib::Array& aux = Array())
const override;
76 QuantLib::Real
shortRate(
const QuantLib::Time t,
const QuantLib::Array& x,
77 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve =
78 Handle<YieldTermStructure>())
const override;
82 const QuantLib::ext::shared_ptr<IrLgm1fParametrization>
parametrization()
const;
84 Real
numeraire(
const Time t,
const Real x,
85 const Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>())
const;
90 const Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>())
const;
92 Real
discountBond(
const Time t,
const Time T,
const Real x,
93 Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>())
const;
96 const Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>())
const;
98 Real
discountBondOption(Option::Type type,
const Real K,
const Time t,
const Time S,
const Time T,
99 Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>())
const;
106 const std::vector<Real>& weights = std::vector<Real>());
113 const std::vector<Real>& weights = std::vector<Real>());
116 void calibrateVolatilities(
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
119 const std::vector<Real>& weights = std::vector<Real>());
122 void calibrateReversions(
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
125 const std::vector<Real>& weights = std::vector<Real>());
134 QL_REQUIRE(i < parametrization_->parameter(0)->size(),
135 "volatility index (" << i <<
") out of range 0..." <<
parametrization_->parameter(0)->size() - 1);
142 QL_REQUIRE(i < parametrization_->parameter(1)->size(),
143 "reversion index (" << i <<
") out of range 0..." <<
parametrization_->parameter(1)->size() - 1);
176 QL_REQUIRE(
measure_ ==
Measure::LGM,
"LinearGaussMarkovModel::stateProcess() only supports measure = LGM");
182 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve)
const {
183 QL_REQUIRE(x.size() ==
n(),
"LinearGaussMarkovModel::discountBond() requires input state of dimension " <<
n());
189 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve,
190 const QuantLib::Array& aux)
const {
191 QL_REQUIRE(x.size() ==
n(),
"LinearGaussMarkovModel::numeraire() requires input state of dimension " <<
n());
192 QL_REQUIRE(aux.size() ==
n_aux(),
193 "LinearGaussMarkovModel::numeraire() requires aux input state of dimension " <<
n_aux());
195 return numeraire(t, x[0], discountCurve);
206 const Handle<YieldTermStructure> discountCurve)
const {
207 QL_REQUIRE(t >= 0.0,
"t (" << t <<
") >= 0 required in LGM::numeraire");
210 (discountCurve.empty() ?
parametrization_->termStructure()->discount(t) : discountCurve->discount(t));
214 const Handle<YieldTermStructure> discountCurve)
const {
215 if (QuantLib::close_enough(t, T))
217 QL_REQUIRE(T >= t && t >= 0.0,
"T(" << T <<
") >= t(" << t <<
") >= 0 required in LGM::discountBond");
220 return (discountCurve.empty()
222 : discountCurve->discount(T) / discountCurve->discount(t)) *
223 std::exp(-(HT - Ht) * x - 0.5 * (HT * HT - Ht * Ht) *
parametrization_->zeta(t));
228 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve)
const {
229 QL_FAIL(
"LGM does not provide short rate.");
233 const Handle<YieldTermStructure> discountCurve)
const {
234 if (QuantLib::close_enough(t, T))
235 return 1.0 /
numeraire(t, x, discountCurve);
236 QL_REQUIRE(T >= t && t >= 0.0,
"T(" << T <<
") >= t(" << t <<
") >= 0 required in LGM::reducedDiscountBond");
238 return (discountCurve.empty() ?
parametrization_->termStructure()->discount(T) : discountCurve->discount(T)) *
244 const Handle<YieldTermStructure> discountCurve)
const {
245 QL_REQUIRE(T > S && S >= t && t >= 0.0,
246 "T(" << T <<
") > S(" << S <<
") >= t(" << t <<
") >= 0 required in LGM::discountBondOption");
247 Real w = (type == Option::Call ? 1.0 : -1.0);
248 Real pS = discountCurve.empty() ?
parametrization_->termStructure()->discount(S) : discountCurve->discount(S);
249 Real pT = discountCurve.empty() ?
parametrization_->termStructure()->discount(T) : discountCurve->discount(T);
253 Real dp = std::log(pT / (K * pS)) / sigma + 0.5 * sigma * sigma;
254 Real dm = dp - sigma;
255 CumulativeNormalDistribution N;
256 return w * (pT * N(w * dp) - pS * K * N(w * dm));
260 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
OptimizationMethod& method,
261 const EndCriteria& endCriteria,
const Constraint& constraint,
const std::vector<Real>& weights) {
262 for (Size i = 0; i < helpers.size(); ++i) {
263 std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> h(1, helpers[i]);
270 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
OptimizationMethod& method,
271 const EndCriteria& endCriteria,
const Constraint& constraint,
const std::vector<Real>& weights) {
272 for (Size i = 0; i < helpers.size(); ++i) {
273 std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> h(1, helpers[i]);
282 const Constraint& constraint,
const std::vector<Real>& weights) {
293 const Constraint& constraint,
const std::vector<Real>& weights) {
Linear Gauss Morkov Model.
void calibrateVolatilities(const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
const QuantLib::ext::shared_ptr< Parametrization > parametrizationBase() const override
QuantLib::ext::shared_ptr< StochasticProcess > stateProcess() const override
Size n_aux() const override
bool evaluateBankAccount_
LgmCalibrationInfo calibrationInfo_
const QuantLib::ext::shared_ptr< IrLgm1fParametrization > parametrization() const
LGM specific methods.
Measure measure() const override
IrModel interface.
QuantLib::Real discountBond(const QuantLib::Time t, const QuantLib::Time T, const QuantLib::Array &x, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve=Handle< YieldTermStructure >()) const override
void generateArguments() override
QuantLib::ext::shared_ptr< IrLgm1fParametrization > parametrization_
void setCalibrationInfo(const LgmCalibrationInfo &calibrationInfo)
Handle< YieldTermStructure > termStructure() const override
QuantLib::Real shortRate(const QuantLib::Time t, const QuantLib::Array &x, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve=Handle< YieldTermStructure >()) const override
QuantLib::ext::shared_ptr< StochasticProcess1D > stateProcess_
const LgmCalibrationInfo & getCalibrationInfo() const
std::vector< bool > MoveReversion(const Size i)
Discretization discretization_
Real reducedDiscountBond(const Time t, const Time T, const Real x, const Handle< YieldTermStructure > discountCurve=Handle< YieldTermStructure >()) const
Size m_aux() const override
QuantLib::ext::shared_ptr< Integrator > integrator_
void calibrateVolatilitiesIterative(const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
std::vector< bool > MoveVolatility(const Size i)
Real bankAccountNumeraire(const Time t, const Real x, const Real y, const Handle< YieldTermStructure > discountCurve=Handle< YieldTermStructure >()) const
void calibrateReversionsIterative(const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
QuantLib::Real numeraire(const QuantLib::Time t, const QuantLib::Array &x, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), const QuantLib::Array &aux=Array()) const override
Real discountBondOption(Option::Type type, const Real K, const Time t, const Time S, const Time T, Handle< YieldTermStructure > discountCurve=Handle< YieldTermStructure >()) const
void calibrateReversions(const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
const QuantLib::ext::shared_ptr< Constraint > & constraint() const
EndCriteria::Type endCriteria() const
Returns end criteria result.
virtual void calibrate(const std::vector< QuantLib::ext::shared_ptr< CalibrationHelper > > &, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >(), const std::vector< bool > &fixParameters=std::vector< bool >())
Calibrate to a set of market instruments (usually caps/swaptions)
Interest Rate Linear Gaussian Markov 1 factor parametrization.
info data on how a lgm model was calibrated
calibrated model class with linkable parameters
LinearGaussMarkovModel LGM