Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fdconvertiblebondevents.hpp
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
19/*! \file qle/pricingengines/fdconvertiblebondevents.hpp */
20
21#pragma once
22
24
27
28#include <ql/math/array.hpp>
29#include <ql/math/matrix.hpp>
30#include <ql/timegrid.hpp>
31
32namespace QuantExt {
33
34using QuantLib::DayCounter;
35using QuantLib::TimeGrid;
36
38public:
39 // represents call and put rights
40 struct CallData {
41 Real price;
44 bool isSoft;
46 // make whole result of cr increase as a function of stock price and current cr
47 std::function<Real(Real, Real)> mwCr;
48 };
49
50 // represents voluntary conversion with coco barrier
53 };
54
55 // represents mandatory conversion
61 };
62
63 /* represents
64 1) conversion ratio resets or
65 2) dividend protection with conversion ratio adjustments or
66 3) conversion ratio change if an event of type 1) or 2) preceeds this change, because
67 in this case we need to handle it differently from a simple determinisitic cr change */
69
70 // conversion ratio reset
71 bool resetActive = false;
73 Real gearing; // > 0
74 Real floor, globalFloor; // zero if not applicable
75 Real threshold; // > 0
76
77 // dividend protection with conversion ratio adjustment
78 bool divProtActive = false;
80 adjustmentStyle; // CrUpOnly, CrUpDown, CrUpOnly2, CrUpDown2
84 Real divThreshold; // > 0
85
86 // reset of cr to specific value
88 Real newCr;
89 };
90
91 // represents dividend protection with div pass through
94 adjustmentStyle; // PassThroughUpOnly, PassThroughUpDown
95 ConvertibleBond2::DividendProtectionData::DividendType dividendType; // Absolute, Relative (remove, not needed?)
99 };
100
101 FdConvertibleBondEvents(const Date& today, const DayCounter& dc, const Real N0,
102 const QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>& equity,
103 const QuantLib::ext::shared_ptr<FxIndex>& fxConversion);
104
105 // The intended workflow is as follows:
106
107 // 1 register events describing the convertible bond features and cashflows
108 void registerBondCashflow(const QuantLib::ext::shared_ptr<CashFlow>& c);
117
118 // 2 get the times associated to the events, i.e. the mandatory times for the PDE grid
119 const std::set<Real>& times() const;
120
121 // 3 call finalise w.r.t. the desired time grid t_0, ..., t_n
122 void finalise(const TimeGrid& grid);
123
124 // 4 get event information per time index i for time t_i and event number j
125 bool hasBondCashflow(const Size i) const;
126 bool hasCall(const Size i) const;
127 bool hasPut(const Size i) const;
128 bool hasConversion(const Size i) const;
129 bool hasMandatoryConversion(const Size i) const;
130 bool hasContingentConversion(const Size i) const;
131 bool hasNoConversionPlane(const Size i) const; // true => barrier check is done on next date in the past where false
132 bool hasConversionReset(const Size i) const; // due to conv reset or div prot with cr adj
133 bool hasDividendPassThrough(const Size i) const;
134
135 Real getBondCashflow(const Size i) const;
136 Real getBondFinalRedemption(const Size i) const;
137 const CallData& getCallData(const Size i) const;
138 const CallData& getPutData(const Size i) const;
139 const ConversionData& getConversionData(const Size i) const; // conv reset or div prot with cr adj
140 const MandatoryConversionData& getMandatoryConversionData(const Size i) const;
141 const ConversionResetData& getConversionResetData(const Size i) const;
142 const DividendPassThroughData& getDividendPassThroughData(const Size i) const;
143
144 bool hasStochasticConversionRatio(const Size i) const; // populated for all i
145 Real getInitialConversionRatio() const; // initial conv ratio, even if in the past
146 Real getCurrentConversionRatio(const Size i) const; // populated for all i
147 Real getCurrentFxConversion(const Size i) const; // populated for all i
148 Date getAssociatedDate(const Size i) const; // null if no date is associated
149
150 const std::map<std::string, boost::any>& additionalResults() const { return additionalResults_; }
151
152private:
153 Date nextExerciseDate(const Date& d, const std::vector<ConvertibleBond2::CallabilityData>& data) const;
154 Date nextConversionDate(const Date& d) const;
155
156 Real time(const Date& d) const;
157
159 void processExerciseData(const std::vector<ConvertibleBond2::CallabilityData>& sourceData,
160 std::vector<bool>& targetFlags, std::vector<CallData>& targetData);
164
165 Date today_;
166 DayCounter dc_;
167 Real N0_;
168 QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> equity_;
169 QuantLib::ext::shared_ptr<FxIndex> fxConversion_;
170
171 std::set<Real> times_;
172 TimeGrid grid_;
173 bool finalised_ = false;
174
176
177 // the registered events (before finalise())
178 std::vector<QuantLib::ext::shared_ptr<CashFlow>> registeredBondCashflows_;
179 std::vector<ConvertibleBond2::CallabilityData> registeredCallData_, registeredPutData_;
180 std::vector<ConvertibleBond2::ConversionRatioData> registeredConversionRatioData_;
181 std::vector<ConvertibleBond2::ConversionData> registeredConversionData_;
182 std::vector<ConvertibleBond2::MandatoryConversionData> registeredMandatoryConversionData_;
183 std::vector<ConvertibleBond2::ConversionResetData> registeredConversionResetData_;
184 std::vector<ConvertibleBond2::DividendProtectionData> registeredDividendProtectionData_;
186
187 // per time index i flags to indicate events
188 std::vector<bool> hasBondCashflow_, hasCall_, hasPut_;
191 std::vector<bool> hasDividendPassThrough_;
192
193 // per time index the data associated to events
195 std::vector<CallData> callData_, putData_;
196 std::vector<ConversionData> conversionData_;
197 std::vector<MandatoryConversionData> mandatoryConversionData_;
198 std::vector<ConversionResetData> conversionResetData_;
199 std::vector<DividendPassThroughData> dividendPassThroughData_;
200
201 std::vector<bool> stochasticConversionRatio_; // filled for all i
203 std::vector<Real> currentConversionRatio_; // filled for all i
204 std::vector<Real> currentFxConversion_; // filled for all i
205 std::vector<Date> associatedDate_;
206
207 // additional results provided by the event processor
208 std::map<std::string, boost::any> additionalResults_;
209
210 // containers to store interpolation data for mw cr increases
211 QuantLib::Array mw_cr_inc_x_, mw_cr_inc_y_;
212 QuantLib::Matrix mw_cr_inc_z_;
213};
214
215} // namespace QuantExt
bool hasDividendPassThrough(const Size i) const
std::vector< ConvertibleBond2::CallabilityData > registeredCallData_
bool hasMandatoryConversion(const Size i) const
bool hasContingentConversion(const Size i) const
const std::set< Real > & times() const
Date nextConversionDate(const Date &d) const
void registerMandatoryConversion(const ConvertibleBond2::MandatoryConversionData &c)
void registerBondCashflow(const QuantLib::ext::shared_ptr< CashFlow > &c)
Date nextExerciseDate(const Date &d, const std::vector< ConvertibleBond2::CallabilityData > &data) const
QuantLib::ext::shared_ptr< FxIndex > fxConversion_
void registerConversionReset(const ConvertibleBond2::ConversionResetData &c)
std::vector< QuantLib::ext::shared_ptr< CashFlow > > registeredBondCashflows_
std::vector< ConvertibleBond2::MandatoryConversionData > registeredMandatoryConversionData_
std::map< std::string, boost::any > additionalResults_
std::vector< ConvertibleBond2::ConversionRatioData > registeredConversionRatioData_
std::vector< DividendPassThroughData > dividendPassThroughData_
const ConversionResetData & getConversionResetData(const Size i) const
std::vector< ConversionData > conversionData_
void registerPut(const ConvertibleBond2::CallabilityData &c)
Real getCurrentFxConversion(const Size i) const
void registerConversion(const ConvertibleBond2::ConversionData &c)
const MandatoryConversionData & getMandatoryConversionData(const Size i) const
void registerConversionRatio(const ConvertibleBond2::ConversionRatioData &c)
std::vector< ConvertibleBond2::ConversionData > registeredConversionData_
std::vector< ConvertibleBond2::CallabilityData > registeredPutData_
std::vector< MandatoryConversionData > mandatoryConversionData_
void registerCall(const ConvertibleBond2::CallabilityData &c)
std::vector< ConversionResetData > conversionResetData_
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > equity_
void processExerciseData(const std::vector< ConvertibleBond2::CallabilityData > &sourceData, std::vector< bool > &targetFlags, std::vector< CallData > &targetData)
Real getCurrentConversionRatio(const Size i) const
std::vector< ConvertibleBond2::ConversionResetData > registeredConversionResetData_
const ConversionData & getConversionData(const Size i) const
std::vector< ConvertibleBond2::DividendProtectionData > registeredDividendProtectionData_
const std::map< std::string, boost::any > & additionalResults() const
const DividendPassThroughData & getDividendPassThroughData(const Size i) const
const CallData & getCallData(const Size i) const
ConvertibleBond2::MakeWholeData registeredMakeWholeData_
Real getBondFinalRedemption(const Size i) const
const CallData & getPutData(const Size i) const
bool hasStochasticConversionRatio(const Size i) const
void registerDividendProtection(const ConvertibleBond2::DividendProtectionData &c)
void registerMakeWhole(const ConvertibleBond2::MakeWholeData &c)
equity index class for holding equity fixing histories and forwarding.
FX index class.
ConvertibleBond2::CallabilityData::PriceType priceType
ConvertibleBond2::DividendProtectionData::AdjustmentStyle adjustmentStyle
ConvertibleBond2::DividendProtectionData::DividendType dividendType
ConvertibleBond2::ConversionResetData::ReferenceType reference
ConvertibleBond2::DividendProtectionData::AdjustmentStyle adjustmentStyle
ConvertibleBond2::DividendProtectionData::DividendType dividendType