26#include <boost/make_shared.hpp>
32#include <ql/pricingengines/vanilla/analyticeuropeanengine.hpp>
33#include <ql/pricingengines/vanilla/fdblackscholesvanillaengine.hpp>
34#include <ql/processes/blackscholesprocess.hpp>
54 const std::vector<Time>& timePoints = {},
55 const bool useFxSpot =
true) {
61 Handle<BlackVolTermStructure> vol = this->
market_->equityVol(assetName, config);
62 if (!timePoints.empty()) {
63 vol = Handle<BlackVolTermStructure>(QuantLib::ext::make_shared<VVTS>(vol, timePoints));
64 vol->enableExtrapolation();
66 return QuantLib::ext::make_shared<QuantLib::GeneralizedBlackScholesProcess>(
67 this->
market_->equitySpot(assetName, config), this->market_->equityDividendCurve(assetName, config),
68 this->market_->equityForecastCurve(assetName, config), vol);
71 const string& ccyPairCode = assetName + ccy.code();
72 Handle<BlackVolTermStructure> vol = this->
market_->fxVol(ccyPairCode, config);
73 if (!timePoints.empty()) {
74 vol = Handle<BlackVolTermStructure>(QuantLib::ext::make_shared<VVTS>(vol, timePoints));
75 vol->enableExtrapolation();
78 return QuantLib::ext::make_shared<QuantLib::GeneralizedBlackScholesProcess>(
79 this->
market_->fxSpot(ccyPairCode, config), this->market_->discountCurve(assetName, config),
80 this->market_->discountCurve(ccy.code(), config), vol);
82 return QuantLib::ext::make_shared<QuantLib::GeneralizedBlackScholesProcess>(
83 this->
market_->fxRate(ccyPairCode, config), this->market_->discountCurve(assetName, config),
84 this->market_->discountCurve(ccy.code(), config), vol);
89 Handle<BlackVolTermStructure> vol = this->
market_->commodityVolatility(assetName, config);
90 if (!timePoints.empty()) {
91 vol = Handle<BlackVolTermStructure>(QuantLib::ext::make_shared<VVTS>(vol, timePoints));
92 vol->enableExtrapolation();
96 Handle<QuantExt::PriceTermStructure> priceCurve = this->
market_->commodityPriceCurve(assetName, config);
97 Handle<Quote> commoditySpot(QuantLib::ext::make_shared<QuantExt::DerivedPriceQuote>(priceCurve));
98 Handle<YieldTermStructure> discount = this->
market_->discountCurve(ccy.code(), config);
99 Handle<YieldTermStructure> yield(
100 QuantLib::ext::make_shared<QuantExt::PriceTermStructureAdapter>(*priceCurve, *discount));
101 yield->enableExtrapolation();
103 return QuantLib::ext::make_shared<QuantLib::GeneralizedBlackScholesProcess>(commoditySpot, yield, discount, vol);
106 QL_FAIL(
"Asset class of " << (
int)assetClassUnderlying <<
" not recognized.");
121 const AssetClass& assetClass,
const Date& expiryDate)
124 QuantLib::ext::shared_ptr<PricingEngine>
engine(
const string& assetName,
const Currency& ccy,
const Date& expiryDate,
const bool useFxSpot =
true) {
129 QuantLib::ext::shared_ptr<PricingEngine>
engine(
const Currency& ccy1,
const Currency& ccy2,
const Date& expiryDate,
130 const bool useFxSpot =
true) {
136 virtual string keyImpl(
const string& assetName,
const Currency& ccy,
const AssetClass& assetClassUnderlying,
137 const Date& expiryDate,
const bool useFxSpot)
override {
138 return assetName +
"/" + ccy.code() +
"/" +
to_string(expiryDate);
155 virtual QuantLib::ext::shared_ptr<PricingEngine>
engineImpl(
const string& assetName,
const Currency& ccy,
157 const Date& expiryDate,
const bool useFxSpot)
override {
158 QuantLib::ext::shared_ptr<QuantLib::GeneralizedBlackScholesProcess> gbsp =
160 Handle<YieldTermStructure> discountCurve =
162 return QuantLib::ext::make_shared<QuantLib::AnalyticEuropeanEngine>(gbsp, discountCurve);
177 virtual QuantLib::ext::shared_ptr<PricingEngine>
engineImpl(
const string& assetName,
const Currency& ccy,
178 const AssetClass& assetClassUnderlying,
const Date& expiryDate,
179 const bool useFxSpot)
override {
180 QuantLib::ext::shared_ptr<QuantLib::GeneralizedBlackScholesProcess> gbsp =
182 Handle<YieldTermStructure> discountCurve =
184 return QuantLib::ext::make_shared<QuantExt::AnalyticEuropeanForwardEngine>(gbsp, discountCurve);
197 virtual QuantLib::ext::shared_ptr<PricingEngine>
engineImpl(
const string& assetName,
const Currency& ccy,
198 const AssetClass& assetClassUnderlying,
const Date& expiryDate,
199 const bool useFxSpot)
override {
200 QuantLib::ext::shared_ptr<QuantLib::GeneralizedBlackScholesProcess> gbsp =
202 Handle<YieldTermStructure> discountCurve =
204 return QuantLib::ext::make_shared<QuantExt::AnalyticCashSettledEuropeanEngine>(gbsp, discountCurve);
216 const AssetClass& assetClass,
const Date& expiryDate)
228 const Date& expiryDate)
232 virtual QuantLib::ext::shared_ptr<PricingEngine>
engineImpl(
const string& assetName,
const Currency& ccy,
233 const AssetClass& assetClass,
const Date& expiryDate,
234 const bool useFxSpot)
override {
236 Handle<YieldTermStructure> riskFreeRate =
238 Time expiry = riskFreeRate->dayCounter().yearFraction(riskFreeRate->referenceDate(),
239 std::max(riskFreeRate->referenceDate(), expiryDate));
247 tGrid = std::max(tGridMin, tGrid);
249 QuantLib::ext::shared_ptr<QuantLib::GeneralizedBlackScholesProcess> gbsp;
255 const Size totalSteps = tGrid + dampingSteps;
256 std::vector<Time> timePoints(totalSteps + 1);
257 Array timePointsArray(totalSteps, expiry, -expiry / totalSteps);
259 for (Size i = 0; i < totalSteps; i++)
260 timePoints[timePoints.size() - i - 1] = timePointsArray[i];
261 timePoints.insert(std::upper_bound(timePoints.begin(), timePoints.end(), 0.99 / 365), 0.99 / 365);
266 return QuantLib::ext::make_shared<FdBlackScholesVanillaEngine>(gbsp, tGrid, xGrid, dampingSteps, scheme);
281 virtual QuantLib::ext::shared_ptr<PricingEngine>
engineImpl(
const string& assetName,
const Currency& ccy,
282 const AssetClass& assetClass,
const Date& expiryDate,
283 const bool useFxSpot)
override {
284 QuantLib::ext::shared_ptr<QuantLib::GeneralizedBlackScholesProcess> gbsp =
getBlackScholesProcess(assetName, ccy, assetClass);
285 return QuantLib::ext::make_shared<QuantExt::BaroneAdesiWhaleyApproximationEngine>(gbsp);
Abstract template engine builder class.
Abstract Engine Builder for American Vanilla Options using Barone Adesi Whaley Approximation.
AmericanOptionBAWEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass)
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClass, const Date &expiryDate, const bool useFxSpot) override
Abstract Engine Builder for American Vanilla Options.
AmericanOptionEngineBuilder(const string &model, const string &engine, const set< string > &tradeTypes, const AssetClass &assetClass, const Date &expiryDate)
Abstract Engine Builder for American Vanilla Options using Finite Difference Method.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClass, const Date &expiryDate, const bool useFxSpot) override
AmericanOptionFDEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass, const Date &expiryDate)
Abstract template EngineBuilder class that can cache engines and coupon pricers.
QuantLib::ext::shared_ptr< QuantLib::GeneralizedBlackScholesProcess > getBlackScholesProcess(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const std::vector< Time > &timePoints={}, const bool useFxSpot=true)
CachingOptionEngineBuilder(const string &model, const string &engine, const set< string > &tradeTypes, const AssetClass &assetClass)
QuantLib::ext::shared_ptr< Market > market_
const string & engine() const
Return the engine name.
const set< string > & tradeTypes() const
Return the possible trade types.
const string & model() const
Return the model name.
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)
EuropeanCSOptionEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass)
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate, const bool useFxSpot) override
Abstract Engine Builder for European Vanilla Forward Options.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate, const bool useFxSpot) override
EuropeanForwardOptionEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass)
Abstract Engine Builder for European Vanilla Options.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate, const bool useFxSpot) override
EuropeanOptionEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass)
Abstract Engine Builder for Vanilla Options.
QuantLib::ext::shared_ptr< PricingEngine > engine(const string &assetName, const Currency &ccy, const Date &expiryDate, const bool useFxSpot=true)
VanillaOptionEngineBuilder(const string &model, const string &engine, const set< string > &tradeTypes, const AssetClass &assetClass, const Date &expiryDate)
QuantLib::ext::shared_ptr< PricingEngine > engine(const Currency &ccy1, const Currency &ccy2, const Date &expiryDate, const bool useFxSpot=true)
virtual string keyImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate, const bool useFxSpot) override
bool parseBool(const string &s)
Convert text to bool.
FdmSchemeDesc parseFdmSchemeDesc(const std::string &s)
Convert string to fdm scheme desc.
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
std::string to_string(const LocationInfo &l)
Serializable Credit Default Swap.
string conversion utilities