Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
compositetrade.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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/compositetrade.hpp
18 \brief Composite trades operate as a mini portfolio.
19 Their intended use is for strategies like straddles.
20 \ingroup portfolio
21*/
22
23#pragma once
24
28#include <ostream>
29
30namespace ore {
31namespace data {
32using QuantLib::Date;
33using std::string;
34
35//! Composite Trade class
36/*! CompositeTrades are single currency strategies consisting of independent financial instruments but regarded as a
37 single position n the portfolio. Examples include straddles, butterflies, iron condors. The class can also be used to
38 create representations of single contracts which can be replicated by linear combinations of other positions. E.g. Bond
39 + Bond Option = Callable Bond. \ingroup portfolio
40*/
41class CompositeTrade : public Trade {
42public:
43 /// This enum decalres how the notional of the CompositeTrade should be calculated
45 Sum, ///< The notional is calculated as the sum of notionals of subtrades
46 Mean, ///< The notional is calculated as the average of notionals of subtrades
47 First, ///< The notional is taken as the first subtrade notional
48 Last, ///< The notional is taken as the last subtrade notional
49 Min, ///< The notional is taken as the minimum subtrade notional
50 Max, ///< The notional is taken as the maximum subtrade notional
51 Override ///< The notional is explicitly overridden
52 };
53
54 //! Constructor requires a trade factory so that subtrades can be built
56 : Trade("CompositeTrade", env, ta) {
57 reset();
58 }
59
60 //! Fully-specified Constructor
61 CompositeTrade(const string currency, const vector<QuantLib::ext::shared_ptr<Trade>>& trades,
62 const string notionalCalculation = "", const Real notionalOverride = 0.0,
63 const Envelope& env = Envelope(), const TradeActions& ta = TradeActions())
64 : Trade("CompositeTrade", env, ta), currency_(currency), notionalOverride_(notionalOverride),
66
67 //! Build QuantLib/QuantExt instrument, link pricing engine
68 virtual void build(const QuantLib::ext::shared_ptr<EngineFactory>&) override;
69 QuantLib::Real notional() const override;
70
71 //! \name Inspectors
72 //@{
73 const string& currency() const { return currency_; }
74 const string& portfolioId() const { return portfolioId_; }
75 const bool& portfolioBasket() const { return portfolioBasket_; }
76 const string& notionalCalculation() const { return notionalCalculation_; }
77 const vector<QuantLib::ext::shared_ptr<Trade>>& trades() const { return trades_; }
78 //@}
79
80 //! \name Utility functions
81 //@{
82 //! returns the number of subtrades in the strategy
83 Size size() const { return trades_.size(); }
84
85 //! calculates the CompositeTrade notional, when supplied with the notionals of the subtrades
86 Real calculateNotional(const vector<Real>& tradeNotionals) const;
87 //@}
88
89 //! \name Serialisation
90 //@{
91 virtual void fromXML(XMLNode* node) override;
92 virtual XMLNode* toXML(XMLDocument& doc) const override;
93 //@}
94
95 //! \name trade overrides
96 //@{
97 std::map<std::string, RequiredFixings::FixingDates> fixings(const QuantLib::Date& settlementDate) const override;
98 std::map<AssetClass, std::set<std::string>> underlyingIndices(const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceDataManager) const override;;
99 const std::map<std::string,boost::any>& additionalData() const override;
100 //@}
101
102private:
103
104 void populateFromReferenceData(const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceDataManager);
105 void getTradesFromReferenceData(const QuantLib::ext::shared_ptr<PortfolioBasketReferenceDatum>& ptfReferenceDatum);
106
107 string currency_;
110 vector<QuantLib::ext::shared_ptr<Trade>> trades_;
111 vector<Handle<Quote>> fxRates_, fxRatesNotional_;
114};
115
116} // namespace data
117} // namespace oreplus
Composite Trade class.
vector< Handle< Quote > > fxRatesNotional_
std::map< std::string, RequiredFixings::FixingDates > fixings(const QuantLib::Date &settlementDate) const override
const string & currency() const
const bool & portfolioBasket() const
Real calculateNotional(const vector< Real > &tradeNotionals) const
calculates the CompositeTrade notional, when supplied with the notionals of the subtrades
const string & portfolioId() const
const vector< QuantLib::ext::shared_ptr< Trade > > & trades() const
void getTradesFromReferenceData(const QuantLib::ext::shared_ptr< PortfolioBasketReferenceDatum > &ptfReferenceDatum)
vector< Handle< Quote > > fxRates_
CompositeTrade(const Envelope &env=Envelope(), const TradeActions &ta=TradeActions())
Constructor requires a trade factory so that subtrades can be built.
QuantLib::Real notional() const override
Return the current notional in npvCurrency. See individual sub-classes for the precise definition.
vector< QuantLib::ext::shared_ptr< Trade > > trades_
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const string & notionalCalculation() const
NotionalCalculation
This enum decalres how the notional of the CompositeTrade should be calculated.
@ Mean
The notional is calculated as the average of notionals of subtrades.
@ Max
The notional is taken as the maximum subtrade notional.
@ Override
The notional is explicitly overridden.
@ Min
The notional is taken as the minimum subtrade notional.
@ First
The notional is taken as the first subtrade notional.
@ Sum
The notional is calculated as the sum of notionals of subtrades.
@ Last
The notional is taken as the last subtrade notional.
void populateFromReferenceData(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager)
Size size() const
returns the number of subtrades in the strategy
CompositeTrade(const string currency, const vector< QuantLib::ext::shared_ptr< Trade > > &trades, const string notionalCalculation="", const Real notionalOverride=0.0, const Envelope &env=Envelope(), const TradeActions &ta=TradeActions())
Fully-specified Constructor.
std::map< AssetClass, std::set< std::string > > underlyingIndices(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager) const override
virtual void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
const std::map< std::string, boost::any > & additionalData() const override
returns all additional data returned by the trade once built
Serializable object holding generic trade data, reporting dimensions.
Definition: envelope.hpp:51
Serializable object holding generic trade actions.
Trade base class.
Definition: trade.hpp:55
void reset()
Reset trade, clear all base class data. This does not reset accumulated timings for this trade.
Definition: trade.cpp:130
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Reference data model and serialization.
base trade data model and serialization
Trade Factory.