Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
irlgm1fconstantparametrization.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 irlgm1fconstantparametrization.hpp
20 \brief constant model parametrization
21 \ingroup models
22*/
23
24#ifndef quantext_constant_irlgm1f_parametrizations_hpp
25#define quantext_constant_irlgm1f_parametrizations_hpp
26
28
29namespace QuantExt {
30
31//! LGM 1F Constant Parametrization
32/*! \ingroup models
33 */
34template <class TS> class Lgm1fConstantParametrization : public Lgm1fParametrization<TS> {
35public:
36 Lgm1fConstantParametrization(const Currency& currency, const Handle<TS>& termStructure, const Real alpha,
37 const Real kappa, const std::string& name = std::string());
38 Real zeta(const Time t) const override;
39 Real H(const Time t) const override;
40 Real alpha(const Time t) const override;
41 Real kappa(const Time t) const override;
42 Real Hprime(const Time t) const override;
43 Real Hprime2(const Time t) const override;
44 const QuantLib::ext::shared_ptr<Parameter> parameter(const Size) const override;
45
46protected:
47 Real direct(const Size i, const Real x) const override;
48 Real inverse(const Size j, const Real y) const override;
49
50private:
51 const QuantLib::ext::shared_ptr<PseudoParameter> alpha_, kappa_;
52 const Real zeroKappaCutoff_;
53};
54
55// implementation
56
57template <class TS>
59 const Handle<TS>& termStructure, const Real alpha,
60 const Real kappa, const std::string& name)
61 : Lgm1fParametrization<TS>(currency, termStructure, name), alpha_(QuantLib::ext::make_shared<PseudoParameter>(1)),
62 kappa_(QuantLib::ext::make_shared<PseudoParameter>(1)), zeroKappaCutoff_(1.0E-6) {
63 alpha_->setParam(0, inverse(0, alpha));
64 kappa_->setParam(0, inverse(1, kappa));
65}
66
67// inline
68
69template <class TS> inline Real Lgm1fConstantParametrization<TS>::direct(const Size i, const Real x) const {
70 return i == 0 ? x * x : x;
71}
72
73template <class TS> inline Real Lgm1fConstantParametrization<TS>::inverse(const Size i, const Real y) const {
74 return i == 0 ? std::sqrt(y) : y;
75}
76
77template <class TS> inline Real Lgm1fConstantParametrization<TS>::zeta(const Time t) const {
78 return direct(0, alpha_->params()[0]) * direct(0, alpha_->params()[0]) * t / (this->scaling_ * this->scaling_);
79}
80
81template <class TS> inline Real Lgm1fConstantParametrization<TS>::H(const Time t) const {
82 if (std::fabs(kappa_->params()[0]) < zeroKappaCutoff_) {
83 return this->scaling_ * t + this->shift_;
84 } else {
85 return this->scaling_ * (1.0 - std::exp(-kappa_->params()[0] * t)) / kappa_->params()[0] + this->shift_;
86 }
87}
88
89template <class TS> inline Real Lgm1fConstantParametrization<TS>::alpha(const Time) const {
90 return direct(0, alpha_->params()[0]) / this->scaling_;
91}
92
93template <class TS> inline Real Lgm1fConstantParametrization<TS>::kappa(const Time) const {
94 return kappa_->params()[0];
95}
96
97template <class TS> inline Real Lgm1fConstantParametrization<TS>::Hprime(const Time t) const {
98 return this->scaling_ * std::exp(-kappa_->params()[0] * t);
99}
100
101template <class TS> inline Real Lgm1fConstantParametrization<TS>::Hprime2(const Time t) const {
102 return -this->scaling_ * kappa_->params()[0] * std::exp(-kappa_->params()[0] * t);
103}
104
105template <class TS>
106inline const QuantLib::ext::shared_ptr<Parameter> Lgm1fConstantParametrization<TS>::parameter(const Size i) const {
107 QL_REQUIRE(i < 2, "parameter " << i << " does not exist, only have 0..1");
108 if (i == 0)
109 return alpha_;
110 else
111 return kappa_;
112}
113
114// typedef
115
117
118} // namespace QuantExt
119
120#endif
Real direct(const Size i, const Real x) const override
const QuantLib::ext::shared_ptr< PseudoParameter > alpha_
Real inverse(const Size j, const Real y) const override
const QuantLib::ext::shared_ptr< PseudoParameter > kappa_
const QuantLib::ext::shared_ptr< Parameter > parameter(const Size) const override
Lgm1fConstantParametrization(const Currency &currency, const Handle< TS > &termStructure, const Real alpha, const Real kappa, const std::string &name=std::string())
const Handle< TS > termStructure() const
const std::string & name() const
virtual const Currency & currency() const
Parameter that accesses CalibratedModel.
Interest Rate Linear Gaussian Markov 1 factor parametrization.
Lgm1fConstantParametrization< YieldTermStructure > IrLgm1fConstantParametrization