26#include <boost/make_shared.hpp>
30#include <ql/quotes/compositequote.hpp>
32#include <ql/pricingengines/vanilla/analyticeuropeanengine.hpp>
33#include <ql/processes/blackscholesprocess.hpp>
49 :
CachingEngineBuilder(
"BlackScholes",
"AnalyticEuropeanEngine", {
"EquityEuropeanCompositeOption"}) {}
52 virtual string keyImpl(
const string& equityName,
const Currency& equityCcy,
const Currency& strikeCcy,
53 const Date& expiry)
override {
54 return equityName +
"/" + equityCcy.code() +
"/" + strikeCcy.code() +
"/" +
to_string(expiry);
57 virtual QuantLib::ext::shared_ptr<PricingEngine>
engineImpl(
const string& equityName,
const Currency& equityCcy,
58 const Currency& strikeCcy,
const Date& expiry)
override {
64 string ccyPairCode = equityCcy.code() + strikeCcy.code();
66 Handle<Quote> equitySpot = this->
market_->equitySpot(equityName, config);
67 Handle<Quote> fxSpot = this->
market_->fxRate(ccyPairCode, config);
69 std::function<Real(
const Real&,
const Real&)> multiply = [](
const Real& a,
const Real& b) {
return a * b; };
71 using scaledQuoted = CompositeQuote<std::function<Real(
const Real&,
const Real&)>>;
73 Handle<Quote> spot(QuantLib::ext::make_shared<scaledQuoted>(equitySpot, fxSpot, multiply));
75 auto dividendCurve = this->
market_->equityDividendCurve(equityName, config);
77 auto equtiyForcastCurve = this->
market_->equityForecastCurve(equityName, config);
79 auto equityIndex = this->
market_->equityCurve(equityName, config);
81 Handle<BlackVolTermStructure> eqVol = this->
market_->equityVol(equityName, config);
82 Handle<BlackVolTermStructure> fxVol = this->
market_->fxVol(ccyPairCode, config);
84 auto strikeCcyDiscountCurve = this->
market_->discountCurve(strikeCcy.code(), config);
86 auto fxIndex =
market_->fxIndex(equityCcy.code() + strikeCcy.code()).currentLink();
89 Handle<QuantExt::CorrelationTermStructure> correlation;
91 correlation = this->
market_->correlationCurve(
92 "FX-GENERIC-" + equityCcy.code() +
"-" + strikeCcy.code(),
"EQ-" + equityName, config);
94 WLOG(
"Couldnt find correlation curve "
95 <<
" FX - GENERIC - " << equityCcy.code() <<
" -" << strikeCcy.code() <<
"&EQ - " << equityName <<
". will fallback to zero correlation");
96 correlation = Handle<QuantExt::CorrelationTermStructure>(QuantLib::ext::make_shared<QuantExt::FlatCorrelation>(0, WeekendsOnly(), 0, Actual365Fixed()));
99 Handle<BlackVolTermStructure> vol(
100 QuantLib::ext::make_shared<QuantExt::BlackVolatilitySurfaceProxy>(*eqVol, *equityIndex, *equityIndex, *fxVol, fxIndex, *correlation));
102 auto blackScholesProcess = QuantLib::ext::make_shared<QuantLib::GeneralizedBlackScholesProcess>(
103 spot, dividendCurve, strikeCcyDiscountCurve, vol);
105 Handle<YieldTermStructure> discountCurve =
108 return QuantLib::ext::make_shared<QuantLib::AnalyticEuropeanEngine>(blackScholesProcess, discountCurve);
Abstract template engine builder class.
Abstract template EngineBuilder class that can cache engines and coupon pricers.
QuantLib::ext::shared_ptr< Market > market_
const string & configuration(const MarketContext &key)
Return a configuration (or the default one if key not found)
Engine Builder for Composite European Equity Options.
EquityEuropeanCompositeEngineBuilder()
virtual string keyImpl(const string &equityName, const Currency &equityCcy, const Currency &strikeCcy, const Date &expiry) override
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &equityName, const Currency &equityCcy, const Currency &strikeCcy, const Date &expiry) override
#define WLOG(text)
Logging Macro (Level = Warning)
std::string to_string(const LocationInfo &l)
Serializable Credit Default Swap.
string conversion utilities