Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
irlgm1fpiecewiseconstanthullwhiteadaptor.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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/*! \file irlgm1fpiecewiseconstanthullwhiteadaptor.hpp
20 \brief adaptor to emulate piecewise constant Hull White parameters
21 \ingroup models
22*/
23
24#ifndef quantext_piecewiseconstant_irlgm1f_hwadaptor_hpp
25#define quantext_piecewiseconstant_irlgm1f_hwadaptor_hpp
26
27#include <ql/math/comparison.hpp>
30
31namespace QuantExt {
32
33//! LGM 1f Piecewise Constant Hull White Adaptor
34/*! \ingroup models
35 */
36template <class TS>
40public:
42 const Currency& currency, const Handle<TS>& termStructure, const Array& sigmaTimes, const Array& sigma,
43 const Array& kappaTimes, const Array& kappa, const std::string& name = std::string(),
44 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& sigmaConstraint = QuantLib::ext::make_shared<QuantLib::NoConstraint>(),
45 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& kappaConstraint = QuantLib::ext::make_shared<QuantLib::NoConstraint>());
47 const Currency& currency, const Handle<TS>& termStructure, const std::vector<Date>& sigmaDates,
48 const Array& sigma, const std::vector<Date>& kappaDates, const Array& kappa,
49 const std::string& name = std::string(),
50 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& sigmaConstraint = QuantLib::ext::make_shared<QuantLib::NoConstraint>(),
51 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& kappaConstraint = QuantLib::ext::make_shared<QuantLib::NoConstraint>());
52 Real zeta(const Time t) const override;
53 Real H(const Time t) const override;
54 Real alpha(const Time t) const override;
55 Real kappa(const Time t) const override;
56 Real Hprime(const Time t) const override;
57 Real Hprime2(const Time t) const override;
58 Real hullWhiteSigma(const Time t) const override;
59 const Array& parameterTimes(const Size) const override;
60 const QuantLib::ext::shared_ptr<Parameter> parameter(const Size) const override;
61 void update() const override;
62
63protected:
64 Real direct(const Size i, const Real x) const override;
65 Real inverse(const Size j, const Real y) const override;
66
67private:
68 void initialize(const Array& sigma, const Array& kappa);
69};
70
71// implementation
72
73template <class TS>
75 const Currency& currency, const Handle<TS>& termStructure, const Array& sigmaTimes, const Array& sigma,
76 const Array& kappaTimes, const Array& kappa, const std::string& name,
77 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& sigmaConstraint,
78 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& kappaConstraint)
79 : Lgm1fParametrization<TS>(currency, termStructure, name),
80 PiecewiseConstantHelper3(sigmaTimes, kappaTimes, sigmaConstraint, kappaConstraint),
82 initialize(sigma, kappa);
83}
84
85template <class TS>
87 const Currency& currency, const Handle<TS>& termStructure, const std::vector<Date>& sigmaDates, const Array& sigma,
88 const std::vector<Date>& kappaDates, const Array& kappa, const std::string& name,
89 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& sigmaConstraint,
90 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& kappaConstraint)
91 : Lgm1fParametrization<TS>(currency, termStructure, name),
92 PiecewiseConstantHelper3(sigmaDates, kappaDates, termStructure, sigmaConstraint, kappaConstraint),
94 initialize(sigma, kappa);
95}
96
97template <class TS>
98void Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::initialize(const Array& sigma, const Array& kappa) {
99 QL_REQUIRE(PiecewiseConstantHelper3::t1().size() + 1 == sigma.size(),
100 "sigma size (" << sigma.size() << ") inconsistent to times size ("
101 << PiecewiseConstantHelper3::t1().size() << ")");
102 QL_REQUIRE(PiecewiseConstantHelper2::t().size() + 1 == kappa.size(),
103 "kappa size (" << kappa.size() << ") inconsistent to times size ("
104 << PiecewiseConstantHelper2::t().size() << ")");
105
106 // store raw parameter values
107 for (Size i = 0; i < PiecewiseConstantHelper3::y1_->size(); ++i) {
108 PiecewiseConstantHelper3::y1_->setParam(i, inverse(0, sigma[i]));
109 }
110 for (Size i = 0; i < PiecewiseConstantHelper3::y2_->size(); ++i) {
111 PiecewiseConstantHelper3::y2_->setParam(i, inverse(1, kappa[i]));
112 }
113 update();
114}
115
116// inline
117
118template <class TS> inline Real Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::direct(const Size i, const Real x) const {
120}
121
122template <class TS> inline Real Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::inverse(const Size i, const Real y) const {
124}
125
126template <class TS> inline Real Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::zeta(const Time t) const {
127 return PiecewiseConstantHelper3::int_y1_sqr_exp_2_int_y2(t) / (this->scaling_ * this->scaling_);
128}
129
130template <class TS> inline Real Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::alpha(const Time t) const {
131 return hullWhiteSigma(t) / Hprime(t) / this->scaling_;
132}
133
134template <class TS> inline Real Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::H(const Time t) const {
135 return this->scaling_ * PiecewiseConstantHelper2::int_exp_m_int_y(t) + this->shift_;
136}
137
138template <class TS> inline Real Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::kappa(const Time t) const {
140}
141
142template <class TS> inline Real Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::Hprime(const Time t) const {
143 return this->scaling_ * PiecewiseConstantHelper2::exp_m_int_y(t);
144}
145
146template <class TS> inline Real Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::Hprime2(const Time t) const {
147 return -this->scaling_ * PiecewiseConstantHelper2::exp_m_int_y(t) * kappa(t);
148}
149
150template <class TS> inline Real Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::hullWhiteSigma(const Time t) const {
152}
153
154template <class TS> inline void Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::update() const {
158}
159
160template <class TS> inline const Array& Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::parameterTimes(const Size i) const {
161 QL_REQUIRE(i < 2, "parameter " << i << " does not exist, only have 0..1");
162 if (i == 0)
164 else
166}
167
168template <class TS>
169inline const QuantLib::ext::shared_ptr<Parameter> Lgm1fPiecewiseConstantHullWhiteAdaptor<TS>::parameter(const Size i) const {
170 QL_REQUIRE(i < 2, "parameter " << i << " does not exist, only have 0..1");
171 if (i == 0)
173 else
175}
176
177// typedef
178
180
181} // namespace QuantExt
182
183#endif
const Handle< TS > termStructure() const
Lgm1fPiecewiseConstantHullWhiteAdaptor(const Currency &currency, const Handle< TS > &termStructure, const Array &sigmaTimes, const Array &sigma, const Array &kappaTimes, const Array &kappa, const std::string &name=std::string(), const QuantLib::ext::shared_ptr< QuantLib::Constraint > &sigmaConstraint=QuantLib::ext::make_shared< QuantLib::NoConstraint >(), const QuantLib::ext::shared_ptr< QuantLib::Constraint > &kappaConstraint=QuantLib::ext::make_shared< QuantLib::NoConstraint >())
const QuantLib::ext::shared_ptr< Parameter > parameter(const Size) const override
const std::string & name() const
virtual const Currency & currency() const
Real exp_m_int_y(const Time t) const
exp(int_0^t -y(s)) ds
Real int_exp_m_int_y(const Time t) const
int_0^t exp(int_0^s -y(u) du) ds
const QuantLib::ext::shared_ptr< PseudoParameter > y_
const QuantLib::ext::shared_ptr< PseudoParameter > y1_
Real int_y1_sqr_exp_2_int_y2(const Time t) const
int_0^t y1^2(s) exp(2*int_0^s y2(u) du) ds
const QuantLib::ext::shared_ptr< PseudoParameter > y2_
Interest Rate Linear Gaussian Markov 1 factor parametrization.
QuantLib::SparseMatrix inverse(QuantLib::SparseMatrix m)
Lgm1fPiecewiseConstantHullWhiteAdaptor< YieldTermStructure > IrLgm1fPiecewiseConstantHullWhiteAdaptor
helper classes for piecewise constant parametrizations