Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
riskparticipationagreement_tlock.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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
20
21#include <ql/cashflows/cashflows.hpp>
22#include <ql/cashflows/fixedratecoupon.hpp>
23#include <ql/event.hpp>
24
25namespace QuantExt {
26
28 const QuantLib::ext::shared_ptr<QuantLib::Bond>& bond, Real bondNotional, bool payer, Real referenceRate,
29 const DayCounter& dayCounter, const Date& terminationDate, const Date& paymentDate,
30 const std::vector<Leg>& protectionFee, const bool protectionFeePayer,
31 const std::vector<std::string>& protectionFeeCcys, const Real participationRate, const Date& protectionStart,
32 const Date& protectionEnd, const bool settlesAccrual, const Real fixedRecoveryRate)
33 : bond_(bond), bondNotional_(bondNotional), payer_(payer), referenceRate_(referenceRate), dayCounter_(dayCounter),
34 terminationDate_(terminationDate), paymentDate_(paymentDate), protectionFee_(protectionFee),
35 protectionFeePayer_(protectionFeePayer), protectionFeeCcys_(protectionFeeCcys),
36 participationRate_(participationRate), protectionStart_(protectionStart), protectionEnd_(protectionEnd),
37 settlesAccrual_(settlesAccrual), fixedRecoveryRate_(fixedRecoveryRate) {
38
39 // checks
40
41 QL_REQUIRE(bond != nullptr, "RiskParticipationAgreementTLock: underlying bond is null");
42 QL_REQUIRE(!dayCounter.empty(), "RiskParticipationAgreementTLock: day counter is empty");
43
44 QL_REQUIRE(paymentDate_ >= terminationDate, "RiskParticipationAgreementTLock: payment date ("
45 << paymentDate_ << ") must be >= termination date ("
46 << terminationDate_ << ")");
47 QL_REQUIRE(protectionFee_.size() == protectionFeeCcys_.size(),
48 "protection fee size (" << protectionFee_.size() << ") must match protecttion fee ccys size ("
49 << protectionFeeCcys_.size() << ")");
50 QL_REQUIRE(participationRate_ > 0.0 || close_enough(participationRate_, 0.0),
51 "participation rate must be non-negative (" << participationRate_ << ")");
53 "protection end (" << protectionEnd_ << ") must be greater than protection start " << protectionStart_);
54
55 for (auto const& c : bond->cashflows()) {
56 if (auto tmp = QuantLib::ext::dynamic_pointer_cast<Coupon>(c)) {
57 QL_REQUIRE(QuantLib::ext::dynamic_pointer_cast<FixedRateCoupon>(c),
58 "RiskParticipationAgreementTLock: only fixed rate coupons allowed in bond underlying");
59 }
60 }
61
62 // the maturity is the maximum of the protection end date and fee payment dates
63
65 for (auto const& p : protectionFee)
66 maturity_ = std::max(maturity_, CashFlows::maturityDate(p));
67
68 // register with observables
69
70 for (auto const& l : protectionFee)
71 for (auto const& c : l)
72 registerWith(c);
73}
74
75bool RiskParticipationAgreementTLock::isExpired() const { return detail::simple_event(maturity_).hasOccurred(); }
76
77void RiskParticipationAgreementTLock::setupExpired() const { Instrument::setupExpired(); }
78
82 QL_REQUIRE(arguments, "RiskParticipationAgreement::setupArguments(): wrong argument type");
90
99}
100
101void RiskParticipationAgreementTLock::fetchResults(const PricingEngine::results* r) const {
102 Instrument::fetchResults(r);
103}
104
105} // namespace QuantExt
void fetchResults(const QuantLib::PricingEngine::results *) const override
bool isExpired() const override
Instrument interface.
const QuantLib::ext::shared_ptr< QuantLib::Bond > & bond() const
Inspectors.
RiskParticipationAgreementTLock(const QuantLib::ext::shared_ptr< QuantLib::Bond > &bond, Real bondNotional, bool payer, Real referenceRate, const DayCounter &dayCounter, const Date &terminationDate, const Date &paymentDate, const std::vector< Leg > &protectionFee, const bool protectionFeePayer, const std::vector< std::string > &protectionFeeCcys, const Real participationRate, const Date &protectionStart, const Date &protectionEnd, const bool settlesAccrual, const Real fixedRecoveryRate=Null< Real >())
void setupArguments(QuantLib::PricingEngine::arguments *) const override
QuantLib::ext::shared_ptr< QuantLib::Bond > bond_
const Bond & bond_
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
RPA instrument for tlock underlyings.