Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
riskparticipationagreement.hpp
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
19/*! \file riskparticipationagreement.hpp
20 \brief RPA instrument
21*/
22
23#pragma once
24
25#include <ql/cashflow.hpp>
26#include <ql/exercise.hpp>
27#include <ql/instrument.hpp>
28#include <ql/position.hpp>
29#include <ql/pricingengine.hpp>
30
31namespace QuantExt {
32
33using namespace QuantLib;
34
35class RiskParticipationAgreement : public QuantLib::Instrument {
36public:
37 class arguments;
38 class results;
39 class engine;
40 RiskParticipationAgreement(const std::vector<Leg>& underlying, const std::vector<bool>& underlyingPayer,
41 const std::vector<std::string>& underlyingCcys, const std::vector<Leg>& protectionFee,
42 const bool protectionFeePayer, const std::vector<std::string>& protectionFeeCcys,
43 const Real participationRate, const Date& protectionStart, const Date& protectionEnd,
44 const bool settlesAccrual, const Real fixedRecoveryRate = Null<Real>(),
45 const QuantLib::ext::shared_ptr<QuantLib::Exercise>& exercise = nullptr,
46 const bool exerciseIsLong = false, const std::vector<QuantLib::ext::shared_ptr<CashFlow>>& premium = std::vector<QuantLib::ext::shared_ptr<CashFlow>>(),
47 const bool nakedOption = false);
48 //! Instrument interface
49 bool isExpired() const override;
50
51 //! Inspectors
52 const std::vector<Leg>& underlying() const { return underlying_; }
53 const std::vector<bool>& underlyingPayer() const { return underlyingPayer_; }
54 const std::vector<std::string>& underlyingCcys() const { return underlyingCcys_; }
55 const std::vector<Leg>& protectionFee() const { return protectionFee_; }
56 bool protectionFeePayer() const { return protectionFeePayer_; }
57 const std::vector<std::string>& protectionFeeCcys() const { return protectionFeeCcys_; }
58 Real participationRate() const { return participationRate_; }
59 const Date& protectionStart() const { return protectionStart_; }
60 const Date& protectionEnd() const { return protectionEnd_; }
61 bool settlesAccrual() const { return settlesAccrual_; }
62 Real fixedRecoveryRate() const { return fixedRecoveryRate_; }
63 const QuantLib::ext::shared_ptr<Exercise>& exercise() const { return exercise_; }
64 const bool nakedOption() const { return nakedOption_; }
65 //
66 const Date& maturity() const { return maturity_; }
67 const Date& underlyingMaturity() const { return underlyingMaturity_; }
68
69private:
71 void setupExpired() const override;
72 void fetchResults(const QuantLib::PricingEngine::results*) const override;
73 //
74 const std::vector<Leg> underlying_;
75 const std::vector<bool> underlyingPayer_;
76 const std::vector<std::string> underlyingCcys_;
77 const std::vector<Leg> protectionFee_;
79 const std::vector<std::string> protectionFeeCcys_;
82 const bool settlesAccrual_;
84 const QuantLib::ext::shared_ptr<Exercise> exercise_;
85 const bool exerciseIsLong_;
86 const std::vector<QuantLib::ext::shared_ptr<CashFlow>> premium_;
87 const bool nakedOption_;
88
89 //
91 // internal additional results that are passed back to the engine via the arguments
92 // this might or might not be populated / used by an engine
94 mutable std::vector<std::tuple<Date, Date, Date>> optionRepresentationPeriods_;
95 mutable std::vector<QuantLib::ext::shared_ptr<Instrument>> optionRepresentation_;
96 mutable std::vector<Real> optionMultiplier_;
97};
98
100public:
102 void validate() const override {}
103 std::vector<Leg> underlying;
104 std::vector<bool> underlyingPayer;
105 std::vector<std::string> underlyingCcys;
106 std::vector<Leg> protectionFee;
108 std::vector<std::string> protectionFeeCcys;
113 QuantLib::ext::shared_ptr<Exercise> exercise;
115 std::vector<QuantLib::ext::shared_ptr<CashFlow>> premium;
117 std::vector<QuantLib::ext::shared_ptr<Instrument>> optionRepresentation;
118 std::vector<Real> optionMultiplier;
119 std::vector<std::tuple<Date, Date, Date>> optionRepresentationPeriods;
121};
122
124public:
125 std::vector<QuantLib::ext::shared_ptr<Instrument>> optionRepresentation;
126 std::vector<Real> optionMultiplier;
127 std::vector<std::tuple<Date, Date, Date>> optionRepresentationPeriods;
129 void reset() override {
130 Instrument::results::reset();
131 optionRepresentation.clear();
132 optionMultiplier.clear();
135 }
136};
137
139 : public GenericEngine<RiskParticipationAgreement::arguments, RiskParticipationAgreement::results> {};
140
141} // 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_
const std::vector< std::string > & protectionFeeCcys() const
const QuantLib::ext::shared_ptr< Exercise > & exercise() const
const std::vector< std::string > & underlyingCcys() const
const std::vector< bool > & underlyingPayer() const
const std::vector< Leg > & protectionFee() const
void setupArguments(QuantLib::PricingEngine::arguments *) const override