Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
hwconstantparametrization.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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 hwconstantparametrization.hpp
20 \brief Hull White n factor parametrization with constant reversion and vol
21 \ingroup models
22*/
23
24#pragma once
25
27
28namespace QuantExt {
29
30//! HW nF Parametrization with m driving Brownian motions and constant reversion, vol
31/*! \ingroup models
32 */
33template <class TS> class HwConstantParametrization : public HwParametrization<TS> {
34public:
35 HwConstantParametrization(const QuantLib::Currency& currency, const QuantLib::Handle<TS>& termStructure,
36 QuantLib::Matrix sigma, QuantLib::Array kappa, const std::string& name = std::string());
37
38 QuantLib::Matrix sigma_x(const QuantLib::Time t) const override { return sigma_; }
39 QuantLib::Array kappa(const QuantLib::Time t) const override { return kappa_; };
40 QuantLib::Matrix y(const QuantLib::Time t) const override;
41 QuantLib::Array g(const QuantLib::Time t, const QuantLib::Time T) const override;
42
43private:
44 static constexpr QuantLib::Real zeroKappaCutoff_ = 1.0E-6;
45 QuantLib::Matrix sigma_;
46 QuantLib::Array kappa_;
47};
48
49// implementation
50
51template <class TS>
53 const QuantLib::Handle<TS>& termStructure,
54 QuantLib::Matrix sigma, QuantLib::Array kappa,
55 const std::string& name)
56 : HwParametrization<TS>(kappa.size(), sigma.rows(), currency, termStructure, name.empty() ? currency.code() : name),
57 sigma_(std::move(sigma)), kappa_(std::move(kappa)) {
58 QL_REQUIRE(sigma_.columns() == kappa_.size(), "HwConstantParametrization: sigma ("
59 << sigma_.rows() << "x" << sigma_.columns()
60 << ") not consistent with kappa (" << kappa_.size() << ")");
61}
62
63template <class TS> QuantLib::Matrix HwConstantParametrization<TS>::y(const QuantLib::Time t) const {
64 QuantLib::Matrix y(this->n_, this->n_, 0.0);
65 for (Size i = 0; i < this->n_; ++i) {
66 for (Size j = 0; j <= i; ++j) {
67 QuantLib::Real tmp;
68 if (std::abs(kappa_[i] + kappa_[j]) < zeroKappaCutoff_) {
69 tmp = t;
70 } else {
71 tmp = (1.0 - std::exp(-(kappa_[i] + kappa_[j]) * t)) / (kappa_[i] + kappa_[j]);
72 }
73 for (Size k = 0; k < this->m_; ++k) {
74 y(i, j) += sigma_x(t)(k, i) * sigma_x(t)(k, j) * tmp;
75 }
76 }
77 }
78 for (Size i = 0; i < this->n_; ++i) {
79 for (Size j = 0; j < i; ++j) {
80 y(j, i) = y(i, j);
81 }
82 }
83 return y;
84}
85
86template <class TS>
87QuantLib::Array HwConstantParametrization<TS>::g(const QuantLib::Time t, const QuantLib::Time T) const {
88 QL_REQUIRE(t <= T, "HwConstantParametrization::g(" << t << "," << T << ") invalid, expected t < T");
89 QuantLib::Array g(this->n_, 0.0);
90 for (Size i = 0; i < this->n_; ++i) {
91 if (std::abs(kappa_[i]) < zeroKappaCutoff_) {
92 g[i] = T - t;
93 } else {
94 g[i] = (1.0 - std::exp(-kappa_[i] * (T - t))) / kappa_[i];
95 }
96 }
97 return g;
98}
99
100// typedef
101
103
104} // namespace QuantExt
HW nF Parametrization with m driving Brownian motions and constant reversion, vol.
HwConstantParametrization(const QuantLib::Currency &currency, const QuantLib::Handle< TS > &termStructure, QuantLib::Matrix sigma, QuantLib::Array kappa, const std::string &name=std::string())
QuantLib::Array g(const QuantLib::Time t, const QuantLib::Time T) const override
QuantLib::Array kappa(const QuantLib::Time t) const override
static constexpr QuantLib::Real zeroKappaCutoff_
QuantLib::Matrix y(const QuantLib::Time t) const override
QuantLib::Matrix sigma_x(const QuantLib::Time t) const override
HW nF Parametrization with m driving Brownian motions.
const QuantLib::Handle< TS > termStructure() const
const std::string & name() const
virtual const Currency & currency() const
Hull White n factor parametrization.
HwConstantParametrization< YieldTermStructure > IrHwConstantParametrization