Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
VarSwapEngineBuilder Class Reference

Engine Builder for Variance Swaps. More...

#include <ored/portfolio/builders/varianceswap.hpp>

+ Inheritance diagram for VarSwapEngineBuilder:
+ Collaboration diagram for VarSwapEngineBuilder:

Public Member Functions

 VarSwapEngineBuilder ()
 
- Public Member Functions inherited from CachingEngineBuilder< T, U, Args >
 CachingEngineBuilder (const string &model, const string &engine, const set< string > &tradeTypes)
 
QuantLib::ext::shared_ptr< U > engine (Args... params)
 Return a PricingEngine or a FloatingRateCouponPricer. More...
 
void reset () override
 reset the builder (e.g. clear cache) More...
 
- Public Member Functions inherited from EngineBuilder
 EngineBuilder (const string &model, const string &engine, const set< string > &tradeTypes)
 
virtual ~EngineBuilder ()
 Virtual destructor. More...
 
const string & model () const
 Return the model name. More...
 
const string & engine () const
 Return the engine name. More...
 
const set< string > & tradeTypes () const
 Return the possible trade types. More...
 
const string & configuration (const MarketContext &key)
 Return a configuration (or the default one if key not found) More...
 
virtual void reset ()
 reset the builder (e.g. clear cache) More...
 
void init (const QuantLib::ext::shared_ptr< Market > market, const map< MarketContext, string > &configurations, const map< string, string > &modelParameters, const map< string, string > &engineParameters, const std::map< std::string, std::string > &globalParameters={})
 Initialise this Builder with the market and parameters to use. More...
 
const set< std::pair< string, QuantLib::ext::shared_ptr< QuantExt::ModelBuilder > > > & modelBuilders () const
 return model builders More...
 
std::string engineParameter (const std::string &p, const std::vector< std::string > &qualifiers={}, const bool mandatory=true, const std::string &defaultValue="") const
 
std::string modelParameter (const std::string &p, const std::vector< std::string > &qualifiers={}, const bool mandatory=true, const std::string &defaultValue="") const
 

Protected Member Functions

virtual string keyImpl (const string &underlyingName, const Currency &ccy, const AssetClass &assetClassUnderlying, const MomentType &momentType) override
 
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl (const string &underlyingName, const Currency &ccy, const AssetClass &assetClassUnderlying, const MomentType &momentType) override
 
- Protected Member Functions inherited from CachingEngineBuilder< T, U, Args >
virtual T keyImpl (Args...)=0
 
virtual QuantLib::ext::shared_ptr< U > engineImpl (Args...)=0
 

Additional Inherited Members

- Protected Attributes inherited from CachingEngineBuilder< T, U, Args >
map< T, QuantLib::ext::shared_ptr< U > > engines_
 
- Protected Attributes inherited from EngineBuilder
string model_
 
string engine_
 
set< string > tradeTypes_
 
QuantLib::ext::shared_ptr< Marketmarket_
 
map< MarketContext, string > configurations_
 
map< string, string > modelParameters_
 
map< string, string > engineParameters_
 
std::map< std::string, std::string > globalParameters_
 
set< std::pair< string, QuantLib::ext::shared_ptr< QuantExt::ModelBuilder > > > modelBuilders_
 

Detailed Description

Engine Builder for Variance Swaps.

Pricing engines are cached by equity/currency

Definition at line 53 of file varianceswap.hpp.

Constructor & Destructor Documentation

◆ VarSwapEngineBuilder()

Definition at line 56 of file varianceswap.hpp.

57 : CachingEngineBuilder("BlackScholesMerton", "ReplicatingVarianceSwapEngine",
58 {"EquityVarianceSwap", "FxVarianceSwap", "CommodityVarianceSwap"}) {}
CachingEngineBuilder(const string &model, const string &engine, const set< string > &tradeTypes)

Member Function Documentation

◆ keyImpl()

virtual string keyImpl ( const string &  underlyingName,
const Currency &  ccy,
const AssetClass assetClassUnderlying,
const MomentType momentType 
)
overrideprotectedvirtual

Definition at line 61 of file varianceswap.hpp.

62 {
63 return underlyingName + "/" + ccy.code() + "/" +
64 (momentType == MomentType::Variance ? "Variance" : "Volatility");
65 }

◆ engineImpl()

virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl ( const string &  underlyingName,
const Currency &  ccy,
const AssetClass assetClassUnderlying,
const MomentType momentType 
)
overrideprotectedvirtual

Definition at line 67 of file varianceswap.hpp.

69 {
70 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp;
71 QuantLib::ext::shared_ptr<Index> index;
72 if (assetClassUnderlying == AssetClass::EQ) {
73 gbsp = QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(
74 market_->equitySpot(underlyingName, configuration(ore::data::MarketContext::pricing)),
75 market_->equityDividendCurve(underlyingName, configuration(ore::data::MarketContext::pricing)),
76 market_->equityForecastCurve(underlyingName, configuration(ore::data::MarketContext::pricing)),
77 market_->equityVol(underlyingName, configuration(ore::data::MarketContext::pricing)));
78 index = market_->equityCurve(underlyingName).currentLink();
79 } else if (assetClassUnderlying == AssetClass::FX) {
80 const auto fxIndex = parseFxIndex("FX-" + underlyingName);
81 const string& sourceCurrencyCode = fxIndex->sourceCurrency().code();
82 const string& targetCurrencyCode = fxIndex->targetCurrency().code();
83 const string& ccyPairCode = sourceCurrencyCode + targetCurrencyCode;
84 gbsp = QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(
86 market_->discountCurve(targetCurrencyCode, configuration(ore::data::MarketContext::pricing)),
87 market_->discountCurve(sourceCurrencyCode, configuration(ore::data::MarketContext::pricing)),
89
90 index = buildFxIndex("FX-" + underlyingName, targetCurrencyCode, sourceCurrencyCode, market_,
92 } else if (assetClassUnderlying == AssetClass::COM) {
93 Handle<BlackVolTermStructure> vol = market_->commodityVolatility(underlyingName, configuration(ore::data::MarketContext::pricing));
94 Handle<QuantExt::PriceTermStructure> priceCurve = market_->commodityPriceCurve(underlyingName, configuration(ore::data::MarketContext::pricing));
95 Handle<Quote> commoditySpot(QuantLib::ext::make_shared<QuantExt::DerivedPriceQuote>(priceCurve));
96 Handle<YieldTermStructure> discount = market_->discountCurve(ccy.code(), configuration(ore::data::MarketContext::pricing));
97 Handle<YieldTermStructure> yield(QuantLib::ext::make_shared<QuantExt::PriceTermStructureAdapter>(*priceCurve, *discount));
98 yield->enableExtrapolation();
99 gbsp = QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(commoditySpot, yield, discount, vol);
100 index = market_->commodityIndex(underlyingName).currentLink();
101 } else {
102 QL_FAIL("Asset class of " + underlyingName + " not recognized.");
103 }
104
106
107 std::string schemeStr = engineParameter("Scheme", {}, false, "GaussLobatto");
108 std::string boundsStr = engineParameter("Bounds", {}, false, "PriceThreshold");
109
110 if (schemeStr == "GaussLobatto")
111 settings.scheme = QuantExt::GeneralisedReplicatingVarianceSwapEngine::VarSwapSettings::Scheme::GaussLobatto;
112 else if (schemeStr == "Segment")
113 settings.scheme = QuantExt::GeneralisedReplicatingVarianceSwapEngine::VarSwapSettings::Scheme::Segment;
114 else {
115 QL_FAIL("invalid var swap pricing engine parameter Scheme (" << schemeStr
116 << "), expected GaussLobatto, Segment");
117 }
118
119 if (boundsStr == "Fixed")
120 settings.bounds = QuantExt::GeneralisedReplicatingVarianceSwapEngine::VarSwapSettings::Bounds::Fixed;
121 else if (boundsStr == "PriceThreshold")
122 settings.bounds = QuantExt::GeneralisedReplicatingVarianceSwapEngine::VarSwapSettings::Bounds::PriceThreshold;
123 else {
124 QL_FAIL("invalid var swap pricing engine parameter Bounds (" << boundsStr
125 << "), expected Fixed, PriceThreshold");
126 }
127
128 settings.accuracy = parseReal(engineParameter("Accuracy", {}, false, "1E-5"));
129 settings.maxIterations = parseInteger(engineParameter("MaxIterations", {}, false, "1000"));
130 settings.steps = parseInteger(engineParameter("Steps", {}, false, "100"));
131 settings.priceThreshold = parseReal(engineParameter("PriceThreshold", {}, false, "1E-10"));
132 settings.maxPriceThresholdSteps = parseInteger(engineParameter("MaxPriceThresholdSteps", {}, false, "100"));
133 settings.priceThresholdStep = parseReal(engineParameter("PriceThresholdStep", {}, false, "0.1"));
134 settings.fixedMinStdDevs = parseReal(engineParameter("FixedMinStdDevs", {}, false, "-5.0"));
135 settings.fixedMaxStdDevs = parseReal(engineParameter("FixedMaxStdDevs", {}, false, "5.0"));
136
137 bool staticTodaysSpot = false;
138 if (auto it = globalParameters_.find("RunType");
139 it != globalParameters_.end() && it->second != "Exposure") {
140 staticTodaysSpot = parseBool(modelParameter("StaticTodaysSpot", {}, false, "false"));
141 }
142
143 if (momentType == MomentType::Variance)
144 return QuantLib::ext::make_shared<QuantExt::GeneralisedReplicatingVarianceSwapEngine>(
145 index, gbsp, market_->discountCurve(ccy.code(), configuration(ore::data::MarketContext::pricing)),
146 settings, staticTodaysSpot);
147 else
148 return QuantLib::ext::make_shared<QuantExt::VolatilityFromVarianceSwapEngine>(
149 index, gbsp, market_->discountCurve(ccy.code(), configuration(ore::data::MarketContext::pricing)),
150 settings, staticTodaysSpot);
151 }
QuantLib::ext::shared_ptr< Market > market_
std::string modelParameter(const std::string &p, const std::vector< std::string > &qualifiers={}, const bool mandatory=true, const std::string &defaultValue="") const
std::string engineParameter(const std::string &p, const std::vector< std::string > &qualifiers={}, const bool mandatory=true, const std::string &defaultValue="") const
const string & configuration(const MarketContext &key)
Return a configuration (or the default one if key not found)
std::map< std::string, std::string > globalParameters_
QuantLib::ext::shared_ptr< FxIndex > parseFxIndex(const string &s, const Handle< Quote > &fxSpot, const Handle< YieldTermStructure > &sourceYts, const Handle< YieldTermStructure > &targetYts, const bool useConventions)
Convert std::string to QuantExt::FxIndex.
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
QuantLib::ext::shared_ptr< QuantExt::FxIndex > buildFxIndex(const string &fxIndex, const string &domestic, const string &foreign, const QuantLib::ext::shared_ptr< Market > &market, const string &configuration, bool useXbsCurves)
Definition: marketdata.cpp:137
+ Here is the call graph for this function: