Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
irlgm1fpiecewiseconstantparametrization.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 irlgm1fpiecewiseconstantparametrization.hpp
20 \brief piecewise constant model parametrization
21 \ingroup models
22*/
23
24#ifndef quantext_piecewiseconstant_irlgm1f_parametrization_hpp
25#define quantext_piecewiseconstant_irlgm1f_parametrization_hpp
26
29
30namespace QuantExt {
31
32//! LGM 1F Piecewise Constant Parametrization
33/*! \ingroup models
34 */
35template <class TS>
39public:
40 Lgm1fPiecewiseConstantParametrization(const Currency& currency, const Handle<TS>& termStructure,
41 const Array& alphaTimes, const Array& alpha, const Array& kappaTimes,
42 const Array& kappa, const std::string& name = std::string(),
43 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& alphaConstraint = QuantLib::ext::make_shared<QuantLib::NoConstraint>(),
44 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& kappaConstraint = QuantLib::ext::make_shared<QuantLib::NoConstraint>());
45 Lgm1fPiecewiseConstantParametrization(const Currency& currency, const Handle<TS>& termStructure,
46 const std::vector<Date>& alphaDates, const Array& alpha,
47 const std::vector<Date>& kappaDates, const Array& kappa,
48 const std::string& name = std::string(),
49 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& alphaConstraint = QuantLib::ext::make_shared<QuantLib::NoConstraint>(),
50 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& kappaConstraint = QuantLib::ext::make_shared<QuantLib::NoConstraint>());
51
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 const Array& parameterTimes(const Size) const override;
59 const QuantLib::ext::shared_ptr<Parameter> parameter(const Size) const override;
60 void update() const override;
61
62protected:
63 Real direct(const Size i, const Real x) const override;
64 Real inverse(const Size j, const Real y) const override;
65
66private:
67 void initialize(const Array& alpha, const Array& kappa);
68};
69
70// implementation
71
72template <class TS>
74 const Currency& currency, const Handle<TS>& termStructure, const Array& alphaTimes, const Array& alpha,
75 const Array& kappaTimes, const Array& kappa, const std::string& name,
76 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& alphaConstraint,
77 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& kappaConstraint)
78 : Lgm1fParametrization<TS>(currency, termStructure, name),
79 PiecewiseConstantHelper1(alphaTimes, alphaConstraint),
80 PiecewiseConstantHelper2(kappaTimes, kappaConstraint) {
82}
83
84template <class TS>
86 const Currency& currency, const Handle<TS>& termStructure, const std::vector<Date>& alphaDates, const Array& alpha,
87 const std::vector<Date>& kappaDates, const Array& kappa, const std::string& name,
88 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& alphaConstraint,
89 const QuantLib::ext::shared_ptr<QuantLib::Constraint>& kappaConstraint)
90 : Lgm1fParametrization<TS>(currency, termStructure, name),
91 PiecewiseConstantHelper1(alphaDates, termStructure, alphaConstraint),
92 PiecewiseConstantHelper2(kappaDates, termStructure, kappaConstraint) {
94}
95
96template <class TS> void Lgm1fPiecewiseConstantParametrization<TS>::initialize(const Array& alpha, const Array& kappa) {
97 QL_REQUIRE(PiecewiseConstantHelper1::t().size() + 1 == alpha.size(),
98 "alpha size (" << alpha.size() << ") inconsistent to times size ("
99 << PiecewiseConstantHelper1::t().size() << ")");
100 QL_REQUIRE(PiecewiseConstantHelper2::t().size() + 1 == kappa.size(),
101 "kappa size (" << kappa.size() << ") inconsistent to times size ("
102 << PiecewiseConstantHelper2::t().size() << ")");
103 // store raw parameter values
104 for (Size i = 0; i < PiecewiseConstantHelper1::y_->size(); ++i) {
105 PiecewiseConstantHelper1::y_->setParam(i, inverse(0, alpha[i]));
106 }
107 for (Size i = 0; i < PiecewiseConstantHelper2::y_->size(); ++i) {
108 PiecewiseConstantHelper2::y_->setParam(i, inverse(1, kappa[i]));
109 }
110 update();
111}
112
113// inline
114
115template <class TS> inline Real Lgm1fPiecewiseConstantParametrization<TS>::direct(const Size i, const Real x) const {
117}
118
119template <class TS> inline Real Lgm1fPiecewiseConstantParametrization<TS>::inverse(const Size i, const Real y) const {
121}
122
123template <class TS> inline Real Lgm1fPiecewiseConstantParametrization<TS>::zeta(const Time t) const {
124 return PiecewiseConstantHelper1::int_y_sqr(t) / (this->scaling_ * this->scaling_);
125}
126
127template <class TS> inline Real Lgm1fPiecewiseConstantParametrization<TS>::H(const Time t) const {
128 return this->scaling_ * PiecewiseConstantHelper2::int_exp_m_int_y(t) + this->shift_;
129}
130
131template <class TS> inline Real Lgm1fPiecewiseConstantParametrization<TS>::alpha(const Time t) const {
132 return PiecewiseConstantHelper1::y(t) / this->scaling_;
133}
134
135template <class TS> inline Real Lgm1fPiecewiseConstantParametrization<TS>::kappa(const Time t) const {
137}
138
139template <class TS> inline Real Lgm1fPiecewiseConstantParametrization<TS>::Hprime(const Time t) const {
140 return this->scaling_ * PiecewiseConstantHelper2::exp_m_int_y(t);
141}
142
143template <class TS> inline Real Lgm1fPiecewiseConstantParametrization<TS>::Hprime2(const Time t) const {
144 return -this->scaling_ * PiecewiseConstantHelper2::exp_m_int_y(t) * kappa(t);
145}
146
147template <class TS> inline void Lgm1fPiecewiseConstantParametrization<TS>::update() const {
151}
152
153template <class TS> inline const Array& Lgm1fPiecewiseConstantParametrization<TS>::parameterTimes(const Size i) const {
154 QL_REQUIRE(i < 2, "parameter " << i << " does not exist, only have 0..1");
155 if (i == 0)
157 else
159}
160
161template <class TS>
162inline const QuantLib::ext::shared_ptr<Parameter> Lgm1fPiecewiseConstantParametrization<TS>::parameter(const Size i) const {
163 QL_REQUIRE(i < 2, "parameter " << i << " does not exist, only have 0..1");
164 if (i == 0)
166 else
168}
169
170// typedef
171
173
174} // namespace QuantExt
175
176#endif
const Handle< TS > termStructure() const
Lgm1fPiecewiseConstantParametrization(const Currency &currency, const Handle< TS > &termStructure, const Array &alphaTimes, const Array &alpha, const Array &kappaTimes, const Array &kappa, const std::string &name=std::string(), const QuantLib::ext::shared_ptr< QuantLib::Constraint > &alphaConstraint=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
const QuantLib::ext::shared_ptr< PseudoParameter > y_
Real int_y_sqr(const Time t) const
int_0^t y^2(s) ds
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_
Interest Rate Linear Gaussian Markov 1 factor parametrization.
QuantLib::SparseMatrix inverse(QuantLib::SparseMatrix m)
Lgm1fPiecewiseConstantParametrization< YieldTermStructure > IrLgm1fPiecewiseConstantParametrization
helper classes for piecewise constant parametrizations