Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
nettingsetdefinition.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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/nettingsetdefinition.hpp
20 \brief Netting Set Definition - including CSA information where available
21 \ingroup tradedata
22*/
23
24#pragma once
25
26#include <boost/optional.hpp>
29#include <ql/time/period.hpp>
30#include <ql/utilities/null.hpp>
31
33
34namespace ore {
35namespace data {
36using namespace QuantLib;
37
38class CSA {
39public:
40 /*!
41 Enumeration 'Type' specifies what type of
42 collateral agreement is in place.
43 - 'Bilateral' => both sides can request collateral margins
44 - 'PostOnly' => only the counterparty is allowed to issue a call for additional collateral
45 - 'CallOnly' => only WE are allowed to issue a margin call for additional collateral
46 */
48
49 CSA(const Type& type,
50 const string& csaCurrency, // three letter ISO code
51 const string& index, const Real& thresholdPay, const Real& thresholdRcv, const Real& mtaPay, const Real& mtaRcv,
52 const Real& iaHeld, const string& iaType, const Period& marginCallFreq, const Period& marginPostFreq,
53 const Period& mpr, const Real& collatSpreadPay, const Real& collatSpreadRcv,
54 const vector<string>& eligCollatCcys, // vector of three letter ISO codes
56 const string& nonExemptIMRegulations)
59 marginCallFreq_(marginCallFreq), marginPostFreq_(marginPostFreq), mpr_(mpr),
64
65 //! Inspectors
66 //@{
67 /*! Nature of CSA margining agreement (e.g. Bilateral, PostOnly, CallOnly) */
68 const Type& type() const { return type_; }
69 /*! Master Currency of CSA */
70 const string& csaCurrency() const { return csaCurrency_; }
71 /*! Index that determines the compounding rate */
72 const string& index() const { return index_; }
73 /*! Threshold amount for margin calls issued by counterparty */
74 Real thresholdPay() const { return thresholdPay_; }
75 /*! Threshold amount when issuing calls to counterparty */
76 Real thresholdRcv() const { return thresholdRcv_; }
77 /*! Minimum Transfer Amount when posting collateral to counterparty */
78 Real mtaPay() const { return mtaPay_; }
79 /*! Minimum Transfer Amount when receiving collateral from counterparty */
80 Real mtaRcv() const { return mtaRcv_; }
81 /*! Sum of Independent Amounts covered by the CSA (positive => we hold the amount) */
82 Real independentAmountHeld() const { return iaHeld_; }
83 /*! 'Type' of Independent Amount as specified in the CSA */
84 const string& independentAmountType() const { return iaType_; }
85 /*! Margining Frequency when requesting collateral from counterparty (e.g. "1D", "1W") */
86 const Period& marginCallFrequency() const { return marginCallFreq_; }
87 /*! Margining Frequency when counterparty is requesting collateral (e.g. "1D", "1W") */
88 const Period& marginPostFrequency() const { return marginPostFreq_; }
89 /*! Margin Period of Risk (e.g. "1M") */
90 const Period& marginPeriodOfRisk() const { return mpr_; }
91 /*! Spread for interest accrual on held collateral */
92 Real collatSpreadRcv() const { return collatSpreadRcv_; }
93 /*! Spread for interest accrual on posted collateral */
94 Real collatSpreadPay() const { return collatSpreadPay_; }
95 /*! Eligible Collateral Currencies */
96 vector<string> eligCollatCcys() const { return eligCollatCcys_; }
97 /*! Apply (dynamic) initial margin in addition to variation margin */
99 /*! Direction of (dynamic) initial margin */
101 //@}
102 /*! Calculate SIMM as IM (currently used only for SA-CCR) */
104 /*! Calculate VM from NPV (currently used only for SA-CCR) */
106 /*! IM regulations (whose trade sensitivities are usually exempt from margin/sensi calc) that we wish to include
107 (currently used only for SA-CCR) */
109 /*! invert all relevant aspects of the CSA */
110 void invertCSA();
111
112 void validate();
113
114private:
117 string index_;
123 string iaType_;
126 Period mpr_;
129 vector<string> eligCollatCcys_;
134};
135
136CSA::Type parseCsaType(const string& s);
137
138std::ostream& operator<<(std::ostream& out, CSA::Type t);
139
140//! Netting Set Definition
141/*!
142 This class is a container for a definition of a netting agreement (including CSA information)
143
144 \ingroup tradedata
145*/
147public:
148 /*!
149 builds a NettingSetDefinition from an XML input
150 */
152
153 /*!
154 Constructor for "uncollateralised" netting sets
155 */
159
160 /*!
161 Constructor for "collateralised" netting sets
162 */
163 NettingSetDefinition(const NettingSetDetails& nettingSetDetails, const string& bilateral,
164 const string& csaCurrency, // three letter ISO code
165 const string& index, const Real& thresholdPay, const Real& thresholdRcv, const Real& mtaPay,
166 const Real& mtaRcv, const Real& iaHeld, const string& iaType,
167 const string& marginCallFreq, // e.g. "1D", "2W", "3M", "4Y"
168 const string& marginPostFreq, // e.g. "1D", "2W", "3M", "4Y"
169 const string& mpr, // e.g. "1D", "2W", "3M", "4Y"
170 const Real& collatSpreadPay, const Real& collatSpreadRcv,
171 const vector<string>& eligCollatCcys, // vector of three letter ISO codes
172 bool applyInitialMargin = false, const string& initialMarginType = "Bilateral",
173 const bool calculateIMAmount = false, const bool calculateVMAmount = false,
174 const string& nonExemptIMRegulations = "");
175
176 NettingSetDefinition(const string& nettingSetId, const string& bilateral,
177 const string& csaCurrency, // three letter ISO code
178 const string& index, const Real& thresholdPay, const Real& thresholdRcv, const Real& mtaPay,
179 const Real& mtaRcv, const Real& iaHeld, const string& iaType,
180 const string& marginCallFreq, // e.g. "1D", "2W", "3M", "4Y"
181 const string& marginPostFreq, // e.g. "1D", "2W", "3M", "4Y"
182 const string& mpr, // e.g. "1D", "2W", "3M", "4Y"
183 const Real& collatSpreadPay, const Real& collatSpreadRcv,
184 const vector<string>& eligCollatCcys, // vector of three letter ISO codes
185 bool applyInitialMargin = false, const string& initialMarginType = "Bilateral",
186 const bool calculateIMAmount = false, const bool calculateVMAmount = false,
187 const string& nonExemptIMRegulations = "")
188 : NettingSetDefinition(NettingSetDetails(nettingSetId), bilateral, csaCurrency, index, thresholdPay,
189 thresholdRcv, mtaPay, mtaRcv, iaHeld, iaType, marginCallFreq, marginPostFreq, mpr,
190 collatSpreadPay, collatSpreadRcv, eligCollatCcys, applyInitialMargin, initialMarginType,
191 calculateIMAmount, calculateVMAmount, nonExemptIMRegulations) {}
192
193 /*!
194 loads NettingSetDefinition object from XML
195 */
196 void fromXML(XMLNode* node) override;
197 /*!
198 writes object to XML
199 */
200 XMLNode* toXML(XMLDocument& doc) const override;
201
202 /*!
203 validate the netting set definition including CSA details
204 */
205 void validate(); // contains "business logic" for more complete object definition
206
207 //! Inspectors
208 //@{
209 /*! returns netting set id */
210 const string& nettingSetId() const {
211 return (nettingSetDetails_.empty() ? nettingSetId_ : nettingSetDetails_.nettingSetId());
212 }
213 /*! returns netting set details */
214 const NettingSetDetails nettingSetDetails() const { return nettingSetDetails_; }
215 /*! boolean specifying if ISDA agreement is covered by a Credit Support Annex */
216 bool activeCsaFlag() const { return activeCsaFlag_; }
217 /*! CSA details, if active */
218 const QuantLib::ext::shared_ptr<CSA>& csaDetails() { return csa_; }
219
220 // /*! Nature of CSA margining agreement (e.g. Bilateral, PostOnly, CallOnly) */
221 // CSAType csaType() const {
222 // QL_REQUIRE(csaType_.is_initialized(), "csaType is not initialised");
223 // return csaType_.get();
224 // }
225
226 // /*! Master Currency of CSA */
227 // const string& csaCurrency() const { return csaCurrency_; }
228 // /*! Index that determines the compounding rate */
229 // const string& index() const { return index_; }
230 // /*! Threshold amount for margin calls issued by counterparty */
231 // Real thresholdPay() const { return thresholdPay_; }
232 // /*! Threshold amount when issuing calls to counterparty */
233 // Real thresholdRcv() const { return thresholdRcv_; }
234 // /*! Minimum Transfer Amount when posting collateral to counterparty */
235 // Real mtaPay() const { return mtaPay_; }
236 // /*! Minimum Transfer Amount when receiving collateral from counterparty */
237 // Real mtaRcv() const { return mtaRcv_; }
238 // /*! Sum of Independent Amounts covered by the CSA (positive => we hold the amount) */
239 // Real independentAmountHeld() const { return iaHeld_; }
240 // /*! 'Type' of Independent Amount as specified in the CSA */
241 // const string& independentAmountType() const { return iaType_; }
242 // /*! Margining Frequency when requesting collateral from counterparty (e.g. "1D", "1W") */
243 // const Period& marginCallFrequency() const { return marginCallFreq_; }
244 // /*! Margining Frequency when counterparty is requesting collateral (e.g. "1D", "1W") */
245 // const Period& marginPostFrequency() const { return marginPostFreq_; }
246 // /*! Margin Period of Risk (e.g. "1M") */
247 // const Period& marginPeriodOfRisk() const { return mpr_; }
248 // /*! Spread for interest accrual on held collateral */
249 // Real collatSpreadRcv() const { return collatSpreadRcv_; }
250 // /*! Spread for interest accrual on posted collateral */
251 // Real collatSpreadPay() const { return collatSpreadPay_; }
252 // /*! Eligible Collateral Currencies */
253 // vector<string> eligCollatCcys() const { return eligCollatCcys_; }
254 // /*! Apply (dynamic) initial margin in addition to variation margin */
255 // bool applyInitialMargin() { return applyInitialMargin_; }
256 // //@}
257
258private:
259 string nettingSetId_;
260 NettingSetDetails nettingSetDetails_;
261 bool activeCsaFlag_;
262 QuantLib::ext::shared_ptr<CSA> csa_;
263
264 // string csaTypeStr_; // staging value for csaType_
265 // boost::optional<CSAType> csaType_; // initialised during build()
266 // string csaCurrency_;
267 // string index_;
268 // Real thresholdPay_;
269 // Real thresholdRcv_;
270 // Real mtaPay_;
271 // Real mtaRcv_;
272 // Real iaHeld_;
273 // string iaType_;
274 // string marginCallFreqStr_; // staging value for marginCallFreq_
275 // string marginPostFreqStr_; // staging value for marginPostFreq_
276 // Period marginCallFreq_; // initialised during build()
277 // Period marginPostFreq_; // initialised during build()
278 // string mprStr_; // staging value for mpr_
279 // Period mpr_; // initialised during build()
280 // Real collatSpreadPay_;
281 // Real collatSpreadRcv_;
282 // vector<string> eligCollatCcys_;
283 // bool applyInitialMargin_;
284 // bool calculateIMAmount_
285 // bool calculateVMAmount_
286};
287} // namespace data
288} // namespace ore
const Period & marginPeriodOfRisk() const
const string & independentAmountType() const
const Type & type() const
Inspectors.
Real thresholdPay() const
const string & csaCurrency() const
CSA(const Type &type, const string &csaCurrency, const string &index, const Real &thresholdPay, const Real &thresholdRcv, const Real &mtaPay, const Real &mtaRcv, const Real &iaHeld, const string &iaType, const Period &marginCallFreq, const Period &marginPostFreq, const Period &mpr, const Real &collatSpreadPay, const Real &collatSpreadRcv, const vector< string > &eligCollatCcys, bool applyInitialMargin, Type initialMarginType, const bool calculateIMAmount, const bool calculateVMAmount, const string &nonExemptIMRegulations)
const string & index() const
Real collatSpreadPay() const
vector< string > eligCollatCcys() const
Real collatSpreadRcv() const
const string & nonExemptIMRegulations()
Real independentAmountHeld() const
vector< string > eligCollatCcys_
Real thresholdRcv() const
const Period & marginPostFrequency() const
const Period & marginCallFrequency() const
const QuantLib::ext::shared_ptr< CSA > & csaDetails()
const NettingSetDetails nettingSetDetails() const
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
NettingSetDefinition(const string &nettingSetId)
const string & nettingSetId() const
Inspectors.
NettingSetDefinition(const string &nettingSetId, const string &bilateral, const string &csaCurrency, const string &index, const Real &thresholdPay, const Real &thresholdRcv, const Real &mtaPay, const Real &mtaRcv, const Real &iaHeld, const string &iaType, const string &marginCallFreq, const string &marginPostFreq, const string &mpr, const Real &collatSpreadPay, const Real &collatSpreadRcv, const vector< string > &eligCollatCcys, bool applyInitialMargin=false, const string &initialMarginType="Bilateral", const bool calculateIMAmount=false, const bool calculateVMAmount=false, const string &nonExemptIMRegulations="")
Serializable object holding netting set identification data.
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
Base class for all serializable classes.
Definition: xmlutils.hpp:101
@ data
Definition: log.hpp:77
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
CSA::Type parseCsaType(const string &s)
Serializable Credit Default Swap.
Definition: namespaces.docs:23
netting set details data model and serialization
XML utility functions.