Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
tflattice.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2005, 2006 Theo Boafo
3 Copyright (C) 2006, 2007 StatPro Italia srl
4 Copyright (C) 2020 Quaternion Risk Managment Ltd
5
6 This file is part of ORE, a free-software/open-source library
7 for transparent pricing and risk analysis - http://opensourcerisk.org
8
9 ORE is free software: you can redistribute it and/or modify it
10 under the terms of the Modified BSD License. You should have received a
11 copy of the license along with this program.
12 The license is also available online at <http://opensourcerisk.org>
13
14 This program is distributed on the basis that it will form a useful
15 contribution to risk analytics and model standardisation, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20/*! \file qle/pricingengines/tflattice.hpp
21 \brief Binomial Tsiveriotis-Fernandes tree model
22*/
23
24#pragma once
25
27
28#include <ql/methods/lattices/bsmlattice.hpp>
29
30namespace QuantExt {
31
32//! Binomial lattice approximating the Tsiveriotis-Fernandes model
33/*! \ingroup lattices */
34template <class T> class TsiveriotisFernandesLattice : public BlackScholesLattice<T> {
35public:
36 TsiveriotisFernandesLattice(const ext::shared_ptr<T>& tree, Rate riskFreeRate, Time end, Size steps,
37 Spread creditSpread, Volatility volatility, Spread divYield);
38
39 Spread creditSpread() const { return creditSpread_; };
40
41protected:
42 void stepback(Size i, const Array& values, const Array& conversionProbability, const Array& spreadAdjustedRate,
43 Array& newValues, Array& newConversionProbability, Array& newSpreadAdjustedRate) const;
44 void rollback(DiscretizedAsset&, Time to) const override;
45 void partialRollback(DiscretizedAsset&, Time to) const override;
46
47private:
49};
50
51// template definitions
52
53template <class T>
54TsiveriotisFernandesLattice<T>::TsiveriotisFernandesLattice(const ext::shared_ptr<T>& tree, Rate riskFreeRate, Time end,
55 Size steps, Spread creditSpread, Volatility sigma,
56 Spread divYield)
57 : BlackScholesLattice<T>(tree, riskFreeRate, end, steps), creditSpread_(creditSpread) {
58 QL_REQUIRE(this->pu_ <= 1.0, "probability (" << this->pu_ << ") higher than one");
59 QL_REQUIRE(this->pu_ >= 0.0, "negative (" << this->pu_ << ") probability");
60}
61
62template <class T>
63void TsiveriotisFernandesLattice<T>::stepback(Size i, const Array& values, const Array& conversionProbability,
64 const Array& spreadAdjustedRate, Array& newValues,
65 Array& newConversionProbability, Array& newSpreadAdjustedRate) const {
66
67 for (Size j = 0; j < this->size(i); j++) {
68
69 // new conversion probability is calculated via backward
70 // induction using up and down probabilities on tree on
71 // previous conversion probabilities, ie weighted average
72 // of previous probabilities.
73 newConversionProbability[j] = this->pd_ * conversionProbability[j] + this->pu_ * conversionProbability[j + 1];
74
75 // Use blended discounting rate
76 newSpreadAdjustedRate[j] = newConversionProbability[j] * this->riskFreeRate_ +
77 (1 - newConversionProbability[j]) * (this->riskFreeRate_ + creditSpread_);
78
79 newValues[j] = (this->pd_ * values[j] / (1 + (spreadAdjustedRate[j] * this->dt_))) +
80 (this->pu_ * values[j + 1] / (1 + (spreadAdjustedRate[j + 1] * this->dt_)));
81 }
82}
83
84template <class T> void TsiveriotisFernandesLattice<T>::rollback(DiscretizedAsset& asset, Time to) const {
85 partialRollback(asset, to);
86 asset.adjustValues();
87}
88
89template <class T> void TsiveriotisFernandesLattice<T>::partialRollback(DiscretizedAsset& asset, Time to) const {
90
91 Time from = asset.time();
92
93 if (close(from, to))
94 return;
95
96 QL_REQUIRE(from > to, "cannot roll the asset back to" << to << " (it is already at t = " << from << ")");
97
98 QuantExt::DiscretizedConvertible& convertible = dynamic_cast<QuantExt::DiscretizedConvertible&>(asset);
99
100 Integer iFrom = Integer(this->t_.index(from));
101 Integer iTo = Integer(this->t_.index(to));
102
103 for (Integer i = iFrom - 1; i >= iTo; --i) {
104
105 Array newValues(this->size(i));
106 Array newSpreadAdjustedRate(this->size(i));
107 Array newConversionProbability(this->size(i));
108
109 stepback(i, convertible.values(), convertible.conversionProbability(), convertible.spreadAdjustedRate(),
110 newValues, newConversionProbability, newSpreadAdjustedRate);
111
112 convertible.time() = this->t_[i];
113 convertible.values() = newValues;
114 convertible.spreadAdjustedRate() = newSpreadAdjustedRate;
115 convertible.conversionProbability() = newConversionProbability;
116
117 // skip the very last adjustment
118 if (i != iTo)
119 convertible.adjustValues();
120 }
121}
122
123} // namespace QuantExt
Binomial lattice approximating the Tsiveriotis-Fernandes model.
Definition: tflattice.hpp:34
void partialRollback(DiscretizedAsset &, Time to) const override
Definition: tflattice.hpp:89
void rollback(DiscretizedAsset &, Time to) const override
Definition: tflattice.hpp:84
void stepback(Size i, const Array &values, const Array &conversionProbability, const Array &spreadAdjustedRate, Array &newValues, Array &newConversionProbability, Array &newSpreadAdjustedRate) const
Definition: tflattice.hpp:63
TsiveriotisFernandesLattice(const ext::shared_ptr< T > &tree, Rate riskFreeRate, Time end, Size steps, Spread creditSpread, Volatility volatility, Spread divYield)
Definition: tflattice.hpp:54
discretized convertible
std::vector< Size > steps