Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityvolcurve.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 ored/marketdata/commodityvolcurve.hpp
20 \brief Wrapper class for building commodity volatility structures
21 \ingroup curves
22*/
23
24#pragma once
25
33#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
35
36namespace ore {
37namespace data {
38
39//! Wrapper class for building commodity volatility structures
40/*! \ingroup curves
41 */
43public:
44 //! \name Constructors
45 //@{
46 //! Default constructor
48
49 //! Detailed constructor
50 CommodityVolCurve(const QuantLib::Date& asof, const CommodityVolatilityCurveSpec& spec, const Loader& loader,
52 const std::map<std::string, QuantLib::ext::shared_ptr<YieldCurve>>& yieldCurves = {},
53 const std::map<std::string, QuantLib::ext::shared_ptr<CommodityCurve>>& commodityCurves = {},
54 const std::map<std::string, QuantLib::ext::shared_ptr<CommodityVolCurve>>& commodityVolCurves = {},
55 const map<string, QuantLib::ext::shared_ptr<FXVolCurve>>& fxVolCurves = {},
56 const map<string, QuantLib::ext::shared_ptr<CorrelationCurve>>& correlationCurves = {},
57 const Market* fxIndices = nullptr, const bool buildCalibrationInfo = true);
58 //@}
59
60 //! \name Inspectors
61 //@{
62 const CommodityVolatilityCurveSpec& spec() const { return spec_; }
63 const QuantLib::ext::shared_ptr<QuantLib::BlackVolTermStructure>& volatility() { return volatility_; }
64
65 //! Build the calibration info
66 void buildVolCalibrationInfo(const Date& asof, QuantLib::ext::shared_ptr<VolatilityConfig>& volatilityConfig,
68 const QuantLib::ext::shared_ptr<FxEqCommVolCalibrationInfo>& calibrationInfo() const { return calibrationInfo_; }
69 //@}
70
71private:
73 QuantLib::ext::shared_ptr<QuantLib::BlackVolTermStructure> volatility_;
74 QuantLib::ext::shared_ptr<QuantExt::FutureExpiryCalculator> expCalc_;
75 QuantLib::ext::shared_ptr<CommodityFutureConvention> convention_;
77 QuantLib::DayCounter dayCounter_;
78 QuantLib::ext::shared_ptr<FxEqCommVolCalibrationInfo> calibrationInfo_;
79 QuantLib::Date maxExpiry_;
80
81 // Populated for delta, moneyness and possibly absolute strike surfaces and left empty for others
82 QuantLib::Handle<QuantExt::PriceTermStructure> pts_;
83 QuantLib::Handle<QuantLib::YieldTermStructure> yts_;
84
85 //! Build a volatility structure from a single constant volatility quote
86 void buildVolatility(const QuantLib::Date& asof, const CommodityVolatilityConfig& vc,
87 const ConstantVolatilityConfig& cvc, const Loader& loader);
88
89 //! Build a volatility curve from a 1-D curve of volatility quotes
90 void buildVolatility(const QuantLib::Date& asof, const CommodityVolatilityConfig& vc,
91 const VolatilityCurveConfig& vcc, const Loader& loader);
92
93 //! Build a volatility surface from a collection of expiry and absolute strike pairs.
94 void buildVolatility(const QuantLib::Date& asof, CommodityVolatilityConfig& vc,
95 const VolatilityStrikeSurfaceConfig& vssc, const Loader& loader);
96
97 /*! Build a volatility surface from a collection of expiry and absolute strike pairs where the strikes and
98 expiries are both explicitly configured i.e. where wild cards are not used for either the strikes or
99 the expiries.
100 */
101 void buildVolatilityExplicit(const QuantLib::Date& asof, CommodityVolatilityConfig& vc,
102 const VolatilityStrikeSurfaceConfig& vssc, const Loader& loader,
103 const std::vector<QuantLib::Real>& configuredStrikes);
104
105 /*! Build a volatility surface from a collection of expiry and strike pairs where the strikes are defined in
106 terms of option delta and ATM values.
107 */
108 void buildVolatility(const QuantLib::Date& asof, CommodityVolatilityConfig& vc,
109 const VolatilityDeltaSurfaceConfig& vdsc, const Loader& loader);
110
111 /*! Build a volatility surface from a collection of expiry and strike pairs where the strikes are defined in
112 terms of moneyness levels.
113 */
114 void buildVolatility(const QuantLib::Date& asof, CommodityVolatilityConfig& vc,
115 const VolatilityMoneynessSurfaceConfig& vmsc, const Loader& loader);
116
117 /*! Build a future price APO surface using a given price term structure. Use the natural expiries of the future
118 options as the expiry pillar points and use configured moneyness levels in the strike dimension.
119 */
120 void buildVolatility(const QuantLib::Date& asof, CommodityVolatilityConfig& vc,
122 const QuantLib::Handle<QuantLib::BlackVolTermStructure>& baseVts,
123 const QuantLib::Handle<QuantExt::PriceTermStructure>& basePts);
124
125 //! Build a volatility surface as a proxy from another volatility surface
126 void buildVolatility(const QuantLib::Date& asof, const CommodityVolatilityCurveSpec& spec,
128 const map<string, QuantLib::ext::shared_ptr<CommodityCurve>>& comCurves,
129 const map<string, QuantLib::ext::shared_ptr<CommodityVolCurve>>& volCurves,
130 const map<string, QuantLib::ext::shared_ptr<FXVolCurve>>& fxVolCurves,
131 const map<string, QuantLib::ext::shared_ptr<CorrelationCurve>>& correlationCurves,
132 const Market* fxIndices = nullptr);
133
134 /*! Assume that the input price curve \p pts is a future price curve giving the price of a sequence of future
135 contracts at the contract expiry. Create a copy of this input curve with additional pillar points at
136 the future option contract expiries. The price returned when this curve is queried at the option contract
137 expiry or the future contract expiry is the expected future contract price i.e. the quoted future price. We
138 need this to allow option surface creation with our current infrastructure for options on futures in
139 particular where the surface creation relies on knowing the "forward" price.
140 */
141 QuantLib::Handle<QuantExt::PriceTermStructure>
142 correctFuturePriceCurve(const QuantLib::Date& asof, const std::string& contractName,
143 const QuantLib::ext::shared_ptr<QuantExt::PriceTermStructure>& pts,
144 const std::vector<QuantLib::Date>& optionExpiries) const;
145
146 //! Get an explicit expiry date from a commodity option quote's Expiry
147 QuantLib::Date getExpiry(const QuantLib::Date& asof, const QuantLib::ext::shared_ptr<Expiry>& expiry,
148 const std::string& name, QuantLib::Natural rollDays) const;
149
150 //! Populate price curve, \p pts_, and yield curve, \p yts_.
151 void populateCurves(const CommodityVolatilityConfig& config,
152 const std::map<std::string, QuantLib::ext::shared_ptr<YieldCurve>>& yieldCurves,
153 const std::map<std::string, QuantLib::ext::shared_ptr<CommodityCurve>>& commodityCurves,
154 bool searchYield, bool dontThrow = false);
155
156 //! Check and return moneyness levels.
157 std::vector<QuantLib::Real> checkMoneyness(const std::vector<std::string>& moneynessLevels) const;
158};
159
160} // namespace data
161} // namespace ore
Wrapper class for building commodity volatility structures.
void buildVolatility(const QuantLib::Date &asof, const CommodityVolatilityConfig &vc, const ConstantVolatilityConfig &cvc, const Loader &loader)
Build a volatility structure from a single constant volatility quote.
QuantLib::Date getExpiry(const QuantLib::Date &asof, const QuantLib::ext::shared_ptr< Expiry > &expiry, const std::string &name, QuantLib::Natural rollDays) const
Get an explicit expiry date from a commodity option quote's Expiry.
QuantLib::ext::shared_ptr< QuantExt::FutureExpiryCalculator > expCalc_
const QuantLib::ext::shared_ptr< FxEqCommVolCalibrationInfo > & calibrationInfo() const
void buildVolatility(const QuantLib::Date &asof, CommodityVolatilityConfig &vc, const VolatilityMoneynessSurfaceConfig &vmsc, const Loader &loader)
const QuantLib::ext::shared_ptr< QuantLib::BlackVolTermStructure > & volatility()
QuantLib::Handle< QuantExt::PriceTermStructure > pts_
CommodityVolatilityCurveSpec spec_
QuantLib::ext::shared_ptr< CommodityFutureConvention > convention_
QuantLib::ext::shared_ptr< QuantLib::BlackVolTermStructure > volatility_
QuantLib::ext::shared_ptr< FxEqCommVolCalibrationInfo > calibrationInfo_
void buildVolatility(const QuantLib::Date &asof, CommodityVolatilityConfig &vc, const VolatilityApoFutureSurfaceConfig &vapo, const QuantLib::Handle< QuantLib::BlackVolTermStructure > &baseVts, const QuantLib::Handle< QuantExt::PriceTermStructure > &basePts)
void buildVolCalibrationInfo(const Date &asof, QuantLib::ext::shared_ptr< VolatilityConfig > &volatilityConfig, const CurveConfigurations &curveConfigs, const CommodityVolatilityConfig &config)
Build the calibration info.
QuantLib::Handle< QuantExt::PriceTermStructure > correctFuturePriceCurve(const QuantLib::Date &asof, const std::string &contractName, const QuantLib::ext::shared_ptr< QuantExt::PriceTermStructure > &pts, const std::vector< QuantLib::Date > &optionExpiries) const
void populateCurves(const CommodityVolatilityConfig &config, const std::map< std::string, QuantLib::ext::shared_ptr< YieldCurve > > &yieldCurves, const std::map< std::string, QuantLib::ext::shared_ptr< CommodityCurve > > &commodityCurves, bool searchYield, bool dontThrow=false)
Populate price curve, pts_, and yield curve, yts_.
const CommodityVolatilityCurveSpec & spec() const
void buildVolatility(const QuantLib::Date &asof, CommodityVolatilityConfig &vc, const VolatilityDeltaSurfaceConfig &vdsc, const Loader &loader)
void buildVolatility(const QuantLib::Date &asof, CommodityVolatilityConfig &vc, const VolatilityStrikeSurfaceConfig &vssc, const Loader &loader)
Build a volatility surface from a collection of expiry and absolute strike pairs.
CommodityVolCurve()
Default constructor.
CommodityVolCurve(const QuantLib::Date &asof, const CommodityVolatilityCurveSpec &spec, const Loader &loader, const CurveConfigurations &curveConfigs, const std::map< std::string, QuantLib::ext::shared_ptr< YieldCurve > > &yieldCurves={}, const std::map< std::string, QuantLib::ext::shared_ptr< CommodityCurve > > &commodityCurves={}, const std::map< std::string, QuantLib::ext::shared_ptr< CommodityVolCurve > > &commodityVolCurves={}, const map< string, QuantLib::ext::shared_ptr< FXVolCurve > > &fxVolCurves={}, const map< string, QuantLib::ext::shared_ptr< CorrelationCurve > > &correlationCurves={}, const Market *fxIndices=nullptr, const bool buildCalibrationInfo=true)
Detailed constructor.
QuantLib::Handle< QuantLib::YieldTermStructure > yts_
std::vector< QuantLib::Real > checkMoneyness(const std::vector< std::string > &moneynessLevels) const
Check and return moneyness levels.
void buildVolatilityExplicit(const QuantLib::Date &asof, CommodityVolatilityConfig &vc, const VolatilityStrikeSurfaceConfig &vssc, const Loader &loader, const std::vector< QuantLib::Real > &configuredStrikes)
QuantLib::DayCounter dayCounter_
Commodity volatility configuration.
Commodity volatility description.
Definition: curvespec.hpp:440
Container class for all Curve Configurations.
Market data loader base class.
Definition: loader.hpp:47
Class for building a commodity price curve.
Currency and instrument specific conventions/defaults.
Curve configuration repository.
Curve requirements specification.
Wrapper class for building FX volatility structures.
Market Datum Loader Interface.
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
vector< string > curveConfigs
string name
Wrapper class for QuantLib term structures.