Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
collatexposurehelper.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 orea/aggregation/collatexposurehelper.hpp
20 \brief Collateral Exposure Helper Functions (stored in base currency)
21 \ingroup analytics
22*/
23
24#pragma once
25
28#include <ql/handle.hpp>
29#include <ql/termstructures/yieldtermstructure.hpp>
30#include <ql/time/date.hpp>
31
32namespace ore {
33namespace analytics {
34using namespace QuantLib;
35using namespace data;
36
37//! Collateral Exposure Helper
38/*!
39 This class contains helper functions to aid in the calculation
40 of collateralised exposures.
41
42 It can be used to calculate margin requirements in the presence of
43 e.g. thresholds and minimum transfer amounts, update collateral
44 account details with e.g. new margin call info, and return
45 collateralised exposures to the user/invoker.
46
47 For further information refer to the detailed ORE documentation.
48
49 \ingroup analytics
50*/
52public:
53 /*!
54 Enumeration 'CalculationType' specifies how the collateralised
55 exposures should be calculated (please refer to Sungard white-paper
56 titled "Closing In On the CloseOut"):
57 - 'Symmetric' => margin calls only settled after margin period of risk
58 - 'AsymmetricCVA' => margin requested from ctp only settles after margin period of risk
59 -- (our margin postings settle instantaneously)
60 - 'AsymmetricDVA' => margin postings to ctp only settle after margin period of risk
61 -- (margin calls to receive collateral from counterparty settle instantaneously)
62 - 'NoLag' => margin calls/postings settled without margin period of risk delay
63 */
65
66 /*!
67 Calculates CSA margin requirement, taking the following into account
68 - uncollateralised value
69 - collateral value
70 - threshold
71 - minimum transfer amount
72 - independent amount
73 */
74 static Real marginRequirementCalc(const QuantLib::ext::shared_ptr<CollateralAccount>& collat, const Real& uncollatValue,
75 const Date& simulationDate);
76
77 /*!
78 Performs linear interpolation between dates to
79 estimate the value as of simulationDate.
80 Flat extrapolation at far end.
81 */
82 template <class T>
83 static Real estimateUncollatValue(const Date& simulationDate, const Real& npv_t0, const Date& date_t0,
84 const vector<vector<T>>& scenPvProfiles, const unsigned& scenIndex,
85 const vector<Date>& dateGrid);
86
87 /*!
88 Checks if margin call is in need of update, and updates if necessary
89 */
90 static void updateMarginCall(const QuantLib::ext::shared_ptr<CollateralAccount>& collat, const Real& uncollatValue,
91 const Date& simulationDate, const Real& accrualFactor,
92 const CalculationType& calcType = Symmetric, const bool& eligMarginReqDateUs = true,
93 const bool& eligMarginReqDateCtp = true);
94
95 /*!
96 Computes the Credit Support Amount for the portfolio, given an unsecured exposure as input
97 All calculations done in CSA currency
98 */
99 static Real creditSupportAmount(
100 const QuantLib::ext::shared_ptr<ore::data::NettingSetDefinition>& nettingSet,
101 const Real& uncollatValueCsaCur);
102
103 /*!
104 Takes a netting set (and scenario exposures) as input
105 and returns collateral balance paths per scenario
106 */
107 static QuantLib::ext::shared_ptr<vector<QuantLib::ext::shared_ptr<CollateralAccount>>> collateralBalancePaths(
108 const QuantLib::ext::shared_ptr<NettingSetDefinition>& csaDef, const Real& nettingSetPv, const Date& date_t0,
109 const vector<vector<Real>>& nettingSetValues, const Date& nettingSet_maturity, const vector<Date>& dateGrid,
110 const Real& csaFxTodayRate, const vector<vector<Real>>& csaFxScenarioRates, const Real& csaTodayCollatCurve,
111 const vector<vector<Real>>& csaScenCollatCurves, const CalculationType& calcType = Symmetric,
112 const QuantLib::ext::shared_ptr<CollateralBalance>& balance = QuantLib::ext::shared_ptr<CollateralBalance>());
113};
114
115//! Convert text representation to CollateralExposureHelper::CalculationType
117} // namespace analytics
118} // namespace ore
static void updateMarginCall(const QuantLib::ext::shared_ptr< CollateralAccount > &collat, const Real &uncollatValue, const Date &simulationDate, const Real &accrualFactor, const CalculationType &calcType=Symmetric, const bool &eligMarginReqDateUs=true, const bool &eligMarginReqDateCtp=true)
static Real creditSupportAmount(const QuantLib::ext::shared_ptr< ore::data::NettingSetDefinition > &nettingSet, const Real &uncollatValueCsaCur)
static Real estimateUncollatValue(const Date &simulationDate, const Real &npv_t0, const Date &date_t0, const vector< vector< T > > &scenPvProfiles, const unsigned &scenIndex, const vector< Date > &dateGrid)
static Real marginRequirementCalc(const QuantLib::ext::shared_ptr< CollateralAccount > &collat, const Real &uncollatValue, const Date &simulationDate)
static QuantLib::ext::shared_ptr< vector< QuantLib::ext::shared_ptr< CollateralAccount > > > collateralBalancePaths(const QuantLib::ext::shared_ptr< NettingSetDefinition > &csaDef, const Real &nettingSetPv, const Date &date_t0, const vector< vector< Real > > &nettingSetValues, const Date &nettingSet_maturity, const vector< Date > &dateGrid, const Real &csaFxTodayRate, const vector< vector< Real > > &csaFxScenarioRates, const Real &csaTodayCollatCurve, const vector< vector< Real > > &csaScenCollatCurves, const CalculationType &calcType=Symmetric, const QuantLib::ext::shared_ptr< CollateralBalance > &balance=QuantLib::ext::shared_ptr< CollateralBalance >())
Collateral Account Balance (stored in base currency)
data
CollateralExposureHelper::CalculationType parseCollateralCalculationType(const string &s)
Convert text representation to CollateralExposureHelper::CalculationType.