33#include <boost/make_shared.hpp>
41#include <ql/processes/blackscholesprocess.hpp>
54 const AssetClass&, const MomentType&> {
58 {
"EquityVarianceSwap",
"FxVarianceSwap",
"CommodityVarianceSwap"}) {}
61 virtual string keyImpl(
const string& underlyingName,
const Currency& ccy,
const AssetClass& assetClassUnderlying,
63 return underlyingName +
"/" + ccy.code() +
"/" +
67 virtual QuantLib::ext::shared_ptr<PricingEngine>
engineImpl(
const string& underlyingName,
const Currency& ccy,
70 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp;
71 QuantLib::ext::shared_ptr<Index> index;
73 gbsp = QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(
78 index =
market_->equityCurve(underlyingName).currentLink();
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>(
90 index =
buildFxIndex(
"FX-" + underlyingName, targetCurrencyCode, sourceCurrencyCode,
market_,
95 Handle<Quote> commoditySpot(QuantLib::ext::make_shared<QuantExt::DerivedPriceQuote>(priceCurve));
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();
102 QL_FAIL(
"Asset class of " + underlyingName +
" not recognized.");
107 std::string schemeStr =
engineParameter(
"Scheme", {},
false,
"GaussLobatto");
108 std::string boundsStr =
engineParameter(
"Bounds", {},
false,
"PriceThreshold");
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;
115 QL_FAIL(
"invalid var swap pricing engine parameter Scheme (" << schemeStr
116 <<
"), expected GaussLobatto, Segment");
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;
124 QL_FAIL(
"invalid var swap pricing engine parameter Bounds (" << boundsStr
125 <<
"), expected Fixed, PriceThreshold");
137 bool staticTodaysSpot =
false;
144 return QuantLib::ext::make_shared<QuantExt::GeneralisedReplicatingVarianceSwapEngine>(
146 settings, staticTodaysSpot);
148 return QuantLib::ext::make_shared<QuantExt::VolatilityFromVarianceSwapEngine>(
150 settings, staticTodaysSpot);
Abstract template engine builder class.
Size maxPriceThresholdSteps
Abstract template EngineBuilder class that can cache engines and coupon pricers.
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_
Engine Builder for Variance Swaps.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &underlyingName, const Currency &ccy, const AssetClass &assetClassUnderlying, const MomentType &momentType) override
virtual string keyImpl(const string &underlyingName, const Currency &ccy, const AssetClass &assetClassUnderlying, const MomentType &momentType) override
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.
Real parseReal(const string &s)
Convert text to Real.
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
market data related utilties
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)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.
string conversion utilities