Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
yieldcurve.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 Copyright (C) 2021 Skandinaviska Enskilda Banken AB (publ)
4 Copyright (C) 2023 Oleg Kulkov
5 All rights reserved.
6
7 This file is part of ORE, a free-software/open-source library
8 for transparent pricing and risk analysis - http://opensourcerisk.org
9
10 ORE is free software: you can redistribute it and/or modify it
11 under the terms of the Modified BSD License. You should have received a
12 copy of the license along with this program.
13 The license is also available online at <http://opensourcerisk.org>
14
15 This program is distributed on the basis that it will form a useful
16 contribution to risk analytics and model standardisation, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file ored/marketdata/yieldcurve.hpp
22 \brief Wrapper class for QuantLib term structures.
23 \ingroup curves
24*/
25
26#pragma once
27
38
39#include <ql/termstructures/yield/ratehelpers.hpp>
40
41namespace ore {
42namespace data {
43using namespace QuantLib;
49
50class DefaultCurve;
51class ReferenceDataManager;
52
53//! Wrapper class for building yield term structures
54/*!
55 Given yield curve specification and its configuration
56 this class will actually build a QuantLib yield
57 termstructure.
58
59 \ingroup curves
60*/
62public:
63 //! Supported interpolation variables
65
66 //! Supported interpolation methods
68 Linear,
78 Hermite,
84 ExponentialSplines, // fitted bond curves only
85 NelsonSiegel, // fitted bond curves only
86 Svensson // fitted bond curves only
87 };
88
89 //! Constructor
90 YieldCurve( //! Valuation date
91 Date asof,
92 //! Yield curve specification
94 //! Repository of yield curve configurations
96 // TODO shared_ptr or ref?
97 //! Market data loader
98 const Loader& loader,
99 //! Map of underlying yield curves if required
100 const map<string, QuantLib::ext::shared_ptr<YieldCurve>>& requiredYieldCurves =
101 map<string, QuantLib::ext::shared_ptr<YieldCurve>>(),
102 //! Map of underlying default curves if required
103 const map<string, QuantLib::ext::shared_ptr<DefaultCurve>>& requiredDefaultCurves =
104 map<string, QuantLib::ext::shared_ptr<DefaultCurve>>(),
105 //! FxTriangultion to get FX rate from cross if needed
106 const FXTriangulation& fxTriangulation = FXTriangulation(),
107 //! optional pointer to reference data, needed to build fitted bond curves
108 const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceData = nullptr,
109 //! ibor fallback config
110 const IborFallbackConfig& iborfallbackConfig = IborFallbackConfig::defaultConfig(),
111 //! if true keep qloader quotes linked to yield ts, otherwise detach them
112 const bool preserveQuoteLinkage = false,
113 //! build calibration info
114 const bool buildCalibrationInfo = true,
115 //! market object to look up external discount curves
116 const Market* market = nullptr);
117
118 //! \name Inspectors
119 //@{
120 const Handle<YieldTermStructure>& handle() const { return h_; }
122 const Date& asofDate() const { return asofDate_; }
123 const Currency& currency() const { return currency_; }
124 // might be nullptr, if no info was produced for this curve
125 QuantLib::ext::shared_ptr<YieldCurveCalibrationInfo> calibrationInfo() const { return calibrationInfo_; }
126 //@}
127
128private:
130 Currency currency_;
132 DayCounter zeroDayCounter_;
134 QuantLib::ext::shared_ptr<YieldCurve> discountCurve_;
135
136 // TODO: const refs for now, only used during ctor
138 RelinkableHandle<YieldTermStructure> h_;
139 QuantLib::ext::shared_ptr<YieldTermStructure> p_;
140 QuantLib::ext::shared_ptr<YieldCurveCalibrationInfo> calibrationInfo_;
141
142 void buildDiscountCurve();
143 void buildZeroCurve();
146 //! Build a yield curve that uses QuantExt::DiscountRatioModifiedCurve
148 //! Build a yield curve that uses QuantLib::FittedBondCurve
150 //! Build a yield curve that uses QuantExt::WeightedYieldTermStructure
152 //! Build a yield curve that uses QuantExt::YieldPlusDefaultYieldTermStructure
154 //! Build a yield curve that uses QuantExt::IborFallbackCurve
156 //! Build a yield curve that uses QuantExt::bondYieldShiftedCurve
158
159 //! Return the yield curve with the given \p id from the requiredYieldCurves_ map
160 QuantLib::ext::shared_ptr<YieldCurve> getYieldCurve(const std::string& ccy, const std::string& id) const;
161
162 QuantLib::ext::shared_ptr<YieldCurveConfig> curveConfig_;
163 vector<QuantLib::ext::shared_ptr<YieldCurveSegment>> curveSegments_;
167 map<string, QuantLib::ext::shared_ptr<YieldCurve>> requiredYieldCurves_;
168 map<string, QuantLib::ext::shared_ptr<DefaultCurve>> requiredDefaultCurves_;
170 const QuantLib::ext::shared_ptr<ReferenceDataManager> referenceData_;
175
176 QuantLib::ext::shared_ptr<YieldTermStructure> piecewisecurve(vector<QuantLib::ext::shared_ptr<RateHelper>> instruments);
177
178 /* Functions to build RateHelpers from yield curve segments */
179 void addDeposits(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
180 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
181 void addFutures(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
182 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
183 void addFras(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
184 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
185 void addOISs(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
186 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
187 void addSwaps(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
188 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
189 void addAverageOISs(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
190 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
191 void addTenorBasisSwaps(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
192 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
193 void addTenorBasisTwoSwaps(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
194 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
195 void addBMABasisSwaps(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
196 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
197 void addFXForwards(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
198 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
199 void addCrossCcyBasisSwaps(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
200 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
201 void addCrossCcyFixFloatSwaps(const QuantLib::ext::shared_ptr<YieldCurveSegment>& segment,
202 vector<QuantLib::ext::shared_ptr<RateHelper>>& instruments);
203
204 // get the fx spot from the string provided
205 QuantLib::ext::shared_ptr<FXSpotQuote> getFxSpotQuote(string spotId);
206};
207
208//! Helper function for parsing interpolation method
210//! Helper function for parsing interpolation variable
212
213//! Output operator for interpolation method
214std::ostream& operator<<(std::ostream& out, const YieldCurve::InterpolationMethod m);
215
216//! Templated function to build a YieldTermStructure and apply interpolation methods to it
217template <template <class> class CurveType>
218QuantLib::ext::shared_ptr<YieldTermStructure> buildYieldCurve(const vector<Date>& dates, const vector<QuantLib::Real>& rates,
219 const DayCounter& dayCounter,
220 YieldCurve::InterpolationMethod interpolationMethod, Size n = 0);
221
222//! Create a Interpolated Zero Curve and apply interpolators
223QuantLib::ext::shared_ptr<YieldTermStructure> zerocurve(const vector<Date>& dates, const vector<Rate>& yields,
224 const DayCounter& dayCounter,
225 YieldCurve::InterpolationMethod interpolationMethod, Size n = 0);
226
227//! Create a Interpolated Discount Curve and apply interpolators
228QuantLib::ext::shared_ptr<YieldTermStructure> discountcurve(const vector<Date>& dates, const vector<DiscountFactor>& dfs,
229 const DayCounter& dayCounter,
230 YieldCurve::InterpolationMethod interpolationMethod, Size n = 0);
231
232//! Create a Interpolated Forward Curve and apply interpolators
233QuantLib::ext::shared_ptr<YieldTermStructure> forwardcurve(const vector<Date>& dates, const vector<Rate>& forwards,
234 const DayCounter& dayCounter,
235 YieldCurve::InterpolationMethod interpolationMethod, Size n = 0);
236
237} // namespace data
238} // namespace ore
Repository for currency dependent market conventions.
Container class for all Curve Configurations.
static IborFallbackConfig defaultConfig()
Market data loader base class.
Definition: loader.hpp:47
Yield Curve configuration.
Wrapper class for building yield term structures.
Definition: yieldcurve.hpp:61
QuantLib::ext::shared_ptr< YieldTermStructure > p_
Definition: yieldcurve.hpp:139
void addDeposits(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
QuantLib::ext::shared_ptr< YieldCurveCalibrationInfo > calibrationInfo() const
Definition: yieldcurve.hpp:125
void buildBondYieldShiftedCurve()
Build a yield curve that uses QuantExt::bondYieldShiftedCurve.
const bool preserveQuoteLinkage_
Definition: yieldcurve.hpp:172
void addCrossCcyBasisSwaps(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
void buildDiscountRatioCurve()
Build a yield curve that uses QuantExt::DiscountRatioModifiedCurve.
void addTenorBasisSwaps(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
DayCounter zeroDayCounter_
Definition: yieldcurve.hpp:132
void addOISs(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
void addFutures(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
map< string, QuantLib::ext::shared_ptr< DefaultCurve > > requiredDefaultCurves_
Definition: yieldcurve.hpp:168
InterpolationVariable
Supported interpolation variables.
Definition: yieldcurve.hpp:64
void addBMABasisSwaps(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
void addSwaps(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
const Currency & currency() const
Definition: yieldcurve.hpp:123
void buildYieldPlusDefaultCurve()
Build a yield curve that uses QuantExt::YieldPlusDefaultYieldTermStructure.
void buildFittedBondCurve()
Build a yield curve that uses QuantLib::FittedBondCurve.
const Date & asofDate() const
Definition: yieldcurve.hpp:122
RelinkableHandle< YieldTermStructure > h_
Definition: yieldcurve.hpp:138
const QuantLib::ext::shared_ptr< ReferenceDataManager > referenceData_
Definition: yieldcurve.hpp:170
const Market * market_
Definition: yieldcurve.hpp:174
void addFras(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
YieldCurveSpec curveSpec_
Definition: yieldcurve.hpp:131
QuantLib::ext::shared_ptr< YieldCurveConfig > curveConfig_
Definition: yieldcurve.hpp:162
const FXTriangulation & fxTriangulation_
Definition: yieldcurve.hpp:169
void buildIborFallbackCurve()
Build a yield curve that uses QuantExt::IborFallbackCurve.
const Handle< YieldTermStructure > & handle() const
Definition: yieldcurve.hpp:120
YieldCurveSpec curveSpec() const
Definition: yieldcurve.hpp:121
InterpolationMethod
Supported interpolation methods.
Definition: yieldcurve.hpp:67
void addTenorBasisTwoSwaps(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
void addFXForwards(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
const Loader & loader_
Definition: yieldcurve.hpp:137
InterpolationVariable interpolationVariable_
Definition: yieldcurve.hpp:164
map< string, QuantLib::ext::shared_ptr< YieldCurve > > requiredYieldCurves_
Definition: yieldcurve.hpp:167
InterpolationMethod interpolationMethod_
Definition: yieldcurve.hpp:165
IborFallbackConfig iborFallbackConfig_
Definition: yieldcurve.hpp:171
QuantLib::ext::shared_ptr< YieldCurveCalibrationInfo > calibrationInfo_
Definition: yieldcurve.hpp:140
vector< QuantLib::ext::shared_ptr< YieldCurveSegment > > curveSegments_
Definition: yieldcurve.hpp:163
void addCrossCcyFixFloatSwaps(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
void buildWeightedAverageCurve()
Build a yield curve that uses QuantExt::WeightedYieldTermStructure.
QuantLib::ext::shared_ptr< FXSpotQuote > getFxSpotQuote(string spotId)
QuantLib::ext::shared_ptr< YieldTermStructure > piecewisecurve(vector< QuantLib::ext::shared_ptr< RateHelper > > instruments)
Definition: yieldcurve.cpp:390
QuantLib::ext::shared_ptr< YieldCurve > discountCurve_
Definition: yieldcurve.hpp:134
QuantLib::ext::shared_ptr< YieldCurve > getYieldCurve(const std::string &ccy, const std::string &id) const
Return the yield curve with the given id from the requiredYieldCurves_ map.
void addAverageOISs(const QuantLib::ext::shared_ptr< YieldCurveSegment > &segment, vector< QuantLib::ext::shared_ptr< RateHelper > > &instruments)
Base class for yield curve segments.
Yield curve description.
Definition: curvespec.hpp:108
Currency and instrument specific conventions/defaults.
Curve configuration repository.
Curve requirements specification.
Intelligent FX price repository.
ibor fallback configuration
Market Datum Loader Interface.
@ data
Definition: log.hpp:77
Base Market class.
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
QuantLib::ext::shared_ptr< YieldTermStructure > buildYieldCurve(const vector< Date > &dates, const vector< QuantLib::Real > &rates, const DayCounter &dayCounter, YieldCurve::InterpolationMethod interpolationMethod, Size n)
Templated function to build a YieldTermStructure and apply interpolation methods to it.
Definition: yieldcurve.cpp:92
YieldCurve::InterpolationVariable parseYieldCurveInterpolationVariable(const string &s)
Helper function for parsing interpolation variable.
Definition: yieldcurve.cpp:223
QuantLib::ext::shared_ptr< YieldTermStructure > discountcurve(const vector< Date > &dates, const vector< DiscountFactor > &dfs, const DayCounter &dayCounter, YieldCurve::InterpolationMethod interpolationMethod, Size n)
Create a Interpolated Discount Curve and apply interpolators.
Definition: yieldcurve.cpp:166
YieldCurve::InterpolationMethod parseYieldCurveInterpolationMethod(const string &s)
Helper function for parsing interpolation method.
Definition: yieldcurve.cpp:180
std::map< string, QuantLib::ext::shared_ptr< YieldCurveConfig > > YieldCurveConfigMap
QuantLib::ext::shared_ptr< YieldTermStructure > forwardcurve(const vector< Date > &dates, const vector< Rate > &forwards, const DayCounter &dayCounter, YieldCurve::InterpolationMethod interpolationMethod, Size n)
Create a Interpolated Forward Curve and apply interpolators.
Definition: yieldcurve.cpp:172
QuantLib::ext::shared_ptr< YieldTermStructure > zerocurve(const vector< Date > &dates, const vector< Rate > &yields, const DayCounter &dayCounter, YieldCurve::InterpolationMethod interpolationMethod, Size n)
Create a Interpolated Zero Curve and apply interpolators.
Definition: yieldcurve.cpp:160
Serializable Credit Default Swap.
Definition: namespaces.docs:23
vector< string > curveConfigs
a container holding information on calibration results during the t0 market build
Wrapper class for QuantLib term structures.
Yield curve configuration classes.