Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
weightedyieldtermstructure.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 weightedyieldtermstructure.hpp
20 \brief yield term structure given as a weighted average of yield term structures
21 \ingroup models
22*/
23
24#ifndef quantext_weighted_yts_hpp
25#define quantext_weighted_yts_hpp
26
27#include <ql/termstructures/yieldtermstructure.hpp>
28
29namespace QuantExt {
30using namespace QuantLib;
31
32//! weighted yield term structure
33/*! this yield term structure is defined by discount factors given by a weighted geometric average of discount factors
34 of underlying curves; this corresponds to a weighted arithmetic average of instantaneous forward rates and can be
35 used to interpolate e.g. a Euribor2M curve between Euribor1M and Euribor3M (using w1=w2=0.5)
36*/
37class WeightedYieldTermStructure : public YieldTermStructure {
38public:
39 WeightedYieldTermStructure(const Handle<YieldTermStructure>& yts1, const Handle<YieldTermStructure>& yts2,
40 const Real w1, const Real w2)
41 : YieldTermStructure(yts1->dayCounter()), yts1_(yts1), yts2_(yts2), w1_(w1), w2_(w2) {
42 QL_REQUIRE(yts1->dayCounter() == yts2->dayCounter(),
43 "WeightedYieldTermStructure(): sources have inconsistent day counters ("
44 << yts1->dayCounter().name() << " vs. " << yts2->dayCounter().name());
45 registerWith(yts1);
46 registerWith(yts2);
47 }
48 Date maxDate() const override;
49 const Date& referenceDate() const override;
50
51protected:
52 Real discountImpl(Time t) const override;
53 const Handle<YieldTermStructure> yts1_, yts2_;
54 const Real w1_, w2_;
55};
56
57// inline
58
59inline Date WeightedYieldTermStructure::maxDate() const { return std::min(yts1_->maxDate(), yts2_->maxDate()); }
60
62 QL_REQUIRE(yts1_->referenceDate() == yts2_->referenceDate(),
63 "WeightedYieldTermStructure::referenceDate(): inconsistent reference dates in sources ("
64 << yts1_->referenceDate() << " vs. " << yts2_->referenceDate());
65 return yts1_->referenceDate();
66}
67
69 return std::pow(yts1_->discount(t), w1_) * std::pow(yts2_->discount(t), w2_);
70}
71
72} // namespace QuantExt
73
74#endif
const Handle< YieldTermStructure > yts1_
WeightedYieldTermStructure(const Handle< YieldTermStructure > &yts1, const Handle< YieldTermStructure > &yts2, const Real w1, const Real w2)
const Handle< YieldTermStructure > yts2_