Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commoditycurve.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 Quaternion Risk Management Ltd
3 Copyright (C) 2021 Skandinaviska Enskilda Banken AB (publ)
4 All rights reserved.
5
6 This file is part of ORE, a free-software/open-source library
7 for transparent pricing and risk analysis - http://opensourcerisk.org
8
9 ORE is free software: you can redistribute it and/or modify it
10 under the terms of the Modified BSD License. You should have received a
11 copy of the license along with this program.
12 The license is also available online at <http://opensourcerisk.org>
13
14 This program is distributed on the basis that it will form a useful
15 contribution to risk analytics and model standardisation, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20/*! \file ored/marketdata/commoditycurve.hpp
21 \brief Class for building a commodity price curve
22 \ingroup curves
23*/
24
25#pragma once
26
34#include <ql/math/interpolations/backwardflatinterpolation.hpp>
35#include <ql/math/interpolations/linearinterpolation.hpp>
36#include <ql/math/interpolations/loginterpolation.hpp>
39
40namespace ore {
41namespace data {
42
44public:
45 //! \name Constructors
46 //@{
47 //! Default constructor
49
50 //! Detailed constructor
51 CommodityCurve(const QuantLib::Date& asof, const CommodityCurveSpec& spec, const Loader& loader,
53 const FXTriangulation& fxSpots = FXTriangulation(),
54 const std::map<std::string, QuantLib::ext::shared_ptr<YieldCurve>>& yieldCurves = {},
55 const std::map<std::string, QuantLib::ext::shared_ptr<CommodityCurve>>& commodityCurves = {},
56 bool const buildCalibrationInfo = false);
57 //@}
58
59 //! \name Inspectors
60 //@{
61 const CommodityCurveSpec& spec() const { return spec_; }
62 QuantLib::ext::shared_ptr<QuantExt::PriceTermStructure> commodityPriceCurve() const { return commodityPriceCurve_; }
63 QuantLib::ext::shared_ptr<QuantExt::CommodityIndex> commodityIndex() const { return commodityIndex_; }
64 QuantLib::ext::shared_ptr<CommodityCurveCalibrationInfo> calibrationInfo() const { return calibrationInfo_; }
65 //@}
66
67private:
69 QuantLib::ext::shared_ptr<QuantExt::PriceTermStructure> commodityPriceCurve_;
70 QuantLib::ext::shared_ptr<QuantExt::CommodityIndex> commodityIndex_;
71 QuantLib::ext::shared_ptr<CommodityCurveCalibrationInfo> calibrationInfo_;
72
73 //! Store the commodity spot value with \c Null<Real>() indicating that none has been provided.
74 QuantLib::Real commoditySpot_;
75
76 //! Store the overnight value if any
77 QuantLib::Real onValue_;
78
79 //! Store the tomorrow next value if any
80 QuantLib::Real tnValue_;
81
82 //! Populated with \c true if the quotes are configured via a wildcard
84
85 //! Store the interpolation method.
87
88 //! Store the curve's day counter.
89 QuantLib::DayCounter dayCounter_;
90
91 //! Populate \p data with dates and prices from the loader
92 void populateData(std::map<QuantLib::Date, QuantLib::Handle<QuantLib::Quote>>& data, const QuantLib::Date& asof,
93 const QuantLib::ext::shared_ptr<CommodityCurveConfig>& config, const Loader& loader);
94
95 //! Add node to price curve \p data with check for duplicate expiry dates
96 void add(const QuantLib::Date& asof, const QuantLib::Date& expiry, QuantLib::Real value,
97 std::map<QuantLib::Date, QuantLib::Handle<QuantLib::Quote>>& data, bool outright, QuantLib::Real pointsFactor = 1.0);
98
99 //! Build price curve using the curve \p data
100 void buildCurve(const QuantLib::Date& asof, const std::map<QuantLib::Date, QuantLib::Handle<QuantLib::Quote>>& data,
101 const QuantLib::ext::shared_ptr<CommodityCurveConfig>& config);
102
103 //! Build cross currency commodity price curve
104 void buildCrossCurrencyPriceCurve(const QuantLib::Date& asof, const QuantLib::ext::shared_ptr<CommodityCurveConfig>& config,
105 const QuantLib::ext::shared_ptr<CommodityCurveConfig>& baseConfig,
106 const FXTriangulation& fxSpots,
107 const std::map<std::string, QuantLib::ext::shared_ptr<YieldCurve>>& yieldCurves,
108 const std::map<std::string, QuantLib::ext::shared_ptr<CommodityCurve>>& commodityCurves);
109
110 //! Build commodity basis price curve
111 void buildBasisPriceCurve(const QuantLib::Date& asof, const CommodityCurveConfig& config,
112 const QuantLib::Handle<QuantExt::PriceTermStructure>& basePts, const Loader& loader);
113
114 //! Build commodity piecewise price curve
115 void buildPiecewiseCurve(const QuantLib::Date& asof, const CommodityCurveConfig& config,
116 const Loader& loader,
117 const std::map<std::string, QuantLib::ext::shared_ptr<CommodityCurve>>& commodityCurves);
118
119 //! Get the configured quotes. If filter is \c true, remove tenor based quotes and quotes with expiry before asof.
120 std::vector<QuantLib::ext::shared_ptr<CommodityForwardQuote>>
121 getQuotes(const QuantLib::Date& asof, const std::string& /*configId*/, const std::vector<std::string>& quotes,
122 const Loader& loader, bool filter = false);
123
124 //! Method for populating the price curve
125 template <template <class> class CurveType, typename... Args> void populateCurve(Args... args);
126
127 //! Add the instruments relating to a \p priceSegment to \p instruments.
128 using Helper = QuantLib::BootstrapHelper<QuantExt::PriceTermStructure>;
129 void addInstruments(const QuantLib::Date& asof, const Loader& loader, const std::string& configId,
130 const std::string& currency, const PriceSegment& priceSegment,
131 const std::map<std::string, QuantLib::ext::shared_ptr<CommodityCurve>>& commodityCurves,
132 std::map<QuantLib::Date, QuantLib::ext::shared_ptr<Helper>>& instruments);
133
134 //! Special method to add instruments when the \p priceSegment is \c OffPeakPowerDaily
135 void addOffPeakPowerInstruments(const QuantLib::Date& asof, const Loader& loader, const std::string& configId,
136 const PriceSegment& priceSegment,
137 std::map<QuantLib::Date, QuantLib::ext::shared_ptr<Helper>>& instruments);
138};
139
140template <template <class> class CurveType, typename... Args> void CommodityCurve::populateCurve(Args... args) {
141
142 if (interpolationMethod_ == "Linear") {
143 commodityPriceCurve_ = QuantLib::ext::make_shared<CurveType<QuantLib::Linear>>(args...);
144 } else if (interpolationMethod_ == "LogLinear") {
145 commodityPriceCurve_ = QuantLib::ext::make_shared<CurveType<QuantLib::LogLinear>>(args...);
146 } else if (interpolationMethod_ == "Cubic") {
147 commodityPriceCurve_ = QuantLib::ext::make_shared<CurveType<QuantLib::Cubic>>(args...);
148 } else if (interpolationMethod_ == "Hermite") {
149 commodityPriceCurve_ = QuantLib::ext::make_shared<CurveType<QuantLib::Cubic>>(
150 args..., QuantLib::Cubic(QuantLib::CubicInterpolation::Parabolic));
151 } else if (interpolationMethod_ == "LinearFlat") {
152 commodityPriceCurve_ = QuantLib::ext::make_shared<CurveType<QuantExt::LinearFlat>>(args...);
153 } else if (interpolationMethod_ == "LogLinearFlat") {
154 commodityPriceCurve_ = QuantLib::ext::make_shared<CurveType<QuantExt::LogLinearFlat>>(args...);
155 } else if (interpolationMethod_ == "CubicFlat") {
156 commodityPriceCurve_ = QuantLib::ext::make_shared<CurveType<QuantExt::CubicFlat>>(args...);
157 } else if (interpolationMethod_ == "HermiteFlat") {
158 commodityPriceCurve_ = QuantLib::ext::make_shared<CurveType<QuantExt::HermiteFlat>>(args...);
159 } else if (interpolationMethod_ == "BackwardFlat") {
160 commodityPriceCurve_ = QuantLib::ext::make_shared<CurveType<QuantLib::BackwardFlat>>(args...);
161 } else {
162 QL_FAIL("The interpolation method, " << interpolationMethod_ << ", is not supported.");
163 }
164}
165
166} // namespace data
167} // namespace ore
Commodity curve configuration.
std::string interpolationMethod_
Store the interpolation method.
const CommodityCurveSpec & spec() const
QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > commodityIndex_
QuantLib::ext::shared_ptr< QuantExt::PriceTermStructure > commodityPriceCurve_
QuantLib::ext::shared_ptr< CommodityCurveCalibrationInfo > calibrationInfo_
QuantLib::ext::shared_ptr< QuantExt::PriceTermStructure > commodityPriceCurve() const
QuantLib::Real onValue_
Store the overnight value if any.
QuantLib::BootstrapHelper< QuantExt::PriceTermStructure > Helper
Add the instruments relating to a priceSegment to instruments.
void buildCurve(const QuantLib::Date &asof, const std::map< QuantLib::Date, QuantLib::Handle< QuantLib::Quote > > &data, const QuantLib::ext::shared_ptr< CommodityCurveConfig > &config)
Build price curve using the curve data.
CommodityCurve()
Default constructor.
QuantLib::ext::shared_ptr< CommodityCurveCalibrationInfo > calibrationInfo() const
CommodityCurve(const QuantLib::Date &asof, const CommodityCurveSpec &spec, const Loader &loader, const CurveConfigurations &curveConfigs, const FXTriangulation &fxSpots=FXTriangulation(), const std::map< std::string, QuantLib::ext::shared_ptr< YieldCurve > > &yieldCurves={}, const std::map< std::string, QuantLib::ext::shared_ptr< CommodityCurve > > &commodityCurves={}, bool const buildCalibrationInfo=false)
Detailed constructor.
QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > commodityIndex() const
void buildPiecewiseCurve(const QuantLib::Date &asof, const CommodityCurveConfig &config, const Loader &loader, const std::map< std::string, QuantLib::ext::shared_ptr< CommodityCurve > > &commodityCurves)
Build commodity piecewise price curve.
void buildCrossCurrencyPriceCurve(const QuantLib::Date &asof, const QuantLib::ext::shared_ptr< CommodityCurveConfig > &config, const QuantLib::ext::shared_ptr< CommodityCurveConfig > &baseConfig, const FXTriangulation &fxSpots, const std::map< std::string, QuantLib::ext::shared_ptr< YieldCurve > > &yieldCurves, const std::map< std::string, QuantLib::ext::shared_ptr< CommodityCurve > > &commodityCurves)
Build cross currency commodity price curve.
std::vector< QuantLib::ext::shared_ptr< CommodityForwardQuote > > getQuotes(const QuantLib::Date &asof, const std::string &, const std::vector< std::string > &quotes, const Loader &loader, bool filter=false)
Get the configured quotes. If filter is true, remove tenor based quotes and quotes with expiry before...
void add(const QuantLib::Date &asof, const QuantLib::Date &expiry, QuantLib::Real value, std::map< QuantLib::Date, QuantLib::Handle< QuantLib::Quote > > &data, bool outright, QuantLib::Real pointsFactor=1.0)
Add node to price curve data with check for duplicate expiry dates.
QuantLib::Real tnValue_
Store the tomorrow next value if any.
bool regexQuotes_
Populated with true if the quotes are configured via a wildcard.
CommodityCurveSpec spec_
QuantLib::DayCounter dayCounter_
Store the curve's day counter.
void addOffPeakPowerInstruments(const QuantLib::Date &asof, const Loader &loader, const std::string &configId, const PriceSegment &priceSegment, std::map< QuantLib::Date, QuantLib::ext::shared_ptr< Helper > > &instruments)
Special method to add instruments when the priceSegment is OffPeakPowerDaily.
void populateCurve(Args... args)
Method for populating the price curve.
void populateData(std::map< QuantLib::Date, QuantLib::Handle< QuantLib::Quote > > &data, const QuantLib::Date &asof, const QuantLib::ext::shared_ptr< CommodityCurveConfig > &config, const Loader &loader)
Populate data with dates and prices from the loader.
QuantLib::Real commoditySpot_
Store the commodity spot value with Null<Real>() indicating that none has been provided.
void buildBasisPriceCurve(const QuantLib::Date &asof, const CommodityCurveConfig &config, const QuantLib::Handle< QuantExt::PriceTermStructure > &basePts, const Loader &loader)
Build commodity basis price curve.
void addInstruments(const QuantLib::Date &asof, const Loader &loader, const std::string &configId, const std::string &currency, const PriceSegment &priceSegment, const std::map< std::string, QuantLib::ext::shared_ptr< CommodityCurve > > &commodityCurves, std::map< QuantLib::Date, QuantLib::ext::shared_ptr< Helper > > &instruments)
Commodity curve description.
Definition: curvespec.hpp:413
Container class for all Curve Configurations.
Market data loader base class.
Definition: loader.hpp:47
SafeStack< ValueType > value
SafeStack< Filter > filter
Currency and instrument specific conventions/defaults.
Curve configuration repository.
Curve requirements specification.
Intelligent FX price repository.
Market Datum Loader Interface.
@ data
Definition: log.hpp:77
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.