Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxbarrieroption.cpp
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 ORE is free software: you can redistribute it and/or modify it
8 under the terms of the Modified BSD License. You should have received a
9 copy of the license along with this program.
10 The license is also available online at <http://opensourcerisk.org>
11 This program is distributed on the basis that it will form a useful
12 contribution to risk analytics and model standardisation, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
15 */
16
21
22#include <boost/make_shared.hpp>
28#include <ql/errors.hpp>
29#include <ql/exercise.hpp>
30#include <ql/instruments/barrieroption.hpp>
31#include <ql/instruments/barriertype.hpp>
32#include <ql/instruments/compositeinstrument.hpp>
33#include <ql/instruments/vanillaoption.hpp>
35
36using namespace QuantLib;
37
38namespace ore {
39namespace data {
40
42 QL_REQUIRE(barrier().levels().size() == 1, "Invalid number of barrier levels");
43 QL_REQUIRE(barrier().style().empty() || barrier().style() == "American", "Only american barrier style suppported");
44}
45
46QuantLib::ext::shared_ptr<QuantLib::PricingEngine>
47FxBarrierOption::vanillaPricingEngine(const QuantLib::ext::shared_ptr<EngineFactory>& ef, const QuantLib::Date& expiryDate,
48 const QuantLib::Date& paymentDate) {
49
50 if (paymentDate > expiryDate) {
51 QuantLib::ext::shared_ptr<EngineBuilder> builder = ef->builder("FxOptionEuropeanCS");
52 QL_REQUIRE(builder, "No builder found for FxOptionEuropeanCS");
53
54 QuantLib::ext::shared_ptr<FxEuropeanCSOptionEngineBuilder> fxOptBuilder =
55 QuantLib::ext::dynamic_pointer_cast<FxEuropeanCSOptionEngineBuilder>(builder);
56 QL_REQUIRE(fxOptBuilder, "No FxEuropeanCSOptionEngineBuilder found");
57
58 return fxOptBuilder->engine(parseCurrency(boughtCurrency_), parseCurrency(soldCurrency_), paymentDate);
59 } else {
60 QuantLib::ext::shared_ptr<EngineBuilder> builder = ef->builder("FxOption");
61 QL_REQUIRE(builder, "No builder found for FxOption");
62
63 QuantLib::ext::shared_ptr<FxEuropeanOptionEngineBuilder> fxOptBuilder =
64 QuantLib::ext::dynamic_pointer_cast<FxEuropeanOptionEngineBuilder>(builder);
65 QL_REQUIRE(fxOptBuilder, "No FxEuropeanOptionEngineBuilder found");
66
67 setSensitivityTemplate(*fxOptBuilder);
68
69 return fxOptBuilder->engine(parseCurrency(boughtCurrency_), parseCurrency(soldCurrency_), expiryDate);
70 }
71}
72
73QuantLib::ext::shared_ptr<QuantLib::PricingEngine>
74FxBarrierOption::barrierPricingEngine(const QuantLib::ext::shared_ptr<EngineFactory>& ef, const QuantLib::Date& expiryDate,
75 const QuantLib::Date& paymentDate) {
76
77 QuantLib::ext::shared_ptr<EngineBuilder> builder = ef->builder(tradeType_);
78 QL_REQUIRE(builder, "No builder found for " << tradeType_);
79
80 QuantLib::ext::shared_ptr<FxBarrierOptionEngineBuilder> fxBarrierOptBuilder =
81 QuantLib::ext::dynamic_pointer_cast<FxBarrierOptionEngineBuilder>(builder);
82 QL_REQUIRE(fxBarrierOptBuilder, "No FxBarrierOptionEngineBuilder found");
83
84 setSensitivityTemplate(*fxBarrierOptBuilder);
85
86 return fxBarrierOptBuilder->engine(parseCurrency(boughtCurrency_), parseCurrency(soldCurrency_), expiryDate, paymentDate);
87}
88
89} // namespace data
90} // namespace oreplus
Wrapper for option instruments, tracks whether option has been exercised or not.
Engine builder for FX Options.
const BarrierData & barrier() const
QuantLib::ext::shared_ptr< QuantLib::PricingEngine > barrierPricingEngine(const QuantLib::ext::shared_ptr< EngineFactory > &ef, const QuantLib::Date &expiryDate, const QuantLib::Date &paymentDate=QuantLib::Date()) override
QuantLib::ext::shared_ptr< QuantLib::PricingEngine > vanillaPricingEngine(const QuantLib::ext::shared_ptr< EngineFactory > &ef, const QuantLib::Date &expiryDate, const QuantLib::Date &paymentDate=QuantLib::Date()) override
create the pricing engines
void checkBarriers() override
check validity of barriers
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
string tradeType_
Definition: trade.hpp:196
Pricing Engine Factory.
FX Barrier Option data model and serialization.
FX Option data model and serialization.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
Size size(const ValueType &v)
Definition: value.cpp:145
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.