Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
discountratiomodifiedcurve.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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 qle/termstructures/discountratiomodifiedcurve.hpp
20 \brief discount curve modified by the ratio of two other discount curves
21*/
22
23#ifndef quantext_discount_ratio_modified_curve_hpp
24#define quantext_discount_ratio_modified_curve_hpp
25
26#include <ql/termstructures/yieldtermstructure.hpp>
27
28namespace QuantExt {
29
30/*! The DiscountRatioModifiedCurve depends on three other yield curves. The dependency is via the discount factor.
31 In particular, the discount factor \f$P(0, t)\f$ at time \f$t\f$ is given by:
32 \f[
33 P(0, t) = P_b(0, t) \frac{P_n(0, t)}{P_d(0, t)}
34 \f]
35 where \f$P_b(0, t)\f$ is the base curve discount factor, \f$P_n(0, t)\f$ is the numerator curve discount factor
36 and \f$P_d(0, t)\f$ is the denominator curve discount factor.
37
38 A use case for this type of discount curve is where we need to discount cashflows denominated in a currency, call
39 it currency 1, and collateralised in a different currency, call it currency 2. Let \f$P_{1, 2}(0, t)\f$ denote the
40 discount factor on this curve at time \f$t\f$. Assume that we have curves for discounting cashflows denominated in
41 currency 1 and currency 2 and collaterised in a common reference currency. Let \f$P_{1, ref}(0, t)\f$ and
42 \f$P_{2, ref}(0, t)\f$ denote the discount factors on these two curves respectively. Assume also that we have a
43 curve for discounting cashflows denominated and collateralised in currency 2. Let \f$P_{2, 2}(0, t)\f$ denote the
44 discount factor on this curve at time \f$t\f$. Then, by using DiscountRatioModifiedCurve we can set up the
45 following relation:
46 \f[
47 P_{1, 2}(0, t) = P_{2, 2}(0, t) \frac{P_{1, ref}(0, t)}{P_{2, ref}(0, t)}
48 \f]
49 The assumption here is that forward FX rates remain the same if the FX forward's collateral currency is switched
50 from the reference currency to currency 2.
51
52 \warning One must be careful about mixing floating reference date and fixed reference date curves together as the
53 underlying curves in this yield curve and then moving Settings::instance().evaluationDate(). This is
54 alluded to in the corresponding unit tests. If the <code>moving_</code> member variable of TermStructure
55 had an inspector method, then we could enforce that all underlying curves here are either floating or fixed
56 reference date curves.
57*/
58class DiscountRatioModifiedCurve : public QuantLib::YieldTermStructure {
59public:
60 //! Constructor providing the three underlying yield curves
61 DiscountRatioModifiedCurve(const QuantLib::Handle<QuantLib::YieldTermStructure>& baseCurve,
62 const QuantLib::Handle<QuantLib::YieldTermStructure>& numCurve,
63 const QuantLib::Handle<QuantLib::YieldTermStructure>& denCurve);
64
65 //! \name Inspectors
66 //@{
67 //! Return the base curve
68 const QuantLib::Handle<QuantLib::YieldTermStructure>& baseCurve() const { return baseCurve_; }
69 //! Return the numerator curve
70 const QuantLib::Handle<QuantLib::YieldTermStructure>& numeratorCurve() const { return numCurve_; }
71 //! Return the denominator curve
72 const QuantLib::Handle<QuantLib::YieldTermStructure>& denominatorCurve() const { return denCurve_; }
73 //@}
74
75 //! \name YieldTermStructure interface
76 //@{
77 //! Returns the day counter from the base curve
78 QuantLib::DayCounter dayCounter() const override;
79 //! Returns the calendar from the base curve
80 QuantLib::Calendar calendar() const override;
81 //! Returns the settlement days from the base curve
82 QuantLib::Natural settlementDays() const override;
83 //! Returns the reference date from the base curve
84 const QuantLib::Date& referenceDate() const override;
85 //! All range checks happen in the underlying curves
86 QuantLib::Date maxDate() const override { return QuantLib::Date::maxDate(); }
87 //@}
88
89 //! \name Observer interface
90 //@{
91 void update() override;
92 //@}
93
94protected:
95 //! \name YieldTermStructure interface
96 //@{
97 //! Perform the discount factor calculation using the three yield curves
98 QuantLib::DiscountFactor discountImpl(QuantLib::Time t) const override;
99 //@}
100
101private:
102 QuantLib::Handle<YieldTermStructure> baseCurve_;
103 QuantLib::Handle<YieldTermStructure> numCurve_;
104 QuantLib::Handle<YieldTermStructure> denCurve_;
105
106 //! Check that none of the underlying term structures are empty
107 void check() const;
108};
109
110} // namespace QuantExt
111
112#endif
const QuantLib::Handle< QuantLib::YieldTermStructure > & numeratorCurve() const
Return the numerator curve.
QuantLib::Calendar calendar() const override
Returns the calendar from the base curve.
const QuantLib::Handle< QuantLib::YieldTermStructure > & baseCurve() const
Return the base curve.
void check() const
Check that none of the underlying term structures are empty.
QuantLib::Handle< YieldTermStructure > numCurve_
const QuantLib::Date & referenceDate() const override
Returns the reference date from the base curve.
QuantLib::Natural settlementDays() const override
Returns the settlement days from the base curve.
QuantLib::DayCounter dayCounter() const override
Returns the day counter from the base curve.
QuantLib::Date maxDate() const override
All range checks happen in the underlying curves.
const QuantLib::Handle< QuantLib::YieldTermStructure > & denominatorCurve() const
Return the denominator curve.
QuantLib::Handle< YieldTermStructure > baseCurve_
QuantLib::DiscountFactor discountImpl(QuantLib::Time t) const override
Perform the discount factor calculation using the three yield curves.
QuantLib::Handle< YieldTermStructure > denCurve_