Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
jyimpliedzeroinflationtermstructure.cpp
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
22
23using QuantLib::Date;
24using QuantLib::Size;
25using QuantLib::Time;
26
27namespace QuantExt {
28
30 const QuantLib::ext::shared_ptr<CrossAssetModel>& model, Size index)
31 : ZeroInflationModelTermStructure(model, index) {}
32
33QL_DEPRECATED_DISABLE_WARNING
34JyImpliedZeroInflationTermStructure::JyImpliedZeroInflationTermStructure(
35 const QuantLib::ext::shared_ptr<CrossAssetModel>& model, Size index, bool indexIsInterpolated)
36 : ZeroInflationModelTermStructure(model, index, indexIsInterpolated) {}
37QL_DEPRECATED_ENABLE_WARNING
38
39Real JyImpliedZeroInflationTermStructure::zeroRateImpl(Time t) const {
40
41 QL_REQUIRE(t >= 0.0, "JyImpliedZeroInflationTermStructure::zeroRateImpl: negative time (" << t << ") given");
42
43 // Zero rate is calculated from the relation: P_n(S, T) (1 + z(S))^t = P_r(S, T)
44 // Here, S in the relation is given by relativeTime_ and T := S + t.
45 // ratio holds \frac{P_r(S, T)}{P_n(S, T)}.
46 auto S = relativeTime_;
47 auto T = relativeTime_ + t;
48 QL_DEPRECATED_DISABLE_WARNING
49 auto ratio = inflationGrowth(model_, index_, S, T, state_[2], state_[0], indexIsInterpolated_);
50 QL_DEPRECATED_ENABLE_WARNING
51 // Return the desired z(S) = \left( \frac{P_r(S, T)}{P_n(S, T)} \right)^{\frac{1}{t}} - 1
52 return std::pow(ratio, 1 / t) - 1;
53}
54
55void JyImpliedZeroInflationTermStructure::checkState() const {
56 // For JY, expect the state to be three variables i.e. z_I, c_I and z_{ir}.
57 QL_REQUIRE(state_.size() == 3, "JyImpliedZeroInflationTermStructure: expected state to have " <<
58 "three elements but got " << state_.size());
59}
60
61Real inflationGrowth(const QuantLib::ext::shared_ptr<CrossAssetModel>& model, Size index,
62 Time S, Time T, Real irState, Real rrState, bool indexIsInterpolated) {
63
64 QL_REQUIRE(T >= S, "inflationGrowth: end time (" << T << ") must be >= start time (" << S << ")");
65
66 // After this step, p_n holds P_n(S, T) * P_n(0, S) / P_n(0, T)
67 // = \exp \left( - \left[ H_n(T) - H_n(S) \right] z_n(S) -
68 // \frac{1}{2} \left[ H^2_n(T) - H^2_n(S) \right] \zeta_n(S) \right)
69 auto irIdx = model->ccyIndex(model->infjy(index)->currency());
70 auto irTs = model->irlgm1f(irIdx)->termStructure();
71 auto p_n = model->discountBond(irIdx, S, T, irState) * irTs->discount(S) / irTs->discount(T);
72
73 // After this step, p_r holds P_r(S, T) * P_r(0, S) / P_r(0, T)
74 // = \exp \left( - \left[ H_r(T) - H_r(S) \right] z_r(S) -
75 // \frac{1}{2} \left[ H^2_r(T) - H^2_r(S) \right] \zeta_r(S) \right)
76 auto rrParam = model->infjy(index)->realRate();
77 auto H_r_S = rrParam->H(S);
78 auto H_r_T = rrParam->H(T);
79 auto zeta_r_S = rrParam->zeta(S);
80 auto p_r = std::exp(-(H_r_T - H_r_S) * rrState - 0.5 * (H_r_T * H_r_T - H_r_S * H_r_S) * zeta_r_S);
81
82 // Now, use the original zero inflation term structure to get P_r(0, S) / P_n(0, S) and P_r(0, T) / P_n(0, T) and
83 // return \frac{P_r(S, T)}{P_n(S, T)}
84 const auto& zts = model->infjy(index)->realRate()->termStructure();
85 return inflationGrowth(zts, T, indexIsInterpolated) / inflationGrowth(zts, S, indexIsInterpolated) * p_r / p_n;
86
87}
88
89}
JyImpliedZeroInflationTermStructure(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, QuantLib::Size index)
analytics for the cross asset model
some inflation related utilities.
zero inflation term structure implied by a Jarrow Yildrim (JY) model
Real inflationGrowth(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, Size index, Time S, Time T, Real irState, Real rrState, bool indexIsInterpolated)