Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
equityposition.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/equityposition.hpp
20 \brief Equity Position trade data model and serialization
21 \ingroup tradedata
22 */
23
24#pragma once
25
27
29
30namespace ore {
31namespace data {
32
33//! Serializable Equity Position Data
35public:
37 EquityPositionData(const Real quantity, const std::vector<EquityUnderlying>& underlyings)
39
40 Real quantity() const { return quantity_; }
41 const std::vector<EquityUnderlying>& underlyings() const { return underlyings_; }
42
43 void fromXML(XMLNode* node) override;
44 XMLNode* toXML(XMLDocument& doc) const override;
45
46private:
47 Real quantity_ = QuantLib::Null<Real>();
48 std::vector<EquityUnderlying> underlyings_;
49};
50
51//! Serializable Equity Position
52class EquityPosition : public Trade {
53public:
54 EquityPosition() : Trade("EquityPosition") {}
55 EquityPosition(const Envelope& env, const EquityPositionData& data) : Trade("EquityPosition", env), data_(data) {}
56
57 // trade interface
58 void build(const QuantLib::ext::shared_ptr<ore::data::EngineFactory>&) override;
59 void fromXML(XMLNode* node) override;
60 XMLNode* toXML(XMLDocument& doc) const override;
61 std::map<AssetClass, std::set<std::string>>
62 underlyingIndices(const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceDataManager = nullptr) const override;
63
64 // additional inspectors
65 const EquityPositionData& data() const { return data_; }
66 const std::vector<QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>>& indices() const { return indices_; }
67 const std::vector<Real>& weights() const { return weights_; }
68 bool isSingleCurrency() const { return isSingleCurrency_; }
69
70 /*! we allow to set the npv currency to a different currency than the default npv currency = first asset's
71 currency; in this case a conversion rate from the default to the new currency has to be provided */
72 void setNpvCurrencyConversion(const std::string& ccy, const Handle<Quote>& conversion);
73
74private:
76 // populated during build()
77 std::vector<QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>> indices_;
78 std::vector<Real> weights_;
79 std::vector<Handle<Quote>> fxConversion_;
81};
82
83//! Equity Position instrument wrapper
84class EquityPositionInstrumentWrapper : public QuantLib::Instrument {
85public:
86 class arguments;
87 class results;
88 class engine;
89
90 EquityPositionInstrumentWrapper(const Real quantity,
91 const std::vector<QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>>& equities,
92 const std::vector<Real>& weights,
93 const std::vector<Handle<Quote>>& fxConversion = {});
94 //! \name Instrument interface
95 //@{
96 bool isExpired() const override;
98 void fetchResults(const QuantLib::PricingEngine::results*) const override;
99 //@}
100
101 void setNpvCurrencyConversion(const Handle<Quote>& npvCcyConversion);
102
103private:
104 void setupExpired() const override;
106 std::vector<QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>> equities_;
107 std::vector<Real> weights_;
108 std::vector<Handle<Quote>> fxConversion_;
109 Handle<Quote> npvCcyConversion_;
110};
111
113public:
115 std::vector<QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>> equities_;
116 std::vector<Real> weights_;
117 std::vector<Handle<Quote>> fxConversion_;
118 Handle<Quote> npvCcyConversion_;
119 void validate() const override {}
120};
121
122class EquityPositionInstrumentWrapper::results : public Instrument::results {
123public:
124 void reset() override {}
125};
126
128 : public QuantLib::GenericEngine<EquityPositionInstrumentWrapper::arguments,
129 EquityPositionInstrumentWrapper::results> {};
130
132public:
133 void calculate() const override;
134};
135
136} // namespace data
137} // namespace ore
Serializable object holding generic trade data, reporting dimensions.
Definition: envelope.hpp:51
Serializable Equity Position Data.
EquityPositionData(const Real quantity, const std::vector< EquityUnderlying > &underlyings)
const std::vector< EquityUnderlying > & underlyings() const
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
std::vector< EquityUnderlying > underlyings_
Serializable Equity Position.
std::map< AssetClass, std::set< std::string > > underlyingIndices(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
EquityPosition(const Envelope &env, const EquityPositionData &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 EquityPositionData & data() const
std::vector< QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > > indices_
const std::vector< Real > & weights() const
std::vector< Real > weights_
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
EquityPositionData data_
const std::vector< QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > > & indices() const
std::vector< QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > > equities_
Equity Position instrument wrapper.
void fetchResults(const QuantLib::PricingEngine::results *) const override
std::vector< QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > > equities_
std::vector< Handle< Quote > > fxConversion_
void setupArguments(QuantLib::PricingEngine::arguments *) const override
void setNpvCurrencyConversion(const Handle< Quote > &npvCcyConversion)
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
base trade data model and serialization