Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Attributes | List of all members
CollateralAccount Class Reference

Collateral Account. More...

#include <orea/aggregation/collateralaccount.hpp>

+ Collaboration diagram for CollateralAccount:

Classes

class  MarginCall
 Margin Call. More...
 

Public Member Functions

 CollateralAccount ()
 Default constructor. More...
 
 CollateralAccount (const QuantLib::ext::shared_ptr< NettingSetDefinition > &csaDef, const Date &date_t0)
 Constructor assuming initial collateral account balance is zero. More...
 
 CollateralAccount (const QuantLib::ext::shared_ptr< NettingSetDefinition > &csaDef, const Real &balance_t0, const Date &date_t0)
 Constructor taking an initial collateral account balance. More...
 
QuantLib::ext::shared_ptr< NettingSetDefinitioncsaDef () const
 Inspectors. More...
 
Real balance_t0 () const
 
Real accountBalance () const
 
Real accountBalance (const Date &date) const
 
Date balanceDate () const
 
Real outstandingMarginAmount (const Date &simulationDate) const
 
void updateAccountBalance (const Date &simulationDate, const Real &annualisedZeroRate=0.0)
 
void updateMarginCall (const MarginCall &newMarginCall)
 
void updateMarginCall (const Real &marginFlowAmount, const Date &marginPayDate, const Date &marginRequestDate)
 
void closeAccount (const Date &closeDate)
 

Private Attributes

QuantLib::ext::shared_ptr< NettingSetDefinitioncsaDef_
 
Real balance_t0_
 
vector< Real > accountBalances_
 
vector< Date > accountDates_
 
vector< MarginCallmarginCalls_
 

Detailed Description

Collateral Account.

This class holds information corresponding to collateral cash accounts. It stores a balance as well as an asof date for the balance. The class also includes "margin" information relating to the most recent margin call (e.g. call amount, status, expected pay date.

The idea is that this class can be updated on-the-run with new margin requirements and collateral balances, and the timestamps updated accordingly.

For further information refer to the detailed ORE documentation.

Definition at line 53 of file collateralaccount.hpp.

Constructor & Destructor Documentation

◆ CollateralAccount() [1/3]

Default constructor.

Definition at line 56 of file collateralaccount.hpp.

56{}

◆ CollateralAccount() [2/3]

CollateralAccount ( const QuantLib::ext::shared_ptr< NettingSetDefinition > &  csaDef,
const Date &  date_t0 
)

Constructor assuming initial collateral account balance is zero.

Parameters
csaDefCSA details including threshold, minimum transfer amount, margining frequency etc
date_t0Today's date

Definition at line 38 of file collateralaccount.cpp.

39 : csaDef_(csaDef), balance_t0_(0.0) {
41 accountDates_.push_back(date_t0);
42}
QuantLib::ext::shared_ptr< NettingSetDefinition > csaDef_
QuantLib::ext::shared_ptr< NettingSetDefinition > csaDef() const
Inspectors.

◆ CollateralAccount() [3/3]

CollateralAccount ( const QuantLib::ext::shared_ptr< NettingSetDefinition > &  csaDef,
const Real &  balance_t0,
const Date &  date_t0 
)

Constructor taking an initial collateral account balance.

Parameters
csaDefCSA details including threshold, minimum transfer amount, margining frequency etc
balance_t0Initial collateral account balance
date_t0Today's date

Definition at line 44 of file collateralaccount.cpp.

48 accountDates_.push_back(date_t0);
49}

Member Function Documentation

◆ csaDef()

QuantLib::ext::shared_ptr< NettingSetDefinition > csaDef ( ) const

Inspectors.

csa (netting set) definition

Definition at line 105 of file collateralaccount.hpp.

105{ return csaDef_; }

◆ balance_t0()

Real balance_t0 ( ) const

account balance at start date

Definition at line 107 of file collateralaccount.hpp.

107{ return balance_t0_; }

◆ accountBalance() [1/2]

Real accountBalance ( ) const

most up-to-date account balance

Definition at line 109 of file collateralaccount.hpp.

109{ return accountBalances_.back(); }
+ Here is the caller graph for this function:

◆ accountBalance() [2/2]

Real accountBalance ( const Date &  date) const

account balance as of requested date

Definition at line 114 of file collateralaccount.cpp.

114 {
115 QL_REQUIRE(accountDates_.front() <= date, "CollateralAccount error, invalid date for balance request");
116 if (date >= accountDates_.back())
117 return accountBalances_.back(); // flat extrapolation at far end
118 for (unsigned i = 0; i < accountDates_.size(); i++) {
119 if (date == accountDates_[i])
120 return accountBalances_[i];
121 else if (date > accountDates_[i] && date < accountDates_[i + 1])
122 return accountBalances_[i];
123 else
124 continue;
125 }
126 QL_FAIL("CollateralAccount error, balance not found for date " << date);
127}

◆ balanceDate()

Date balanceDate ( ) const

most recent account balance reset date

Definition at line 113 of file collateralaccount.hpp.

113{ return accountDates_.back(); }

◆ outstandingMarginAmount()

Real outstandingMarginAmount ( const Date &  simulationDate) const

Returns the sum of all outstanding margin call amounts

Definition at line 129 of file collateralaccount.cpp.

129 {
130 Real outstandingMarginCallAmounts = 0.0;
131 for (unsigned i = 0; i < marginCalls_.size(); i++) {
132 QL_REQUIRE(marginCalls_[i].openMarginRequest(), "CollateralAccount error, expired margin call found"
133 << " (should have been purged after expiry)");
134 QL_REQUIRE(marginCalls_[i].marginPayDate() > simulationDate,
135 "CollateralAccount error, old margin call pay date,"
136 << " (should have been settled before now)");
137 outstandingMarginCallAmounts += marginCalls_[i].marginAmount();
138 }
139 return outstandingMarginCallAmounts;
140}

◆ updateAccountBalance()

void updateAccountBalance ( const Date &  simulationDate,
const Real &  annualisedZeroRate = 0.0 
)

Updates the account balance, does this by checking if any outstanding margin calls are due for settlement.

Note
The accrual rate is assumed to be compounded daily

Definition at line 51 of file collateralaccount.cpp.

51 {
52 for (unsigned i = 0; i < marginCalls_.size(); i++) {
53 QL_REQUIRE(marginCalls_[i].openMarginRequest(), "CollateralAccount error, expired margin call found"
54 << " (should have been purged after expiry)");
55 if (i != marginCalls_.size() - 1) {
56 QL_REQUIRE(marginCalls_[i].marginPayDate() <= marginCalls_[i + 1].marginPayDate(),
57 "CollateralAccount error; vector of margin calls not sorted correctly");
58 }
59
60 if (marginCalls_[i].marginPayDate() <= simulationDate) {
61 if (marginCalls_[i].marginPayDate() == accountDates_.back()) {
62 accountBalances_.back() += marginCalls_[i].marginAmount();
63 } else {
64 QL_REQUIRE(marginCalls_[i].marginPayDate() > accountDates_.back(),
65 "CollateralAccount error; balance update failed due to invalid dates");
66 int accrualDays = marginCalls_[i].marginPayDate() - accountDates_.back();
67 // apply "effective" accrual rate (i.e. adjust for spread specified in netting set definition)
68 Real accrualRate = (accountBalances_.back() >= 0.0) ? (annualisedZeroRate - csaDef_->csaDetails()->collatSpreadRcv())
69 : (annualisedZeroRate - csaDef_->csaDetails()->collatSpreadPay());
70 // bring collateral account up to margin payment date (note accrual rate is assumed to be compounded
71 // daily)
72 accountBalances_.push_back(accountBalances_.back() * std::pow(1.0 + accrualRate / 365.0, accrualDays) +
73 marginCalls_[i].marginAmount());
74 accountDates_.push_back(marginCalls_[i].marginPayDate());
75 }
76 marginCalls_[i] = MarginCall(0.0, Date(), Date(), false);
77 }
78 }
79 marginCalls_.erase(std::remove_if(marginCalls_.begin(), marginCalls_.end(), isMarginCallExpired),
80 marginCalls_.end());
81 if (simulationDate > accountDates_.back()) { // bring the collateral account up to simulation date
82 int accrualDays = simulationDate - accountDates_.back();
83 // apply "effective" accrual rate (i.e. adjust for spread specified in netting set definition)
84 Real accrualRate = (accountBalances_.back() >= 0.0) ? (annualisedZeroRate - csaDef_->csaDetails()->collatSpreadRcv())
85 : (annualisedZeroRate - csaDef_->csaDetails()->collatSpreadPay());
86 accountDates_.push_back(simulationDate);
87 accountBalances_.push_back(accountBalances_.back() * std::pow(1.0 + accrualRate / 365.0, accrualDays));
88 }
89}

◆ updateMarginCall() [1/2]

void updateMarginCall ( const MarginCall newMarginCall)

Updates the margin call details for this account

Definition at line 91 of file collateralaccount.cpp.

91 {
92 QL_REQUIRE(newMarginCall.openMarginRequest() == true, "CollateralAccount error, "
93 << "attempting to load expired margin call");
94 if (marginCalls_.size() > 0) {
95 QL_REQUIRE(marginCalls_.back().marginRequestDate() < newMarginCall.marginRequestDate(),
96 "CollateralAccount error, attempting to issue an old margin call");
97 }
98 QL_REQUIRE(newMarginCall.marginRequestDate() >= accountDates_.back(),
99 "CollateralAccount error, old margin call being loaded");
100
101 marginCalls_.push_back(newMarginCall);
102 // sorts the vector of margin calls according to ascending pay-date
103 std::sort(marginCalls_.begin(), marginCalls_.end(), isMarginPayDateLessThan);
104}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateMarginCall() [2/2]

void updateMarginCall ( const Real &  marginFlowAmount,
const Date &  marginPayDate,
const Date &  marginRequestDate 
)

Definition at line 106 of file collateralaccount.cpp.

107 {
108 MarginCall newMarginCall(marginFlowAmount, marginPayDate, marginRequestDate);
109 QL_REQUIRE(newMarginCall.marginRequestDate() <= newMarginCall.marginPayDate(),
110 "CollateralAccount error, attempting to issue an old margin call");
111 updateMarginCall(newMarginCall);
112}
void updateMarginCall(const MarginCall &newMarginCall)
+ Here is the call graph for this function:

◆ closeAccount()

void closeAccount ( const Date &  closeDate)

Closes the account as of a given date (i.e. sets the balance to zero)

Definition at line 142 of file collateralaccount.cpp.

142 {
143 QL_REQUIRE(closeDate > accountDates_.back(), "CollateralAccount error, invalid date "
144 << " for closure of Collateral Account");
145 marginCalls_.clear();
146 accountBalances_.push_back(0.0);
147 accountDates_.push_back(closeDate);
148}

Member Data Documentation

◆ csaDef_

QuantLib::ext::shared_ptr<NettingSetDefinition> csaDef_
private

Definition at line 139 of file collateralaccount.hpp.

◆ balance_t0_

Real balance_t0_
private

Definition at line 140 of file collateralaccount.hpp.

◆ accountBalances_

vector<Real> accountBalances_
private

Definition at line 141 of file collateralaccount.hpp.

◆ accountDates_

vector<Date> accountDates_
private

Definition at line 142 of file collateralaccount.hpp.

◆ marginCalls_

vector<MarginCall> marginCalls_
private

Definition at line 143 of file collateralaccount.hpp.