Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
quantovanillaoption.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/quantovanillaoption.hpp
20 \brief Abstract engine builder for Quanto European Options
21 \ingroup builders
22*/
23
24#pragma once
25
26#include <boost/make_shared.hpp>
29#include <ql/pricingengines/quanto/quantoengine.hpp>
30
31namespace ore {
32namespace data{
33
34//! Abstract Engine Builder for Quanto Vanilla Options
35/*! Pricing engines are cached by asset/currency
36
37 \ingroup builders
38*/
40 : public CachingOptionEngineBuilder<string, const string&, const Currency&, const Currency&, const AssetClass&,
41 const Date&> {
42public:
43 QuantoVanillaOptionEngineBuilder(const string& model, const string& engine, const set<string>& tradeTypes,
44 const AssetClass& assetClass, const Date& expiryDate)
45 : CachingOptionEngineBuilder(model, engine, tradeTypes, assetClass), expiryDate_(expiryDate) {}
46
47 QuantLib::ext::shared_ptr<PricingEngine> engine(const string& assetName, const Currency& underlyingCcy,
48 const Currency& payCcy, const Date& expiryDate) {
49 return CachingPricingEngineBuilder<string, const string&, const Currency&, const Currency&, const AssetClass&,
50 const Date&>::engine(assetName, underlyingCcy, payCcy, assetClass_,
51 expiryDate);
52 }
53
54protected:
55 virtual string keyImpl(const string& assetName, const Currency& underlyingCcy, const Currency& payCcy,
56 const AssetClass& assetClassUnderlying, const Date& expiryDate) override {
57 return assetName + "/" + underlyingCcy.code() + "/" + payCcy.code() + "/" + to_string(expiryDate);
58 }
59
61};
62
63//! Abstract Engine Builder for Quanto European Vanilla Options
64/*! Pricing engines are cached by asset/currency
65
66 \ingroup builders
67*/
69public:
70 QuantoEuropeanOptionEngineBuilder(const string& model, const set<string>& tradeTypes, const AssetClass& assetClass)
71 : QuantoVanillaOptionEngineBuilder(model, "AnalyticEuropeanEngine", tradeTypes, assetClass, Date()) {}
72
73protected:
74 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const string& assetName, const Currency& underlyingCcy,
75 const Currency& payCcy, const AssetClass& assetClassUnderlying,
76 const Date& expiryDate) override {
77 QuantLib::ext::shared_ptr<QuantLib::GeneralizedBlackScholesProcess> gbsp =
78 getBlackScholesProcess(assetName, underlyingCcy, assetClassUnderlying);
79
80 Handle<YieldTermStructure> discountCurve =
81 market_->discountCurve(underlyingCcy.code(), configuration(MarketContext::pricing));
82
83 Handle<BlackVolTermStructure> fxVolatility =
84 market_->fxVol(underlyingCcy.code() + payCcy.code(), configuration(MarketContext::pricing));
85
86 std::string fxSource = modelParameters_.at("FXSource");
87 std::string fxIndex = "FX-" + fxSource + "-" + underlyingCcy.code() + "-" + payCcy.code();
88 std::string underlyingIndex;
89 switch (assetClassUnderlying) {
90 case AssetClass::EQ:
91 underlyingIndex = "EQ-" + assetName;
92 break;
93 case AssetClass::COM:
94 underlyingIndex = "COMM-" + assetName;
95 break;
96 default:
97 QL_FAIL("Asset class " << assetClassUnderlying << " not supported for quanto vanilla option.");
98 }
99
100 QuantLib::Handle<QuantExt::CorrelationTermStructure> corrCurve(
101 QuantLib::ext::make_shared<QuantExt::FlatCorrelation>(0, NullCalendar(), 0.0, Actual365Fixed()));
102 try {
103 corrCurve = market_->correlationCurve(fxIndex, underlyingIndex, configuration(MarketContext::pricing));
104 } catch (...) {
105 WLOG("no correlation curve for " << fxIndex << ", " << underlyingIndex
106 << " found, fall back to zero correlation");
107 }
108
109 return QuantLib::ext::make_shared<QuantLib::QuantoEngine<VanillaOption, QuantLib::AnalyticEuropeanEngine>>(
110 gbsp, discountCurve, fxVolatility,
111 Handle<Quote>(
112 QuantLib::ext::make_shared<QuantExt::CorrelationValue>(corrCurve, corrCurve->timeFromReference(expiryDate))));
113 }
114};
115
116} // namespace data
117} //namespace ore
Abstract engine builders for European and American Options.
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)
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.
const string & configuration(const MarketContext &key)
Return a configuration (or the default one if key not found)
map< string, string > modelParameters_
Abstract Engine Builder for Quanto European Vanilla Options.
QuantoEuropeanOptionEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass)
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &underlyingCcy, const Currency &payCcy, const AssetClass &assetClassUnderlying, const Date &expiryDate) override
Abstract Engine Builder for Quanto Vanilla Options.
QuantoVanillaOptionEngineBuilder(const string &model, const string &engine, const set< string > &tradeTypes, const AssetClass &assetClass, const Date &expiryDate)
virtual string keyImpl(const string &assetName, const Currency &underlyingCcy, const Currency &payCcy, const AssetClass &assetClassUnderlying, const Date &expiryDate) override
QuantLib::ext::shared_ptr< PricingEngine > engine(const string &assetName, const Currency &underlyingCcy, const Currency &payCcy, const Date &expiryDate)
@ 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