Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityposition.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 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/commodityposition.hpp
20 \brief Commodity Position trade data model and serialization
21 \ingroup tradedata
22 */
23
24#pragma once
25
29
30namespace ore {
31namespace data {
32
33//! Serializable Commodity Position Data
35public:
37 CommodityPositionData(const Real quantity, const std::vector<CommodityUnderlying>& underlyings)
39
40 Real quantity() const { return quantity_; }
41 const std::vector<CommodityUnderlying>& 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<CommodityUnderlying> underlyings_;
49};
50
51//! Serializable Commodity Position
52class CommodityPosition : public Trade {
53public:
54 CommodityPosition() : Trade("CommodityPosition") {}
55 CommodityPosition(const Envelope& env, const CommodityPositionData& data) : Trade("CommodityPosition", 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 CommodityPositionData& data() const { return data_; }
66 const std::vector<QuantLib::ext::shared_ptr<QuantExt::CommodityIndex>>& 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::CommodityIndex>> indices_;
78 std::vector<Real> weights_;
79 std::vector<Handle<Quote>> fxConversion_;
81};
82
83//! Commodity Position instrument wrapper
84class CommodityPositionInstrumentWrapper : public QuantLib::Instrument {
85public:
86 class arguments;
87 class results;
88 class engine;
89
90 CommodityPositionInstrumentWrapper(const Real quantity,
91 const std::vector<QuantLib::ext::shared_ptr<QuantExt::CommodityIndex>>& commodities,
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::CommodityIndex>> commodities_;
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::CommodityIndex>> commodities_;
116 std::vector<Real> weights_;
117 std::vector<Handle<Quote>> fxConversion_;
118 Handle<Quote> npvCcyConversion_;
119 void validate() const override {}
120};
121
122class CommodityPositionInstrumentWrapper::results : public Instrument::results {
123public:
124 void reset() override {}
125};
126
128 : public QuantLib::GenericEngine<CommodityPositionInstrumentWrapper::arguments,
129 CommodityPositionInstrumentWrapper::results> {};
130
132public:
133 void calculate() const override;
134};
135
136} // namespace data
137} // namespace ore
Serializable Commodity Position Data.
const std::vector< CommodityUnderlying > & underlyings() const
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
std::vector< CommodityUnderlying > underlyings_
CommodityPositionData(const Real quantity, const std::vector< CommodityUnderlying > &underlyings)
Serializable Commodity Position.
std::vector< QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > > indices_
const std::vector< QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > > & indices() const
const CommodityPositionData & data() const
std::map< AssetClass, std::set< std::string > > underlyingIndices(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
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 > & weights() const
CommodityPosition(const Envelope &env, const CommodityPositionData &data)
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
std::vector< QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > > commodities_
Commodity Position instrument wrapper.
void fetchResults(const QuantLib::PricingEngine::results *) const override
std::vector< QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > > commodities_
void setupArguments(QuantLib::PricingEngine::arguments *) const override
void setNpvCurrencyConversion(const Handle< Quote > &npvCcyConversion)
Serializable object holding generic trade data, reporting dimensions.
Definition: envelope.hpp:51
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
underlying data model