Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
equityoptionposition.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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/equityoptionposition.hpp
20 \brief Equity Option Position trade data model and serialization
21 \ingroup tradedata
22 */
23
24#pragma once
25
28
30
31#include <ql/instruments/vanillaoption.hpp>
32
33namespace ore {
34namespace data {
35
36using namespace ore::data;
37
38//! Serializable Equity Option Underlying Data, this represents one underlying in EquityOptionPositionData
40public:
44
45 const EquityUnderlying& underlying() const { return underlying_; }
46 const OptionData& optionData() const { return optionData_; }
47 Real strike() const { return strike_; }
48
49 void fromXML(XMLNode* node) override;
50 XMLNode* toXML(XMLDocument& doc) const override;
51
52private:
55 Real strike_;
56};
57
58//! Serializable Equity Option Position Data
60public:
62 EquityOptionPositionData(const Real quantity, const std::vector<EquityOptionUnderlyingData>& underlyings)
64
65 Real quantity() const { return quantity_; }
66 const std::vector<EquityOptionUnderlyingData>& underlyings() const { return underlyings_; }
67
68 void fromXML(XMLNode* node) override;
69 XMLNode* toXML(XMLDocument& doc) const override;
70
71private:
72 Real quantity_ = QuantLib::Null<Real>();
73 std::vector<EquityOptionUnderlyingData> underlyings_;
74};
75
76//! Serializable Equity Option Position
78public:
79 EquityOptionPosition() : Trade("EquityOptionPosition") {}
81 : Trade("EquityOptionPosition", env), data_(data) {}
82
83 // trade interface
84 void build(const QuantLib::ext::shared_ptr<ore::data::EngineFactory>&) override;
85 void fromXML(XMLNode* node) override;
86 XMLNode* toXML(XMLDocument& doc) const override;
87 std::map<AssetClass, std::set<std::string>>
88 underlyingIndices(const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceDataManager = nullptr) const override;
89
90 // additional inspectors
91 const EquityOptionPositionData& data() const { return data_; }
92 /* the underlying option instruments */
93 const std::vector<QuantLib::ext::shared_ptr<QuantLib::VanillaOption>>& options() const { return options_; }
94 /* by convention, these are generic indices of the form
95 GENERIC-MD/EQUITY_OPTION/PRICE/RIC:GOGO.OQ/USD/2020-03-20/2250/P
96 holding historical price information on the underlying option, needed for GenericTRS trades on
97 an equity option position. */
98 /* the underlying equity option currencies (equal to the equity currencies) */
99 const std::vector<Real>& positions() const { return positions_; }
100 const std::vector<std::string>& currencies() const { return currencies_; }
101 const std::vector<QuantLib::ext::shared_ptr<QuantExt::GenericIndex>> historicalPriceIndices() { return indices_; }
102 const std::vector<Real>& weights() const { return weights_; }
103 bool isSingleCurrency() const { return isSingleCurrency_; }
104
105 /*! we allow to set the npv currency to a different currency than the default npv currency = first asset's
106 currency; in this case a conversion rate from the default to the new currency has to be provided */
107 void setNpvCurrencyConversion(const std::string& ccy, const Handle<Quote>& conversion);
108
109private:
111 // populated during build()
112 std::vector<QuantLib::ext::shared_ptr<QuantLib::VanillaOption>> options_;
113 std::vector<QuantLib::ext::shared_ptr<QuantExt::GenericIndex>> indices_;
114 std::vector<Real> positions_;
115 std::vector<std::string> currencies_;
116 std::vector<Real> weights_;
117 std::vector<Handle<Quote>> fxConversion_;
119};
120
121//! Equity Option Position instrument wrapper
122class EquityOptionPositionInstrumentWrapper : public QuantLib::Instrument {
123public:
124 class arguments;
125 class results;
126 class engine;
127
128 EquityOptionPositionInstrumentWrapper(const Real quantity,
129 const std::vector<QuantLib::ext::shared_ptr<QuantLib::VanillaOption>>& options,
130 const std::vector<Real>& positions,
131 const std::vector<Real>& weights,
132 const std::vector<Handle<Quote>>& fxConversion = {});
133
134 void setNpvCurrencyConversion(const Handle<Quote>& npvCcyConversion);
135
136 //! \name Instrument interface
137 //@{
138 bool isExpired() const override;
140 void fetchResults(const QuantLib::PricingEngine::results*) const override;
141 //@}
142
143private:
145 std::vector<QuantLib::ext::shared_ptr<QuantLib::VanillaOption>> options_;
146 std::vector<Real> weights_;
147 std::vector<Real> positions_;
148 std::vector<Handle<Quote>> fxConversion_;
149 Handle<Quote> npvCcyConversion_;
150};
151
153public:
155 std::vector<QuantLib::ext::shared_ptr<QuantLib::VanillaOption>> options_;
156 std::vector<Real> weights_;
157 std::vector<Real> positions_;
158 std::vector<Handle<Quote>> fxConversion_;
159 Handle<Quote> npvCcyConversion_;
160 void validate() const override {}
161};
162
163class EquityOptionPositionInstrumentWrapper::results : public Instrument::results {
164public:
165 void reset() override {}
166};
167
169 : public QuantLib::GenericEngine<EquityOptionPositionInstrumentWrapper::arguments,
170 EquityOptionPositionInstrumentWrapper::results> {};
171
173public:
174 void calculate() const override;
175};
176
177} // namespace data
178} // namespace ore
Serializable object holding generic trade data, reporting dimensions.
Definition: envelope.hpp:51
Serializable Equity Option Position Data.
const std::vector< EquityOptionUnderlyingData > & underlyings() const
EquityOptionPositionData(const Real quantity, const std::vector< EquityOptionUnderlyingData > &underlyings)
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
std::vector< EquityOptionUnderlyingData > underlyings_
Serializable Equity Option Position.
const std::vector< QuantLib::ext::shared_ptr< QuantExt::GenericIndex > > historicalPriceIndices()
std::vector< QuantLib::ext::shared_ptr< QuantLib::VanillaOption > > options_
const std::vector< std::string > & currencies() const
std::vector< QuantLib::ext::shared_ptr< QuantExt::GenericIndex > > indices_
std::map< AssetClass, std::set< std::string > > underlyingIndices(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
EquityOptionPosition(const Envelope &env, const EquityOptionPositionData &data)
void fromXML(XMLNode *node) override
std::vector< Handle< Quote > > fxConversion_
void setNpvCurrencyConversion(const std::string &ccy, const Handle< Quote > &conversion)
XMLNode * toXML(XMLDocument &doc) const override
const std::vector< Real > & positions() const
const std::vector< QuantLib::ext::shared_ptr< QuantLib::VanillaOption > > & options() const
const std::vector< Real > & weights() const
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
const EquityOptionPositionData & data() const
std::vector< std::string > currencies_
std::vector< QuantLib::ext::shared_ptr< QuantLib::VanillaOption > > options_
Equity Option Position instrument wrapper.
void fetchResults(const QuantLib::PricingEngine::results *) const override
std::vector< QuantLib::ext::shared_ptr< QuantLib::VanillaOption > > options_
void setupArguments(QuantLib::PricingEngine::arguments *) const override
void setNpvCurrencyConversion(const Handle< Quote > &npvCcyConversion)
Serializable Equity Option Underlying Data, this represents one underlying in EquityOptionPositionDat...
const EquityUnderlying & underlying() const
XMLNode * toXML(XMLDocument &doc) const override
EquityOptionUnderlyingData(const EquityUnderlying &underlying, const OptionData &optionData, const Real strike)
Serializable object holding option data.
Definition: optiondata.hpp:42
Trade base class.
Definition: trade.hpp:55
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
Base class for all serializable classes.
Definition: xmlutils.hpp:101
@ 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