Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
cirppconstantparametrization.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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 cirppconstantparametrization.hpp
20 \brief constant CIR ++ parametrization
21 \ingroup models
22*/
23
24#ifndef quantext_cirpp_constant_parametrization_hpp
25#define quantext_cirpp_constant_parametrization_hpp
26
28
29#include <ql/errors.hpp>
30
31namespace QuantExt {
32
33//! CIR++ Constant Parametrization
34/*! \ingroup models
35 */
36template <class TS> class CirppConstantParametrization : public CirppParametrization<TS> {
37public:
38 CirppConstantParametrization(const Currency& currency, const Handle<TS>& termStructure, const Real kappa,
39 const Real theta, const Real sigma, const Real y0, const bool shifted,
40 const std::string& name = std::string());
41
42 Real kappa(const Time t) const;
43 Real theta(const Time t) const;
44 Real sigma(const Time t) const;
45 Real y0(const Time t) const;
46
47 const QuantLib::ext::shared_ptr<Parameter> parameter(const Size) const;
48
49protected:
50 Real direct(const Size i, const Real x) const;
51 Real inverse(const Size j, const Real y) const;
52
53private:
54 const QuantLib::ext::shared_ptr<PseudoParameter> kappa_, theta_, sigma_, y0_;
55};
56
57// implementation
58
59template <class TS>
61 const Handle<TS>& termStructure,
62 const Real kappa, const Real theta,
63 const Real sigma, const Real y0,
64 const bool shifted,
65 const std::string& name)
66 : CirppParametrization<TS>(currency, termStructure, shifted, name),
67 kappa_(QuantLib::ext::make_shared<PseudoParameter>(1)),
68 theta_(QuantLib::ext::make_shared<PseudoParameter>(1)), sigma_(QuantLib::ext::make_shared<PseudoParameter>(1)),
69 y0_(QuantLib::ext::make_shared<PseudoParameter>(1)) {
70 kappa_->setParam(0, inverse(0, kappa));
71 theta_->setParam(0, inverse(1, theta));
72 sigma_->setParam(0, inverse(2, sigma));
73 y0_->setParam(0, inverse(3, y0));
74}
75
76template <class TS> inline Real CirppConstantParametrization<TS>::direct(const Size i, const Real x) const {
77 constexpr Real eps = 1E-10;
78 return x * x + eps;
79}
80
81template <class TS> inline Real CirppConstantParametrization<TS>::inverse(const Size i, const Real y) const {
82 constexpr Real eps = 1E-10;
83 return std::sqrt(y - eps);
84}
85
86template <class TS> inline Real CirppConstantParametrization<TS>::kappa(const Time) const {
87 return direct(0, kappa_->params()[0]);
88}
89
90template <class TS> inline Real CirppConstantParametrization<TS>::theta(const Time) const {
91 return direct(1, theta_->params()[0]);
92}
93
94template <class TS> inline Real CirppConstantParametrization<TS>::sigma(const Time) const {
95 return direct(2, sigma_->params()[0]);
96}
97
98template <class TS> inline Real CirppConstantParametrization<TS>::y0(const Time) const {
99 return direct(3, y0_->params()[0]);
100}
101
102template <class TS>
103inline const QuantLib::ext::shared_ptr<Parameter> CirppConstantParametrization<TS>::parameter(const Size i) const {
104 QL_REQUIRE(i < 4, "parameter " << i << " does not exist, only have 0..3");
105 if (i == 0)
106 return kappa_;
107 else if (i == 1)
108 return theta_;
109 else if (i == 2)
110 return sigma_;
111 else
112 return y0_;
113}
114
115// typedef
118
119} // namespace QuantExt
120
121#endif
CIR ++ parametrisation.
const QuantLib::ext::shared_ptr< Parameter > parameter(const Size) const
Real direct(const Size i, const Real x) const
const QuantLib::ext::shared_ptr< PseudoParameter > theta_
const QuantLib::ext::shared_ptr< PseudoParameter > sigma_
const QuantLib::ext::shared_ptr< PseudoParameter > y0_
CirppConstantParametrization(const Currency &currency, const Handle< TS > &termStructure, const Real kappa, const Real theta, const Real sigma, const Real y0, const bool shifted, const std::string &name=std::string())
Real inverse(const Size j, const Real y) const
const QuantLib::ext::shared_ptr< PseudoParameter > kappa_
const Handle< TS > termStructure() const
const std::string & name() const
virtual const Currency & currency() const
Parameter that accesses CalibratedModel.
CirppConstantParametrization< DefaultProbabilityTermStructure > CrCirppConstantParametrization
CirppConstantParametrization< YieldTermStructure > IrCirppConstantParametrization