Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
pairwisevarianceswap.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 ored/portfolio/builders/pairwisevarianceswap.hpp
20 \brief pairwise variance swap engine builder
21 \ingroup builders
22*/
23
24#pragma once
25
27#include <qle/pricingengines/pairwisevarianceswapengine.hpp>
28
29#include <string>
30
31#include <boost/make_shared.hpp>
38#include <ql/processes/blackscholesprocess.hpp>
39#include <ql/version.hpp>
41
42namespace ore {
43namespace data {
44using namespace std;
45using namespace QuantLib;
46
47//! Engine Builder for Pairwise Variance Swaps
48/*! Pricing engines are cached by equity/currency
49
50 \ingroup builders
51 */
53 : public ore::data::CachingPricingEngineBuilder<string, const string&, const string&, const Currency&, const Date&,
54 const AssetClass&> {
55public:
57 : CachingEngineBuilder("BlackScholes", "PairwiseVarianceSwapEngine",
58 {"EquityPairwiseVarianceSwap", "FxPairwiseVarianceSwap"}) {}
59
60protected:
61 virtual string keyImpl(const string& underlyingName1, const string& underlyingName2, const Currency& ccy,
62 const Date& accrEndDate, const AssetClass& assetClassUnderlyings) override {
63 return underlyingName1 + "/" + underlyingName2 + "/" + ccy.code();
64 }
65
66 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const string& underlyingName1, const string& underlyingName2,
67 const Currency& ccy, const Date& accrEndDate,
68 const AssetClass& assetClassUnderlyings) override {
69 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp1, gbsp2;
70 QuantLib::ext::shared_ptr<Index> index1, index2;
71 if (assetClassUnderlyings == AssetClass::EQ) {
72 gbsp1 = QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(
73 market_->equitySpot(underlyingName1, configuration(ore::data::MarketContext::pricing)),
74 market_->equityDividendCurve(underlyingName1, configuration(ore::data::MarketContext::pricing)),
75 market_->equityForecastCurve(underlyingName1, configuration(ore::data::MarketContext::pricing)),
76 market_->equityVol(underlyingName1, configuration(ore::data::MarketContext::pricing)));
77 index1 = market_->equityCurve(underlyingName1).currentLink();
78 gbsp2 = QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(
79 market_->equitySpot(underlyingName2, configuration(ore::data::MarketContext::pricing)),
80 market_->equityDividendCurve(underlyingName2, configuration(ore::data::MarketContext::pricing)),
81 market_->equityForecastCurve(underlyingName2, configuration(ore::data::MarketContext::pricing)),
82 market_->equityVol(underlyingName2, configuration(ore::data::MarketContext::pricing)));
83 index2 = market_->equityCurve(underlyingName2).currentLink();
84 } else if (assetClassUnderlyings == AssetClass::FX) {
85 const auto fxIndex1 = market_->fxIndex("FX-" + underlyingName1);
86 const auto fxIndex2 = market_->fxIndex("FX-" + underlyingName2);
87 const string& ccyPairCode1 = fxIndex1->sourceCurrency().code() + fxIndex1->targetCurrency().code();
88 const string& ccyPairCode2 = fxIndex2->sourceCurrency().code() + fxIndex2->targetCurrency().code();
89 gbsp1 = QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(
91 fxIndex1->targetCurve(), fxIndex1->sourceCurve(),
93 gbsp2 = QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(
95 fxIndex2->targetCurve(), fxIndex2->sourceCurve(),
97 index1 = fxIndex1.currentLink();
98 index2 = fxIndex2.currentLink();
99
100 } else {
101 QL_FAIL("Asset class of " + underlyingName1 + " and " + underlyingName2 + " not recognized.");
102 }
103
104 QuantLib::Handle<QuantExt::CorrelationTermStructure> corrCurve(
105 QuantLib::ext::make_shared<QuantExt::FlatCorrelation>(0, NullCalendar(), 0.0, Actual365Fixed()));
106 Handle<Quote> correlation(
107 QuantLib::ext::make_shared<QuantExt::CorrelationValue>(corrCurve, corrCurve->timeFromReference(accrEndDate)));
108
109 try {
110 corrCurve =
111 market_->correlationCurve(index1->name(), index2->name(), configuration(MarketContext::pricing));
112 } catch (...) {
113 WLOG("no correlation curve for " << index1->name() << ", " << index2->name()
114 << " found, fall back to zero correlation");
115 }
116
117 return QuantLib::ext::make_shared<QuantExt::PairwiseVarianceSwapEngine>(
118 index1, index2, gbsp1, gbsp2,
119 market_->discountCurve(ccy.code(), configuration(ore::data::MarketContext::pricing)), correlation);
120 }
121};
122
123} // namespace data
124} // 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 Pairwise Variance Swaps.
virtual string keyImpl(const string &underlyingName1, const string &underlyingName2, const Currency &ccy, const Date &accrEndDate, const AssetClass &assetClassUnderlyings) override
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &underlyingName1, const string &underlyingName2, const Currency &ccy, const Date &accrEndDate, const AssetClass &assetClassUnderlyings) override
Pricing Engine Factory.
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
string conversion utilities