Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxdigitalbarrieroption.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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/fxoption.hpp
20 \brief
21 \ingroup portfolio
22*/
23
24#pragma once
25
27
28#include <boost/make_shared.hpp>
33#include <ql/pricingengines/barrier/analyticbinarybarrierengine.hpp>
34#include <ql/processes/blackscholesprocess.hpp>
36
37namespace ore {
38namespace data {
39using namespace std;
40using namespace QuantLib;
41
42//! Engine Builder for European FX Digital Barrier Options
43/*! Pricing engines are cached by currency pair
44
45 \ingroup portfolio
46 */
48 : public ore::data::CachingPricingEngineBuilder<string, const Currency&, const Currency&, const Date&> {
49public:
51 : CachingEngineBuilder("GarmanKohlhagen", "FdBlackScholesBarrierEngine", {"FxDigitalBarrierOption"}) {}
52 FxDigitalBarrierOptionEngineBuilder(const string& model, const string& engine)
53 : CachingEngineBuilder(model, engine, {"FxDigitalBarrierOption"}) {}
54
55protected:
56 virtual string keyImpl(const Currency& forCcy, const Currency& domCcy, const Date& expiryDate) override {
57 return forCcy.code() + domCcy.code() + ore::data::to_string(expiryDate);
58 }
59
60 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const Currency& forCcy, const Currency& domCcy,
61 const Date& expiryDate) override {
62 // We follow the way FdBlackScholesBarrierEngine determines maturity for time grid generation
63 Handle<YieldTermStructure> riskFreeRate =
64 market_->discountCurve(domCcy.code(), configuration(ore::data::MarketContext::pricing));
65 Time expiry = riskFreeRate->dayCounter().yearFraction(riskFreeRate->referenceDate(),
66 std::max(riskFreeRate->referenceDate(), expiryDate));
67
68 FdmSchemeDesc scheme = ore::data::parseFdmSchemeDesc(engineParameter("Scheme"));
69 Size tGrid = std::max<Size>(1, (Size)(ore::data::parseInteger(engineParameter("TimeGridPerYear")) * expiry));
70 Size xGrid = ore::data::parseInteger(engineParameter("XGrid"));
71 Size dampingSteps = ore::data::parseInteger(engineParameter("DampingSteps"));
72 bool monotoneVar = ore::data::parseBool(engineParameter("EnforceMonotoneVariance", {}, false, "true"));
73
74 const string pair = forCcy.code() + domCcy.code();
75 Handle<BlackVolTermStructure> vol = market_->fxVol(pair, configuration(ore::data::MarketContext::pricing));
76 if (monotoneVar) {
77 // Replicate the construction of time grid in FiniteDifferenceModel::rollbackImpl
78 // This time grid is required to build a BlackMonotoneVarVolTermStructure which
79 // ensures monotonic variance along the time grid
80 const Size totalSteps = tGrid + dampingSteps;
81 std::vector<Time> timePoints(totalSteps + 1);
82 Array timePointsArray(totalSteps, expiry, -expiry / totalSteps);
83 timePoints[0] = 0.0;
84 for (Size i = 0; i < totalSteps; i++)
85 timePoints[timePoints.size() - i - 1] = timePointsArray[i];
86 timePoints.insert(std::upper_bound(timePoints.begin(), timePoints.end(), 0.99 / 365), 0.99 / 365);
87 vol = Handle<BlackVolTermStructure>(
88 QuantLib::ext::make_shared<QuantExt::BlackMonotoneVarVolTermStructure>(vol, timePoints));
89 vol->enableExtrapolation();
90 }
91 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp = QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(
93 market_->discountCurve(forCcy.code(), configuration(ore::data::MarketContext::pricing)),
94 market_->discountCurve(domCcy.code(), configuration(ore::data::MarketContext::pricing)), vol);
95 return QuantLib::ext::make_shared<FdBlackScholesBarrierEngine>(gbsp, tGrid, xGrid, dampingSteps, scheme);
96 }
97};
98
99} // namespace data
100} // 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.
std::string engineParameter(const std::string &p, const std::vector< std::string > &qualifiers={}, const bool mandatory=true, const std::string &defaultValue="") const
const string & configuration(const MarketContext &key)
Return a configuration (or the default one if key not found)
Engine Builder for European FX Digital Barrier Options.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const Currency &forCcy, const Currency &domCcy, const Date &expiryDate) override
FxDigitalBarrierOptionEngineBuilder(const string &model, const string &engine)
virtual string keyImpl(const Currency &forCcy, const Currency &domCcy, const Date &expiryDate) override
Pricing Engine Factory.
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
FdmSchemeDesc parseFdmSchemeDesc(const std::string &s)
Convert string to fdm scheme desc.
Definition: parsers.cpp:692
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
@ 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