Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
discountratiomodifiedcurve.cpp
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
20
21using QuantLib::Calendar;
22using QuantLib::Date;
23using QuantLib::DayCounter;
24using QuantLib::DiscountFactor;
25using QuantLib::Handle;
26using QuantLib::Natural;
27using QuantLib::Time;
28using QuantLib::YieldTermStructure;
29
30namespace QuantExt {
31
32DiscountRatioModifiedCurve::DiscountRatioModifiedCurve(const Handle<YieldTermStructure>& baseCurve,
33 const Handle<YieldTermStructure>& numCurve,
34 const Handle<YieldTermStructure>& denCurve)
35 : baseCurve_(baseCurve), numCurve_(numCurve), denCurve_(denCurve) {
36
37 // Cannot construct with empty curves
38 check();
39
40 // All range checks will happen in underlying curves
41 enableExtrapolation(true);
42
43 // Observe the underlying curves
44 registerWith(baseCurve_);
45 registerWith(numCurve_);
46 registerWith(denCurve_);
47}
48
49DayCounter DiscountRatioModifiedCurve::dayCounter() const { return baseCurve_->dayCounter(); }
50
51Calendar DiscountRatioModifiedCurve::calendar() const { return baseCurve_->calendar(); }
52
53Natural DiscountRatioModifiedCurve::settlementDays() const { return baseCurve_->settlementDays(); }
54
55const Date& DiscountRatioModifiedCurve::referenceDate() const { return baseCurve_->referenceDate(); }
56
58 // Make sure that any change to underlying curves leaves them valid
59 check();
60
61 YieldTermStructure::update();
62}
63
64DiscountFactor DiscountRatioModifiedCurve::discountImpl(Time t) const {
65 return baseCurve_->discount(t) * numCurve_->discount(t) / denCurve_->discount(t);
66}
67
69 QL_REQUIRE(!baseCurve_.empty(), "DiscountRatioModifiedCurve: base curve should not be empty");
70 QL_REQUIRE(!numCurve_.empty(), "DiscountRatioModifiedCurve: numerator curve should not be empty");
71 QL_REQUIRE(!denCurve_.empty(), "DiscountRatioModifiedCurve: denominator curve should not be empty");
72}
73
74} // namespace QuantExt
QuantLib::Calendar calendar() const override
Returns the calendar from 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.
DiscountRatioModifiedCurve(const QuantLib::Handle< QuantLib::YieldTermStructure > &baseCurve, const QuantLib::Handle< QuantLib::YieldTermStructure > &numCurve, const QuantLib::Handle< QuantLib::YieldTermStructure > &denCurve)
Constructor providing the three underlying yield curves.
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_
discount curve modified by the ratio of two other discount curves