20#include <ql/errors.hpp>
39 : csaDef_(csaDef), balance_t0_(0.0) {
46 : csaDef_(csaDef), balance_t0_(balance_t0) {
53 QL_REQUIRE(
marginCalls_[i].openMarginRequest(),
"CollateralAccount error, expired margin call found"
54 <<
" (should have been purged after expiry)");
57 "CollateralAccount error; vector of margin calls not sorted correctly");
65 "CollateralAccount error; balance update failed due to invalid dates");
68 Real accrualRate = (
accountBalances_.back() >= 0.0) ? (annualisedZeroRate -
csaDef_->csaDetails()->collatSpreadRcv())
69 : (annualisedZeroRate -
csaDef_->csaDetails()->collatSpreadPay());
84 Real accrualRate = (
accountBalances_.back() >= 0.0) ? (annualisedZeroRate -
csaDef_->csaDetails()->collatSpreadRcv())
85 : (annualisedZeroRate -
csaDef_->csaDetails()->collatSpreadPay());
93 <<
"attempting to load expired margin call");
96 "CollateralAccount error, attempting to issue an old margin call");
99 "CollateralAccount error, old margin call being loaded");
107 const Date& marginRequestDate) {
108 MarginCall newMarginCall(marginFlowAmount, marginPayDate, marginRequestDate);
110 "CollateralAccount error, attempting to issue an old margin call");
115 QL_REQUIRE(
accountDates_.front() <= date,
"CollateralAccount error, invalid date for balance request");
126 QL_FAIL(
"CollateralAccount error, balance not found for date " << date);
130 Real outstandingMarginCallAmounts = 0.0;
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();
139 return outstandingMarginCallAmounts;
143 QL_REQUIRE(closeDate >
accountDates_.back(),
"CollateralAccount error, invalid date "
144 <<
" for closure of Collateral Account");
Date marginPayDate() const
Date marginRequestDate() const
bool openMarginRequest() const
Inspectors.
void updateMarginCall(const MarginCall &newMarginCall)
Real outstandingMarginAmount(const Date &simulationDate) const
vector< MarginCall > marginCalls_
void updateAccountBalance(const Date &simulationDate, const Real &annualisedZeroRate=0.0)
Real accountBalance() const
vector< Real > accountBalances_
QuantLib::ext::shared_ptr< NettingSetDefinition > csaDef_
vector< Date > accountDates_
CollateralAccount()
Default constructor.
void closeAccount(const Date &closeDate)
Collateral Account Balance (stored in base currency)