Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxdoubletouchoption.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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/fxdoubletouchoption.hpp
20 \brief
21 \ingroup portfolio
22*/
23
24#pragma once
25
26#include <boost/make_shared.hpp>
32#include <ql/processes/blackscholesprocess.hpp>
34
35namespace ore {
36namespace data {
37using namespace std;
38using namespace QuantLib;
39
40//! Abstract Engine Builder for FX Double Touch Options
41/*! Pricing engines are cached by currency pair
42
43 \ingroup portfolio
44 */
46 : public ore::data::CachingPricingEngineBuilder<string, const Currency&, const Currency&, const Date&, const bool> {
47public:
48 FxDoubleTouchOptionEngineBuilder(const string& model, const string& engine)
49 : CachingEngineBuilder(model, engine, {"FxDoubleTouchOption"}) {}
50
51protected:
52 virtual string keyImpl(const Currency& forCcy, const Currency& domCcy, const Date& payDate,
53 const bool flipResults) override {
54 return forCcy.code() + domCcy.code() + ore::data::to_string(payDate) + (flipResults ? "_1" : "_0");
55 }
56
57 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess>
58 getBlackScholesProcess(const Currency& forCcy, const Currency& domCcy, const std::vector<Time>& timePoints = {}) {
59 const string pair = forCcy.code() + domCcy.code();
60 Handle<BlackVolTermStructure> vol = market_->fxVol(pair, configuration(ore::data::MarketContext::pricing));
61 if (!timePoints.empty()) {
62 vol = Handle<BlackVolTermStructure>(
63 QuantLib::ext::make_shared<QuantExt::BlackMonotoneVarVolTermStructure>(vol, timePoints));
64 vol->enableExtrapolation();
65 }
66 return QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(
68 market_->discountCurve(forCcy.code(),
69 configuration(ore::data::MarketContext::pricing)), // dividend yield ~ foreign yield
70 market_->discountCurve(domCcy.code(), configuration(ore::data::MarketContext::pricing)), vol);
71 }
72};
73
74//! Analytical Engine Builder for FX Double Touch Options
75/*! Pricing engines are cached by currency pair
76
77 \ingroup portfolio
78 */
80public:
82 : FxDoubleTouchOptionEngineBuilder("GarmanKohlhagen", "AnalyticDoubleBarrierBinaryEngine") {}
83
84protected:
85 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const Currency& forCcy, const Currency& domCcy, const Date& payDate,
86 const bool flipResults) override {
87 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp = getBlackScholesProcess(forCcy, domCcy);
88
89 engine_ = "AnalyticDoubleBarrierBinaryEngine";
90 return QuantLib::ext::make_shared<QuantExt::AnalyticDoubleBarrierBinaryEngine>(gbsp, payDate, flipResults);
91 }
92};
93
94} // namespace data
95} // namespace oreplus
Abstract template engine builder class.
Abstract template EngineBuilder class that can cache engines and coupon pricers.
QuantLib::ext::shared_ptr< Market > market_
const string & engine() const
Return the engine name.
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)
Analytical Engine Builder for FX Double Touch Options.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const Currency &forCcy, const Currency &domCcy, const Date &payDate, const bool flipResults) override
Abstract Engine Builder for FX Double Touch Options.
virtual string keyImpl(const Currency &forCcy, const Currency &domCcy, const Date &payDate, const bool flipResults) override
QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > getBlackScholesProcess(const Currency &forCcy, const Currency &domCcy, const std::vector< Time > &timePoints={})
FxDoubleTouchOptionEngineBuilder(const string &model, const string &engine)
Pricing Engine Factory.
@ data
Definition: log.hpp:77
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
string conversion utilities