Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
riskparticipationagreement.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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/event.hpp>
23
24namespace QuantExt {
25
27 const std::vector<Leg>& underlying, const std::vector<bool>& underlyingPayer,
28 const std::vector<std::string>& underlyingCcys, const std::vector<Leg>& protectionFee,
29 const bool protectionFeePayer, const std::vector<std::string>& protectionFeeCcys, const Real participationRate,
30 const Date& protectionStart, const Date& protectionEnd, const bool settlesAccrual, const Real fixedRecoveryRate,
31 const QuantLib::ext::shared_ptr<Exercise>& exercise, const bool exerciseIsLong, const std::vector<QuantLib::ext::shared_ptr<CashFlow>>& premium, const bool nakedOption)
32 : underlying_(underlying), underlyingPayer_(underlyingPayer), underlyingCcys_(underlyingCcys),
33 protectionFee_(protectionFee), protectionFeePayer_(protectionFeePayer), protectionFeeCcys_(protectionFeeCcys),
34 participationRate_(participationRate), protectionStart_(protectionStart), protectionEnd_(protectionEnd),
35 settlesAccrual_(settlesAccrual), fixedRecoveryRate_(fixedRecoveryRate), exercise_(exercise),
36 exerciseIsLong_(exerciseIsLong), premium_(premium), nakedOption_(nakedOption) {
37
38 QL_REQUIRE(underlying_.size() == underlyingPayer_.size(),
39 "underlying size (" << underlying_.size() << ") must match underlying payer size ("
40 << underlyingPayer_.size() << ")");
41 QL_REQUIRE(underlying_.size() == underlyingCcys_.size(),
42 "underlying size (" << underlying_.size() << ") must match underlying ccys size ("
43 << underlyingCcys_.size() << ")");
44 QL_REQUIRE(!underlying_.empty(), "underlying is empty");
45 QL_REQUIRE(protectionFee_.size() == protectionFeeCcys_.size(),
46 "protection fee size (" << protectionFee_.size() << ") must match protecttion fee ccys size ("
47 << protectionFeeCcys_.size() << ")");
48 QL_REQUIRE(participationRate_ > 0.0 || close_enough(participationRate_, 0.0),
49 "participation rate must be non-negative (" << participationRate_ << ")");
51 "protection end (" << protectionEnd_ << ") must be greater than protection start " << protectionStart_);
52
53 // the maturity is the maximum of the protection end date and the last fee cashflow payment date
55 for (auto const& p : protectionFee) {
56 if (!p.empty())
57 maturity_ = std::max(maturity_, CashFlows::maturityDate(p));
58 }
59
60 // the underlying maturity is the maturity over the underlying legs
61 underlyingMaturity_ = Date::minDate();
62 for (auto const& l : underlying)
63 underlyingMaturity_ = std::max(underlyingMaturity_, CashFlows::maturityDate(l));
64
65 for (auto const& l : underlying) {
66 for (auto const& c : l) {
67 registerWith(c);
68 if (auto lazy = QuantLib::ext::dynamic_pointer_cast<LazyObject>(c))
69 lazy->alwaysForwardNotifications();
70 }
71 }
72
73 for (auto const& l : protectionFee) {
74 for (auto const& c : l) {
75 registerWith(c);
76 if (auto lazy = QuantLib::ext::dynamic_pointer_cast<LazyObject>(c))
77 lazy->alwaysForwardNotifications();
78 }
79 }
80}
81
82bool RiskParticipationAgreement::isExpired() const { return detail::simple_event(maturity()).hasOccurred(); }
83
85 Instrument::setupExpired();
87 optionMultiplier_.clear();
90}
91
94 QL_REQUIRE(arguments, "RiskParticipationAgreement::setupArguments(): wrong argument type");
111 // provide previously computed option representation, if this is available
116}
117
118void RiskParticipationAgreement::fetchResults(const PricingEngine::results* r) const {
119 Instrument::fetchResults(r);
121 QL_REQUIRE(results, "RiskParticipationAgreement::fetchResults(): wrong result type");
122 // might be empty / null if engine does not provide these
127}
128
129} // namespace QuantExt
std::vector< QuantLib::ext::shared_ptr< CashFlow > > premium
std::vector< QuantLib::ext::shared_ptr< Instrument > > optionRepresentation
std::vector< std::tuple< Date, Date, Date > > optionRepresentationPeriods
std::vector< QuantLib::ext::shared_ptr< Instrument > > optionRepresentation
std::vector< std::tuple< Date, Date, Date > > optionRepresentationPeriods
void fetchResults(const QuantLib::PricingEngine::results *) const override
const std::vector< std::string > protectionFeeCcys_
const std::vector< Leg > & underlying() const
Inspectors.
bool isExpired() const override
Instrument interface.
std::vector< QuantLib::ext::shared_ptr< Instrument > > optionRepresentation_
const QuantLib::ext::shared_ptr< Exercise > exercise_
const std::vector< std::string > underlyingCcys_
std::vector< std::tuple< Date, Date, Date > > optionRepresentationPeriods_
const std::vector< QuantLib::ext::shared_ptr< CashFlow > > premium_
RiskParticipationAgreement(const std::vector< Leg > &underlying, const std::vector< bool > &underlyingPayer, const std::vector< std::string > &underlyingCcys, 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 >(), const QuantLib::ext::shared_ptr< QuantLib::Exercise > &exercise=nullptr, const bool exerciseIsLong=false, const std::vector< QuantLib::ext::shared_ptr< CashFlow > > &premium=std::vector< QuantLib::ext::shared_ptr< CashFlow > >(), const bool nakedOption=false)
const std::vector< Leg > & protectionFee() const
void setupArguments(QuantLib::PricingEngine::arguments *) const override
Filter close_enough(const RandomVariable &x, const RandomVariable &y)