Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
hwmodel.cpp
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
21
22namespace QuantExt {
23
24HwModel::HwModel(const QuantLib::ext::shared_ptr<IrHwParametrization>& parametrization, const Measure measure,
25 const Discretization discretization, const bool evaluateBankAccount)
26 : parametrization_(parametrization), measure_(measure), discretization_(discretization),
27 evaluateBankAccount_(evaluateBankAccount) {
28 QL_REQUIRE(parametrization_ != nullptr, "HwModel: parametrization is null");
30 QuantLib::ext::make_shared<IrHwStateProcess>(parametrization_, measure_, discretization_, evaluateBankAccount_);
31}
32
33QuantLib::Real HwModel::discountBond(const QuantLib::Time t, const QuantLib::Time T, const QuantLib::Array& x,
34 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve) const {
35 if (QuantLib::close_enough(t, T))
36 return 1.0;
37 QL_REQUIRE(T >= t && t >= 0.0, "T(" << T << ") >= t(" << t << ") >= 0 required in HwModel::discountBond");
38 QuantLib::Array gt = parametrization_->g(t, T);
39 QuantLib::Matrix yt = parametrization_->y(t);
40
41 return (discountCurve.empty()
42 ? parametrization_->termStructure()->discount(T) / parametrization_->termStructure()->discount(t)
43 : discountCurve->discount(T) / discountCurve->discount(t)) *
44 std::exp(-QuantLib::DotProduct(gt, x) - 0.5 * QuantLib::DotProduct(gt, yt * gt));
45}
46
47QuantLib::Real HwModel::numeraire(const QuantLib::Time t, const QuantLib::Array& x,
48 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve,
49 const QuantLib::Array& aux) const {
50 QL_REQUIRE(measure_ == IrModel::Measure::BA, "HwModel::numeraire() supports BA measure only currently.");
51 return std::exp(std::accumulate(aux.begin(), aux.end(), 0.0)) /
52 (discountCurve.empty() ? parametrization_->termStructure()->discount(t) : discountCurve->discount(t));
53}
54
55QuantLib::Real HwModel::shortRate(const QuantLib::Time t, const QuantLib::Array& x,
56 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve) const {
57 return std::accumulate(x.begin(), x.end(), 0.0) +
58 (discountCurve.empty() ? parametrization_->termStructure()->forwardRate(t, t, Compounding::Continuous)
59 : discountCurve->forwardRate(t, t, Compounding::Continuous));
60}
61
63 parametrization_->update();
64 notifyObservers();
65}
66
68
69Size HwModel::n() const { return parametrization_->n(); }
70Size HwModel::m() const { return parametrization_->m(); }
71Size HwModel::n_aux() const { return evaluateBankAccount_ && measure_ == Measure::BA ? n() : 0; }
72Size HwModel::m_aux() const {
74}
75
76} // namespace QuantExt
Measure measure_
Definition: hwmodel.hpp:78
Size m() const override
Definition: hwmodel.cpp:70
Size n() const override
Definition: hwmodel.cpp:69
Size n_aux() const override
Definition: hwmodel.cpp:71
bool evaluateBankAccount_
Definition: hwmodel.hpp:81
void update() override
Definition: hwmodel.cpp:62
QuantLib::ext::shared_ptr< StochasticProcess > stateProcess_
Definition: hwmodel.hpp:80
HwModel(const QuantLib::ext::shared_ptr< IrHwParametrization > &parametrization, const Measure measure=Measure::BA, const Discretization discretization=Discretization::Euler, const bool evaluateBankAccount=true)
Definition: hwmodel.cpp:24
QuantLib::Real discountBond(const QuantLib::Time t, const QuantLib::Time T, const QuantLib::Array &x, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve=Handle< YieldTermStructure >()) const override
Definition: hwmodel.cpp:33
void generateArguments() override
Definition: hwmodel.cpp:67
QuantLib::Real shortRate(const QuantLib::Time t, const QuantLib::Array &x, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve=Handle< YieldTermStructure >()) const override
Definition: hwmodel.cpp:55
Discretization discretization_
Definition: hwmodel.hpp:79
Size m_aux() const override
Definition: hwmodel.cpp:72
QuantLib::ext::shared_ptr< IrHwParametrization > parametrization_
Definition: hwmodel.hpp:77
QuantLib::Real numeraire(const QuantLib::Time t, const QuantLib::Array &x, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), const QuantLib::Array &aux=Array()) const override
Definition: hwmodel.cpp:47
hull white n Factor model class
ir hw model state process