Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
equitycompositeoption.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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 portfolio/builders/equitycompositeoption.hpp
20 \brief Engine builder for equity composite options
21 \ingroup builders
22*/
23
24#pragma once
25
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>
36
37namespace ore {
38namespace data {
39
40//! Engine Builder for Composite European Equity Options
41/*! Pricing engines are cached by asset/asset currency/strike currency
42
43 \ingroup builders
44 */
46 : public CachingPricingEngineBuilder<string, const string&, const Currency&, const Currency&, const Date&> {
47public:
49 : CachingEngineBuilder("BlackScholes", "AnalyticEuropeanEngine", {"EquityEuropeanCompositeOption"}) {}
50
51protected:
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);
55 }
56
57 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const string& equityName, const Currency& equityCcy,
58 const Currency& strikeCcy, const Date& expiry) override {
59
61
62 // FOR = Underlyign CCY and DOM = Strike Currency
63 // -> converting underlying ccy into strike ccy by multiply eq spot by fx spot
64 string ccyPairCode = equityCcy.code() + strikeCcy.code();
65
66 Handle<Quote> equitySpot = this->market_->equitySpot(equityName, config);
67 Handle<Quote> fxSpot = this->market_->fxRate(ccyPairCode, config);
68
69 std::function<Real(const Real&, const Real&)> multiply = [](const Real& a, const Real& b) { return a * b; };
70
71 using scaledQuoted = CompositeQuote<std::function<Real(const Real&, const Real&)>>;
72
73 Handle<Quote> spot(QuantLib::ext::make_shared<scaledQuoted>(equitySpot, fxSpot, multiply));
74
75 auto dividendCurve = this->market_->equityDividendCurve(equityName, config);
76
77 auto equtiyForcastCurve = this->market_->equityForecastCurve(equityName, config);
78
79 auto equityIndex = this->market_->equityCurve(equityName, config);
80
81 Handle<BlackVolTermStructure> eqVol = this->market_->equityVol(equityName, config);
82 Handle<BlackVolTermStructure> fxVol = this->market_->fxVol(ccyPairCode, config);
83
84 auto strikeCcyDiscountCurve = this->market_->discountCurve(strikeCcy.code(), config);
85
86 auto fxIndex = market_->fxIndex(equityCcy.code() + strikeCcy.code()).currentLink();
87
88 // Try Catch and 0 correlation fallback
89 Handle<QuantExt::CorrelationTermStructure> correlation;
90 try {
91 correlation = this->market_->correlationCurve(
92 "FX-GENERIC-" + equityCcy.code() + "-" + strikeCcy.code(), "EQ-" + equityName, config);
93 } catch (...) {
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()));
97 }
98
99 Handle<BlackVolTermStructure> vol(
100 QuantLib::ext::make_shared<QuantExt::BlackVolatilitySurfaceProxy>(*eqVol, *equityIndex, *equityIndex, *fxVol, fxIndex, *correlation));
101
102 auto blackScholesProcess = QuantLib::ext::make_shared<QuantLib::GeneralizedBlackScholesProcess>(
103 spot, dividendCurve, strikeCcyDiscountCurve, vol);
104
105 Handle<YieldTermStructure> discountCurve =
106 market_->discountCurve(strikeCcy.code(), configuration(MarketContext::pricing));
107
108 return QuantLib::ext::make_shared<QuantLib::AnalyticEuropeanEngine>(blackScholesProcess, discountCurve);
109 }
110};
111
112} // namespace data
113} // namespace ore
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.
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
Pricing Engine Factory.
@ data
Definition: log.hpp:77
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
Serializable Credit Default Swap.
Definition: namespaces.docs:23
string conversion utilities