Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
barrieroption.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 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
17/*! \file ored/portfolio/barrieroption.hpp
18 \brief Barrier Option data model and serialization
19 \ingroup portfolio
20*/
21
22#pragma once
23
30
31#include <ql/instruments/barriertype.hpp>
32
33namespace ore {
34namespace data {
35
36//! Serializable FX Barrier Option
37/*!
38 \ingroup tradedata
39*/
40class BarrierOption : virtual public ore::data::Trade {
41public:
42 //! Constructor
44
46 const std::string& calendar = std::string())
49 }
50
51 //! Build QuantLib/QuantExt instrument, link pricing engine
52 void build(const QuantLib::ext::shared_ptr<ore::data::EngineFactory>&) override;
53
54 //! check validity of barriers
55 virtual void checkBarriers() = 0;
56
57 // index of the underlying
58 virtual QuantLib::ext::shared_ptr<QuantLib::Index> getIndex() = 0;
59
60 // strike of underlying option
61 virtual const QuantLib::Real strike() = 0;
62
63 virtual QuantLib::Real tradeMultiplier() = 0;
64 virtual Currency tradeCurrency() = 0;
65 virtual QuantLib::ext::shared_ptr<QuantLib::PricingEngine>
66 vanillaPricingEngine(const QuantLib::ext::shared_ptr<EngineFactory>& ef, const QuantLib::Date& expiryDate,
67 const QuantLib::Date& paymentDate) = 0;
68 virtual QuantLib::ext::shared_ptr<QuantLib::PricingEngine>
69 barrierPricingEngine(const QuantLib::ext::shared_ptr<EngineFactory>& ef, const QuantLib::Date& expiryDate,
70 const QuantLib::Date& paymentDate) = 0;
71 virtual const QuantLib::Handle<QuantLib::Quote>& spotQuote() = 0;
72
73 virtual void additionalFromXml(ore::data::XMLNode* node) = 0;
74 virtual void additionalToXml(ore::data::XMLDocument& doc, ore::data::XMLNode* node) const = 0;
75 virtual std::string indexFixingName() = 0;
76
77 //! \name Inspectors
78 //@{
79 const ore::data::OptionData& option() const { return option_; }
80 const BarrierData& barrier() const { return barrier_; }
81 const QuantLib::Date& startDate() const { return startDate_; }
82 const QuantLib::Calendar& calendar() const { return calendar_; }
83 //@}
84
85 //! \name Serialisation
86 //@{
87 void fromXML(ore::data::XMLNode* node) override;
89 //@}
90
91private:
94 QuantLib::Date startDate_;
96
97protected:
98 std::string calendarStr_;
99};
100
102public:
103 //! Default constructor
105 boughtAmount_(0.0), soldAmount_(0.0) {}
106
107 //! Constructor
109 BarrierData barrier, QuantLib::Date startDate, std::string calendar, std::string boughtCurrency,
110 QuantLib::Real boughtAmount, std::string soldCurrency, QuantLib::Real soldAmount,
111 std::string fxIndex = std::string())
112 : ore::data::Trade(tradeType, env),
116
117 //! \name Inspectors
118 //@{
119 QuantLib::Real boughtAmount() const { return boughtAmount_; }
120 QuantLib::Real soldAmount() const { return soldAmount_; }
121 //@}
122
123 void build(const QuantLib::ext::shared_ptr<ore::data::EngineFactory>& ef) override;
124 //! \name Serialisation
125 //@{
126 void additionalFromXml(ore::data::XMLNode* node) override;
127 void additionalToXml(ore::data::XMLDocument& doc, ore::data::XMLNode* node) const override;
128 //@}
129
130 QuantLib::ext::shared_ptr<QuantLib::Index> getIndex() override { return QuantLib::ext::dynamic_pointer_cast<Index>(fxIndex_); }
131 const QuantLib::Real strike() override { return soldAmount_ / boughtAmount_; }
132 QuantLib::Real tradeMultiplier() override { return boughtAmount_; }
133 Currency tradeCurrency() override { return parseCurrency(soldCurrency_); }
134 const QuantLib::Handle<QuantLib::Quote>& spotQuote() override { return spotQuote_; }
135 std::string indexFixingName() override;
136
137 void fromXML(ore::data::XMLNode* node) override { BarrierOption::fromXML(node); }
139
140private:
141 std::string fxIndexStr_;
142 QuantLib::ext::shared_ptr<QuantExt::FxIndex> fxIndex_;
143 QuantLib::Handle<QuantLib::Quote> spotQuote_;
144 QuantLib::Real boughtAmount_;
145 QuantLib::Real soldAmount_;
146};
147
148
150public:
151 //! Default constructor
154
155 //! Constructor
157 BarrierData barrier, QuantLib::Date startDate, std::string calendar, const EquityUnderlying& equity,
158 QuantLib::Currency currency, QuantLib::Real quantity, TradeStrike strike)
162
163 //! \name Inspectors
164 //@{
165 QuantLib::Real quantity() const { return quantity_; }
166 //@}
167
168 void build(const QuantLib::ext::shared_ptr<ore::data::EngineFactory>& ef) override;
169 //! \name Serialisation
170 //@{
171 void additionalFromXml(ore::data::XMLNode* node) override;
172 void additionalToXml(ore::data::XMLDocument& doc, ore::data::XMLNode* node) const override;
173 //@}
174
175 QuantLib::ext::shared_ptr<QuantLib::Index> getIndex() override { return QuantLib::ext::dynamic_pointer_cast<Index>(eqIndex_); }
176 const QuantLib::Real strike() override { return tradeStrike_.value(); }
177 QuantLib::Real tradeMultiplier() override { return quantity_; }
178 Currency tradeCurrency() override { return currency_; }
179 const QuantLib::Handle<QuantLib::Quote>& spotQuote() override { return eqIndex_->equitySpot(); }
180 std::string indexFixingName() override { return "EQ-" + eqIndex_->name(); };
181
182 void fromXML(ore::data::XMLNode* node) override { BarrierOption::fromXML(node); }
184
185private:
186 QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> eqIndex_;
187 QuantLib::Currency currency_;
188 std::string currencyStr_;
189 QuantLib::Real quantity_;
191};
192
193} // namespace data
194} // namespace oreplus
Serializable obejct holding barrier data.
Definition: barrierdata.hpp:34
Serializable FX Barrier Option.
virtual QuantLib::ext::shared_ptr< QuantLib::PricingEngine > vanillaPricingEngine(const QuantLib::ext::shared_ptr< EngineFactory > &ef, const QuantLib::Date &expiryDate, const QuantLib::Date &paymentDate)=0
const BarrierData & barrier() const
virtual std::string indexFixingName()=0
const QuantLib::Date & startDate() const
virtual QuantLib::Real tradeMultiplier()=0
const ore::data::OptionData & option() const
virtual Currency tradeCurrency()=0
ore::data::OptionData option_
void fromXML(ore::data::XMLNode *node) override
virtual void checkBarriers()=0
check validity of barriers
const QuantLib::Calendar & calendar() const
virtual void additionalToXml(ore::data::XMLDocument &doc, ore::data::XMLNode *node) const =0
QuantLib::Calendar calendar_
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
virtual QuantLib::ext::shared_ptr< QuantLib::PricingEngine > barrierPricingEngine(const QuantLib::ext::shared_ptr< EngineFactory > &ef, const QuantLib::Date &expiryDate, const QuantLib::Date &paymentDate)=0
virtual void additionalFromXml(ore::data::XMLNode *node)=0
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
virtual const QuantLib::Handle< QuantLib::Quote > & spotQuote()=0
virtual const QuantLib::Real strike()=0
BarrierOption(ore::data::OptionData option, BarrierData barrier, QuantLib::Date startDate=QuantLib::Date(), const std::string &calendar=std::string())
virtual QuantLib::ext::shared_ptr< QuantLib::Index > getIndex()=0
Serializable object holding generic trade data, reporting dimensions.
Definition: envelope.hpp:51
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &ef) override
void additionalFromXml(ore::data::XMLNode *node) override
void fromXML(ore::data::XMLNode *node) override
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
QuantLib::ext::shared_ptr< QuantLib::Index > getIndex() override
void additionalToXml(ore::data::XMLDocument &doc, ore::data::XMLNode *node) const override
EquityOptionWithBarrier(const std::string &tradeType)
Default constructor.
const QuantLib::Real strike() override
QuantLib::Real tradeMultiplier() override
EquityOptionWithBarrier(const std::string &tradeType, ore::data::Envelope &env, ore::data::OptionData option, BarrierData barrier, QuantLib::Date startDate, std::string calendar, const EquityUnderlying &equity, QuantLib::Currency currency, QuantLib::Real quantity, TradeStrike strike)
Constructor.
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > eqIndex_
const QuantLib::Handle< QuantLib::Quote > & spotQuote() override
std::string indexFixingName() override
Base class for all single asset Equity Derivaties.
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &ef) override
Currency tradeCurrency() override
QuantLib::ext::shared_ptr< QuantExt::FxIndex > fxIndex_
void additionalFromXml(ore::data::XMLNode *node) override
QuantLib::Real boughtAmount() const
FxOptionWithBarrier(const std::string &tradeType, ore::data::Envelope &env, ore::data::OptionData option, BarrierData barrier, QuantLib::Date startDate, std::string calendar, std::string boughtCurrency, QuantLib::Real boughtAmount, std::string soldCurrency, QuantLib::Real soldAmount, std::string fxIndex=std::string())
Constructor.
QuantLib::Real soldAmount() const
void fromXML(ore::data::XMLNode *node) override
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
QuantLib::ext::shared_ptr< QuantLib::Index > getIndex() override
void additionalToXml(ore::data::XMLDocument &doc, ore::data::XMLNode *node) const override
FxOptionWithBarrier(const std::string &tradeType)
Default constructor.
const QuantLib::Real strike() override
QuantLib::Real tradeMultiplier() override
QuantLib::Handle< QuantLib::Quote > spotQuote_
const QuantLib::Handle< QuantLib::Quote > & spotQuote() override
std::string indexFixingName() override
Base class for all single asset FX Derivaties.
const std::string & soldCurrency() const
const std::string & boughtCurrency() const
Serializable object holding option data.
Definition: optiondata.hpp:42
Trade base class.
Definition: trade.hpp:55
const string & tradeType() const
Definition: trade.hpp:133
QuantLib::Real value() const
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
EQ base trade classes.
FX base trade classes.
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Definition: parsers.cpp:157
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
trade option data model and serialization
base trade data model and serialization