31 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
32 const QuantLib::ext::shared_ptr<NPVCube>& tradeExposureCube,
33 const QuantLib::ext::shared_ptr<NPVCube>& nettedExposureCube,
34 const Size allocatedTradeEpeIndex,
const Size allocatedTradeEneIndex,
35 const Size tradeEpeIndex,
const Size tradeEneIndex,
36 const Size nettingSetEpeIndex,
const Size nettingSetEneIndex)
37 : portfolio_(portfolio), tradeExposureCube_(tradeExposureCube),
38 nettedExposureCube_(nettedExposureCube),
39 tradeEpeIndex_(tradeEpeIndex), tradeEneIndex_(tradeEneIndex),
40 allocatedTradeEpeIndex_(allocatedTradeEpeIndex), allocatedTradeEneIndex_(allocatedTradeEneIndex),
41 nettingSetEpeIndex_(nettingSetEpeIndex), nettingSetEneIndex_(nettingSetEneIndex) {}
44 LOG(
"Compute allocated trade exposures");
48 for (
const auto & [tid, trade] :
portfolio_->trades()) {
49 string nid = trade->envelope().nettingSetId();
50 if (nid != nettingSetId)
64 LOG(
"Completed calculating allocated trade exposures");
68 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
69 const QuantLib::ext::shared_ptr<NPVCube>& tradeExposureCube,
70 const QuantLib::ext::shared_ptr<NPVCube>& nettedExposureCube,
71 const QuantLib::ext::shared_ptr<NPVCube>& npvCube,
72 const Size allocatedTradeEpeIndex,
const Size allocatedTradeEneIndex,
73 const Size tradeEpeIndex,
const Size tradeEneIndex,
74 const Size nettingSetEpeIndex,
const Size nettingSetEneIndex)
76 allocatedTradeEpeIndex, allocatedTradeEneIndex,
77 tradeEpeIndex, tradeEneIndex,
78 nettingSetEpeIndex, nettingSetEneIndex) {
80 for (
auto tradeIt =
portfolio_->trades().begin(); tradeIt !=
portfolio_->trades().end(); ++tradeIt, ++i) {
81 auto trade = tradeIt->second;
82 string tradeId = tradeIt->first;
83 string nettingSetId = trade->envelope().nettingSetId();
88 Real npv = npvCube->getT0(i);
98 const Date& date,
const Size sample) {
106 const Date& date,
const Size sample) {
114 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
115 const QuantLib::ext::shared_ptr<NPVCube>& tradeExposureCube,
116 const QuantLib::ext::shared_ptr<NPVCube>& nettedExposureCube,
117 const QuantLib::ext::shared_ptr<NPVCube>& npvCube,
118 const Size allocatedTradeEpeIndex,
const Size allocatedTradeEneIndex,
119 const Size tradeEpeIndex,
const Size tradeEneIndex,
120 const Size nettingSetEpeIndex,
const Size nettingSetEneIndex)
122 allocatedTradeEpeIndex, allocatedTradeEneIndex,
123 tradeEpeIndex, tradeEneIndex,
124 nettingSetEpeIndex, nettingSetEneIndex) {
126 for (
auto tradeIt =
portfolio_->trades().begin(); tradeIt !=
portfolio_->trades().end(); ++tradeIt, ++i) {
127 auto trade = tradeIt->second;
128 string tradeId = tradeIt->first;
129 string nettingSetId = trade->envelope().nettingSetId();
132 Real npv = npvCube->getT0(i);
139 const Date& date,
const Size sample) {
147 const Date& date,
const Size sample) {
155 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
156 const QuantLib::ext::shared_ptr<NPVCube>& tradeExposureCube,
157 const QuantLib::ext::shared_ptr<NPVCube>& nettedExposureCube,
158 const QuantLib::ext::shared_ptr<NPVCube>& npvCube,
159 const map<string, Real>& tradeCva,
160 const map<string, Real>& tradeDva,
161 const map<string, Real>& nettingSetSumCva,
162 const map<string, Real>& nettingSetSumDva,
163 const Size allocatedTradeEpeIndex,
const Size allocatedTradeEneIndex,
164 const Size tradeEpeIndex,
const Size tradeEneIndex,
165 const Size nettingSetEpeIndex,
const Size nettingSetEneIndex)
167 allocatedTradeEpeIndex, allocatedTradeEneIndex,
168 tradeEpeIndex, tradeEneIndex,
169 nettingSetEpeIndex, nettingSetEneIndex),
170 tradeCva_(tradeCva), tradeDva_(tradeDva),
171 nettingSetSumCva_(nettingSetSumCva), nettingSetSumDva_(nettingSetSumDva) {}
174 const Date& date,
const Size sample) {
179 const Date& date,
const Size sample) {
185 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
186 const QuantLib::ext::shared_ptr<NPVCube>& tradeExposureCube,
187 const QuantLib::ext::shared_ptr<NPVCube>& nettedExposureCube)
191 const Date& date,
const Size sample) {
195 const Date& date,
const Size sample) {
200 static map<string, ExposureAllocator::AllocationMethod> m = {
212 QL_FAIL(
"AllocationMethod \"" << s <<
"\" not recognized");
222 out <<
"RelativeFairValueGross";
224 out <<
"RelativeFairValueNet";
226 out <<
"RelativeXVA";
228 QL_FAIL(
"Allocation method not covered");
Exposure allocator base class.
Size allocatedTradeEneIndex_
QuantLib::ext::shared_ptr< NPVCube > tradeExposureCube_
virtual Real calculateAllocatedEpe(const string &tid, const string &nid, const Date &date, const Size sample)=0
QuantLib::ext::shared_ptr< NPVCube > nettedExposureCube_
virtual void build()
Compute exposures along all paths and fill result structures.
QuantLib::ext::shared_ptr< Portfolio > portfolio_
Size allocatedTradeEpeIndex_
ExposureAllocator(const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< NPVCube > &tradeExposureCube, const QuantLib::ext::shared_ptr< NPVCube > &nettedExposureCube, const Size allocatedTradeEpeIndex=2, const Size allocatedTradeEneIndex=3, const Size tradeEpeIndex=0, const Size tradeEneIndex=1, const Size nettingSetEpeIndex=1, const Size nettingSetEneIndex=2)
virtual Real calculateAllocatedEne(const string &tid, const string &nid, const Date &date, const Size sample)=0
virtual Real calculateAllocatedEpe(const string &tid, const string &nid, const Date &date, const Size sample) override
NoneExposureAllocator(const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< NPVCube > &tradeExposureCube, const QuantLib::ext::shared_ptr< NPVCube > &nettedExposureCube)
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
map< string, Real > nettingSetValueToday_
map< string, Real > tradeValueToday_
virtual Real calculateAllocatedEne(const string &tid, const string &nid, const Date &date, const Size sample) override
RelativeFairValueGrossExposureAllocator(const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< NPVCube > &tradeExposureCube, const QuantLib::ext::shared_ptr< NPVCube > &nettedExposureCube, const QuantLib::ext::shared_ptr< NPVCube > &npvCube, const Size allocatedTradeEpeIndex=2, const Size allocatedTradeEneIndex=3, const Size tradeEpeIndex=0, const Size tradeEneIndex=1, const Size nettingSetEpeIndex=1, const Size nettingSetEneIndex=2)
virtual Real calculateAllocatedEpe(const string &tid, const string &nid, const Date &date, const Size sample) override
map< string, Real > nettingSetPositiveValueToday_
map< string, Real > tradeValueToday_
virtual Real calculateAllocatedEne(const string &tid, const string &nid, const Date &date, const Size sample) override
RelativeFairValueNetExposureAllocator(const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< NPVCube > &tradeExposureCube, const QuantLib::ext::shared_ptr< NPVCube > &nettedExposureCube, const QuantLib::ext::shared_ptr< NPVCube > &npvCube, const Size allocatedTradeEpeIndex=2, const Size allocatedTradeEneIndex=3, const Size tradeEpeIndex=0, const Size tradeEneIndex=1, const Size nettingSetEpeIndex=1, const Size nettingSetEneIndex=2)
map< string, Real > nettingSetNegativeValueToday_
map< string, Real > nettingSetSumCva_
virtual Real calculateAllocatedEpe(const string &tid, const string &nid, const Date &date, const Size sample) override
map< string, Real > nettingSetSumDva_
RelativeXvaExposureAllocator(const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< NPVCube > &tradeExposureCube, const QuantLib::ext::shared_ptr< NPVCube > &nettedExposureCube, const QuantLib::ext::shared_ptr< NPVCube > &npvCube, const map< string, Real > &tradeCva, const map< string, Real > &tradeDva, const map< string, Real > &nettingSetSumCva, const map< string, Real > &nettingSetSumDva, const Size allocatedTradeEpeIndex=2, const Size allocatedTradeEneIndex=3, const Size tradeEpeIndex=0, const Size tradeEneIndex=1, const Size nettingSetEpeIndex=0, const Size nettingSetEneIndex=1)
map< string, Real > tradeDva_
map< string, Real > tradeCva_
virtual Real calculateAllocatedEne(const string &tid, const string &nid, const Date &date, const Size sample) override
A cube implementation that stores the cube in memory.
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
ExposureAllocator::AllocationMethod parseAllocationMethod(const string &s)
Convert text representation to ExposureAllocator::AllocationMethod.