Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
DiscretizedConvertible Class Reference

#include <qle/pricingengines/discretizedconvertible.hpp>

+ Inheritance diagram for DiscretizedConvertible:
+ Collaboration diagram for DiscretizedConvertible:

Public Member Functions

 DiscretizedConvertible (const ConvertibleBond::option::arguments &args, const ext::shared_ptr< GeneralizedBlackScholesProcess > &process, const Handle< Quote > &creditSpread, const TimeGrid &grid)
 
void reset (Size size) override
 
const Array & conversionProbability () const
 
Array & conversionProbability ()
 
const Array & spreadAdjustedRate () const
 
Array & spreadAdjustedRate ()
 
const Array & dividendValues () const
 
Array & dividendValues ()
 
std::vector< Time > mandatoryTimes () const override
 

Protected Member Functions

void postAdjustValuesImpl () override
 

Protected Attributes

Array conversionProbability_
 
Array spreadAdjustedRate_
 
Array dividendValues_
 

Private Member Functions

Array adjustedGrid () const
 
void applyConvertibility ()
 
void applyCallability (Size, bool convertible)
 
void addCashflow (Size)
 
Real getConversionRatio (const Real t) const
 

Private Attributes

ConvertibleBond::option::arguments arguments_
 
QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > process_
 
Handle< Quote > creditSpread_
 
std::vector< Time > stoppingTimes_
 
std::vector< Time > callabilityTimes_
 
std::vector< Time > cashflowTimes_
 
std::vector< Time > dividendTimes_
 
std::vector< Time > notionalTimes_
 

Detailed Description

Definition at line 33 of file discretizedconvertible.hpp.

Constructor & Destructor Documentation

◆ DiscretizedConvertible()

DiscretizedConvertible ( const ConvertibleBond::option::arguments args,
const ext::shared_ptr< GeneralizedBlackScholesProcess > &  process,
const Handle< Quote > &  creditSpread,
const TimeGrid &  grid 
)

Definition at line 27 of file discretizedconvertible.cpp.

30 : arguments_(args), process_(process), creditSpread_(creditSpread) {
31
32 dividendValues_ = Array(arguments_.dividends.size(), 0.0);
33
34 Date settlementDate = process_->riskFreeRate()->referenceDate();
35 for (Size i = 0; i < arguments_.dividends.size(); i++) {
36 if (arguments_.dividends[i]->date() >= settlementDate) {
38 arguments_.dividends[i]->amount() * process_->riskFreeRate()->discount(arguments_.dividends[i]->date());
39 }
40 }
41
42 DayCounter dayCounter = process_->riskFreeRate()->dayCounter();
43 Date bondSettlement = arguments_.settlementDate;
44
45 stoppingTimes_.resize(arguments_.exercise->dates().size());
46 for (Size i = 0; i < stoppingTimes_.size(); ++i)
47 stoppingTimes_[i] = dayCounter.yearFraction(bondSettlement, arguments_.exercise->date(i));
48
50 for (Size i = 0; i < callabilityTimes_.size(); ++i)
51 callabilityTimes_[i] = dayCounter.yearFraction(bondSettlement, arguments_.callabilityDates[i]);
52
54 for (Size i = 0; i < cashflowTimes_.size(); ++i) {
55 cashflowTimes_[i] = dayCounter.yearFraction(bondSettlement, arguments_.cashflowDates[i]);
56 }
57
59 for (Size i = 0; i < dividendTimes_.size(); ++i)
60 dividendTimes_[i] = dayCounter.yearFraction(bondSettlement, arguments_.dividendDates[i]);
61
62 if (!grid.empty()) {
63 // adjust times to grid
64 for (Size i = 0; i < stoppingTimes_.size(); i++)
65 stoppingTimes_[i] = grid.closestTime(stoppingTimes_[i]);
66 for (Size i = 0; i < cashflowTimes_.size(); i++)
67 cashflowTimes_[i] = grid.closestTime(cashflowTimes_[i]);
68 for (Size i = 0; i < callabilityTimes_.size(); i++)
69 callabilityTimes_[i] = grid.closestTime(callabilityTimes_[i]);
70 for (Size i = 0; i < dividendTimes_.size(); i++)
71 dividendTimes_[i] = grid.closestTime(dividendTimes_[i]);
72 }
73
74 notionalTimes_.clear();
75 for (auto const& d : arguments_.notionalDates) {
76 notionalTimes_.push_back(grid.closestTime(dayCounter.yearFraction(bondSettlement, d)));
77 }
78}
ConvertibleBond::option::arguments arguments_
QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > process_

Member Function Documentation

◆ reset()

void reset ( Size  size)
override

Definition at line 92 of file discretizedconvertible.cpp.

92 {
93
94 // Set cashflow on last date
95 values_ = Array(size, 0.0);
96 for (Size i = 0; i < cashflowTimes_.size(); ++i) {
98 values_ += arguments_.cashflowAmounts[i];
99 }
100 }
101
102 conversionProbability_ = Array(size, 0.0);
103 spreadAdjustedRate_ = Array(size, 0.0);
104
105 DayCounter rfdc = process_->riskFreeRate()->dayCounter();
106
107 // this takes care of convertibility and conversion probabilities
108 adjustValues();
109
110 Real creditSpread = creditSpread_->value();
111 Rate riskFreeRate = process_->riskFreeRate()->zeroRate(arguments_.maturityDate, rfdc, Continuous, NoFrequency);
112
113 // Calculate blended discount rate to be used on roll back.
114 for (Size j = 0; j < values_.size(); j++) {
116 conversionProbability_[j] * riskFreeRate + (1 - conversionProbability_[j]) * (riskFreeRate + creditSpread);
117 }
118}
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
+ Here is the call graph for this function:

◆ conversionProbability() [1/2]

const Array & conversionProbability ( ) const

Definition at line 41 of file discretizedconvertible.hpp.

41{ return conversionProbability_; }
+ Here is the caller graph for this function:

◆ conversionProbability() [2/2]

Array & conversionProbability ( )

Definition at line 42 of file discretizedconvertible.hpp.

42{ return conversionProbability_; }

◆ spreadAdjustedRate() [1/2]

const Array & spreadAdjustedRate ( ) const

Definition at line 44 of file discretizedconvertible.hpp.

44{ return spreadAdjustedRate_; }
+ Here is the caller graph for this function:

◆ spreadAdjustedRate() [2/2]

Array & spreadAdjustedRate ( )

Definition at line 45 of file discretizedconvertible.hpp.

45{ return spreadAdjustedRate_; }

◆ dividendValues() [1/2]

const Array & dividendValues ( ) const

Definition at line 47 of file discretizedconvertible.hpp.

47{ return dividendValues_; }

◆ dividendValues() [2/2]

Array & dividendValues ( )

Definition at line 48 of file discretizedconvertible.hpp.

48{ return dividendValues_; }

◆ mandatoryTimes()

std::vector< Time > mandatoryTimes ( ) const
override

Definition at line 80 of file discretizedconvertible.cpp.

80 {
81 std::vector<Time> result;
82 // the stopping times might be negative, if an exercise date lies in the past
83 for (auto const& t : stoppingTimes_) {
84 if (t > 0.0)
85 result.push_back(t);
86 }
87 std::copy(callabilityTimes_.begin(), callabilityTimes_.end(), std::back_inserter(result));
88 std::copy(cashflowTimes_.begin(), cashflowTimes_.end(), std::back_inserter(result));
89 return result;
90}

◆ postAdjustValuesImpl()

void postAdjustValuesImpl ( )
overrideprotected

Definition at line 120 of file discretizedconvertible.cpp.

120 {
121
122 bool convertible = false;
123 switch (arguments_.exercise->type()) {
124 case Exercise::American:
125 if (time() <= stoppingTimes_[1] && time() >= stoppingTimes_[0])
126 convertible = true;
127 break;
128 case Exercise::European:
129 if (isOnTime(stoppingTimes_[0]))
130 convertible = true;
131 break;
132 case Exercise::Bermudan:
133 for (Size i = 0; i < stoppingTimes_.size(); ++i) {
134 if (isOnTime(stoppingTimes_[i]))
135 convertible = true;
136 }
137 break;
138 default:
139 QL_FAIL("invalid option type");
140 }
141
142 for (Size i = 0; i < callabilityTimes_.size(); i++) {
143 if (isOnTime(callabilityTimes_[i]))
144 applyCallability(i, convertible);
145 }
146
147 for (Size i = 0; i < cashflowTimes_.size(); i++) {
148 if (isOnTime(cashflowTimes_[i]) && !close_enough(cashflowTimes_[i], cashflowTimes_.back()))
149 addCashflow(i);
150 }
151
152 if (convertible)
154}
void applyCallability(Size, bool convertible)
+ Here is the call graph for this function:

◆ adjustedGrid()

Array adjustedGrid ( ) const
private

Definition at line 215 of file discretizedconvertible.cpp.

215 {
216 Time t = time();
217 Array grid = method()->grid(t);
218 // add back all dividend amounts in the future
219 for (Size i = 0; i < arguments_.dividends.size(); i++) {
220 Time dividendTime = dividendTimes_[i];
221 if (dividendTime >= t || close(dividendTime, t)) {
222 const ext::shared_ptr<Dividend>& d = arguments_.dividends[i];
223 DiscountFactor dividendDiscount =
224 process_->riskFreeRate()->discount(dividendTime) / process_->riskFreeRate()->discount(t);
225 for (Size j = 0; j < grid.size(); j++)
226 grid[j] += d->amount(grid[j]) * dividendDiscount;
227 }
228 }
229 return grid;
230}
+ Here is the caller graph for this function:

◆ applyConvertibility()

void applyConvertibility ( )
private

Definition at line 164 of file discretizedconvertible.cpp.

164 {
165 Array grid = adjustedGrid();
166 Real conversionRatio = getConversionRatio(time());
167 for (Size j = 0; j < values_.size(); j++) {
168 Real payoff = conversionRatio * grid[j];
169 if (values_[j] <= payoff) {
170 values_[j] = payoff;
171 conversionProbability_[j] = 1.0;
172 }
173 }
174}
Real getConversionRatio(const Real t) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyCallability()

void applyCallability ( Size  i,
bool  convertible 
)
private

Definition at line 176 of file discretizedconvertible.cpp.

176 {
177 Size j;
178 Array grid = adjustedGrid();
179 Real conversionRatio = getConversionRatio(time());
180 switch (arguments_.callabilityTypes[i]) {
181 case Callability::Call:
182 if (arguments_.callabilityTriggers[i] != Null<Real>() && arguments_.conversionValue != Null<Real>()) {
184 for (j = 0; j < values_.size(); j++) {
185 // the callability is conditioned by the trigger...
186 if (grid[j] >= trigger) {
187 // ...and might trigger conversion
188 values_[j] =
189 std::min(std::max(arguments_.callabilityPrices[i], conversionRatio * grid[j]), values_[j]);
190 }
191 }
192 } else if (convertible) {
193 for (j = 0; j < values_.size(); j++) {
194 // exercising the callability might trigger conversion
195 values_[j] = std::min(std::max(arguments_.callabilityPrices[i], conversionRatio * grid[j]), values_[j]);
196 }
197 } else {
198 for (j = 0; j < values_.size(); j++) {
199 values_[j] = std::min(arguments_.callabilityPrices[i], values_[j]);
200 }
201 }
202 break;
203 case Callability::Put:
204 for (j = 0; j < values_.size(); j++) {
205 values_[j] = std::max(values_[j], arguments_.callabilityPrices[i]);
206 }
207 break;
208 default:
209 QL_FAIL("unknown callability type");
210 }
211}
std::vector< Callability::Type > callabilityTypes
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addCashflow()

void addCashflow ( Size  i)
private

Definition at line 213 of file discretizedconvertible.cpp.

213{ values_ += arguments_.cashflowAmounts[i]; }
+ Here is the caller graph for this function:

◆ getConversionRatio()

Real getConversionRatio ( const Real  t) const
private

Definition at line 156 of file discretizedconvertible.cpp.

156 {
157 Size idx = std::distance(notionalTimes_.begin(), std::upper_bound(notionalTimes_.begin(), notionalTimes_.end(), t));
158 if (idx > 0)
159 --idx;
160 return arguments_.notionals[std::min(idx, arguments_.notionals.size() - 1)] / arguments_.notionals.front() *
162}
+ Here is the caller graph for this function:

Member Data Documentation

◆ conversionProbability_

Array conversionProbability_
protected

Definition at line 54 of file discretizedconvertible.hpp.

◆ spreadAdjustedRate_

Array spreadAdjustedRate_
protected

Definition at line 54 of file discretizedconvertible.hpp.

◆ dividendValues_

Array dividendValues_
protected

Definition at line 54 of file discretizedconvertible.hpp.

◆ arguments_

Definition at line 61 of file discretizedconvertible.hpp.

◆ process_

QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> process_
private

Definition at line 62 of file discretizedconvertible.hpp.

◆ creditSpread_

Handle<Quote> creditSpread_
private

Definition at line 63 of file discretizedconvertible.hpp.

◆ stoppingTimes_

std::vector<Time> stoppingTimes_
private

Definition at line 64 of file discretizedconvertible.hpp.

◆ callabilityTimes_

std::vector<Time> callabilityTimes_
private

Definition at line 65 of file discretizedconvertible.hpp.

◆ cashflowTimes_

std::vector<Time> cashflowTimes_
private

Definition at line 66 of file discretizedconvertible.hpp.

◆ dividendTimes_

std::vector<Time> dividendTimes_
private

Definition at line 67 of file discretizedconvertible.hpp.

◆ notionalTimes_

std::vector<Time> notionalTimes_
private

Definition at line 71 of file discretizedconvertible.hpp.