Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
exposureallocator.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 orea/aggregation/exposureallocator.hpp
20 \brief Exposure allocator
21 \ingroup analytics
22*/
23
24#pragma once
25
26#include <orea/cube/npvcube.hpp>
28
29namespace ore {
30namespace analytics {
31using namespace QuantLib;
32using namespace QuantExt;
33using namespace data;
34using namespace std;
35
36//! Exposure allocator base class
37/*!
38 Derived classes implement a constructor with the relevant additional input data
39 and a build function that performs the XVA calculations for all netting sets and
40 along all paths.
41*/
43public:
44
45 enum class AllocationMethod {
46 None,
47 Marginal, // Pykhtin & Rosen, 2010
51 };
52
54 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
55 const QuantLib::ext::shared_ptr<NPVCube>& tradeExposureCube,
56 const QuantLib::ext::shared_ptr<NPVCube>& nettedExposureCube,
57 const Size allocatedTradeEpeIndex = 2, const Size allocatedTradeEneIndex = 3,
58 const Size tradeEpeIndex = 0, const Size tradeEneIndex = 1,
59 const Size nettingSetEpeIndex = 1, const Size nettingSetEneIndex = 2);
60
61 virtual ~ExposureAllocator() {}
62 const QuantLib::ext::shared_ptr<NPVCube>& exposureCube() { return tradeExposureCube_; }
63 //! Compute exposures along all paths and fill result structures
64 virtual void build();
65
66
67protected:
68 virtual Real calculateAllocatedEpe(const string& tid, const string& nid, const Date& date, const Size sample) = 0;
69 virtual Real calculateAllocatedEne(const string& tid, const string& nid, const Date& date, const Size sample) = 0;
70 QuantLib::ext::shared_ptr<Portfolio> portfolio_;
71 QuantLib::ext::shared_ptr<NPVCube> tradeExposureCube_;
72 QuantLib::ext::shared_ptr<NPVCube> nettedExposureCube_;
80};
81
83public:
85 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
86 const QuantLib::ext::shared_ptr<NPVCube>& tradeExposureCube,
87 const QuantLib::ext::shared_ptr<NPVCube>& nettedExposureCube,
88 const QuantLib::ext::shared_ptr<NPVCube>& npvCube,
89 const Size allocatedTradeEpeIndex = 2, const Size allocatedTradeEneIndex = 3,
90 const Size tradeEpeIndex = 0, const Size tradeEneIndex = 1,
91 const Size nettingSetEpeIndex = 1, const Size nettingSetEneIndex = 2);
92
93protected:
94 virtual Real calculateAllocatedEpe(const string& tid, const string& nid, const Date& date, const Size sample) override;
95 virtual Real calculateAllocatedEne(const string& tid, const string& nid, const Date& date, const Size sample) override;
96 map<string, Real> tradeValueToday_;
99};
100
102public:
104 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
105 const QuantLib::ext::shared_ptr<NPVCube>& tradeExposureCube,
106 const QuantLib::ext::shared_ptr<NPVCube>& nettedExposureCube,
107 const QuantLib::ext::shared_ptr<NPVCube>& npvCube,
108 const Size allocatedTradeEpeIndex = 2, const Size allocatedTradeEneIndex = 3,
109 const Size tradeEpeIndex = 0, const Size tradeEneIndex = 1,
110 const Size nettingSetEpeIndex = 1, const Size nettingSetEneIndex = 2);
111
112protected:
113 virtual Real calculateAllocatedEpe(const string& tid, const string& nid, const Date& date, const Size sample) override;
114 virtual Real calculateAllocatedEne(const string& tid, const string& nid, const Date& date, const Size sample) override;
115 map<string, Real> tradeValueToday_;
116 map<string, Real> nettingSetValueToday_;
117};
118
120public:
122 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
123 const QuantLib::ext::shared_ptr<NPVCube>& tradeExposureCube,
124 const QuantLib::ext::shared_ptr<NPVCube>& nettedExposureCube,
125 const QuantLib::ext::shared_ptr<NPVCube>& npvCube,
126 const map<string, Real>& tradeCva,
127 const map<string, Real>& tradeDva,
128 const map<string, Real>& nettingSetSumCva,
129 const map<string, Real>& nettingSetSumDva,
130 const Size allocatedTradeEpeIndex = 2, const Size allocatedTradeEneIndex = 3,
131 const Size tradeEpeIndex = 0, const Size tradeEneIndex = 1,
132 const Size nettingSetEpeIndex = 0, const Size nettingSetEneIndex = 1);
133
134protected:
135 virtual Real calculateAllocatedEpe(const string& tid, const string& nid, const Date& date, const Size sample) override;
136 virtual Real calculateAllocatedEne(const string& tid, const string& nid, const Date& date, const Size sample) override;
137 map<string, Real> tradeCva_;
138 map<string, Real> tradeDva_;
139 map<string, Real> nettingSetSumCva_;
140 map<string, Real> nettingSetSumDva_;
141 map<string, Real> tradeValueToday_;
142};
143
145public:
147 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
148 const QuantLib::ext::shared_ptr<NPVCube>& tradeExposureCube,
149 const QuantLib::ext::shared_ptr<NPVCube>& nettedExposureCube);
150
151protected:
152 virtual Real calculateAllocatedEpe(const string& tid, const string& nid, const Date& date, const Size sample) override;
153 virtual Real calculateAllocatedEne(const string& tid, const string& nid, const Date& date, const Size sample) override;
154};
155
156//! Convert text representation to ExposureAllocator::AllocationMethod
158//! Convert ExposureAllocator::AllocationMethod to text representation
159std::ostream& operator<<(std::ostream& out, ExposureAllocator::AllocationMethod m);
160} // namespace analytics
161} // namespace ore
Exposure allocator base class.
QuantLib::ext::shared_ptr< NPVCube > tradeExposureCube_
const QuantLib::ext::shared_ptr< NPVCube > & exposureCube()
virtual Real calculateAllocatedEpe(const string &tid, const string &nid, const Date &date, const Size sample)=0
map< string, Real > nettingSetPositiveValueToday_
QuantLib::ext::shared_ptr< NPVCube > nettedExposureCube_
virtual void build()
Compute exposures along all paths and fill result structures.
QuantLib::ext::shared_ptr< Portfolio > portfolio_
virtual Real calculateAllocatedEne(const string &tid, const string &nid, const Date &date, const Size sample)=0
map< string, Real > nettingSetNegativeValueToday_
virtual Real calculateAllocatedEpe(const string &tid, const string &nid, const Date &date, const Size sample) override
virtual Real calculateAllocatedEne(const string &tid, const string &nid, const Date &date, const Size sample) override
virtual Real calculateAllocatedEpe(const string &tid, const string &nid, const Date &date, const Size sample) override
virtual Real calculateAllocatedEne(const string &tid, const string &nid, const Date &date, const Size sample) override
virtual Real calculateAllocatedEpe(const string &tid, const string &nid, const Date &date, const Size sample) override
virtual Real calculateAllocatedEne(const string &tid, const string &nid, const Date &date, const Size sample) override
virtual Real calculateAllocatedEpe(const string &tid, const string &nid, const Date &date, const Size sample) override
virtual Real calculateAllocatedEne(const string &tid, const string &nid, const Date &date, const Size sample) override
data
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
ExposureAllocator::AllocationMethod parseAllocationMethod(const string &s)
Convert text representation to ExposureAllocator::AllocationMethod.
The base NPV cube class.