25#ifndef quantlib_lattices_tf_lattice_hpp
26#define quantlib_lattices_tf_lattice_hpp
54 const Array& conversionProbability,
55 const Array& spreadAdjustedRate,
57 Array& newConversionProbability,
58 Array& newSpreadAdjustedRate)
const;
71 const ext::shared_ptr<T>& tree,
79 creditSpread_(creditSpread) {
81 "probability (" << this->
pu_ <<
") higher than one");
83 "negative (" << this->
pu_ <<
") probability");
90 const Array& conversionProbability,
91 const Array& spreadAdjustedRate,
93 Array& newConversionProbability,
94 Array& newSpreadAdjustedRate)
const {
96 for (
Size j=0; j<this->size(i); j++) {
102 newConversionProbability[j] =
103 this->
pd_*conversionProbability[j] +
104 this->pu_*conversionProbability[j+1];
107 newSpreadAdjustedRate[j] =
108 newConversionProbability[j] * this->riskFreeRate_ +
109 (1-newConversionProbability[j])*(this->riskFreeRate_+creditSpread_);
112 (this->
pd_*values[j]/(1+(spreadAdjustedRate[j]*this->dt_)))
113 + (this->pu_*values[j+1]/(1+(spreadAdjustedRate[j+1]*this->dt_)));
121 partialRollback(asset,to);
136 "cannot roll the asset back to" << to
137 <<
" (it is already at t = " << from <<
")");
141 auto iFrom =
Integer(this->
t_.index(from));
144 for (
Integer i=iFrom-1; i>=iTo; --i) {
146 Array newValues(this->size(i));
147 Array newSpreadAdjustedRate(this->size(i));
148 Array newConversionProbability(this->size(i));
150 stepback(i, convertible.values(),
151 convertible.conversionProbability(),
152 convertible.spreadAdjustedRate(), newValues,
153 newConversionProbability,newSpreadAdjustedRate);
155 convertible.time() = this->
t_[i];
156 convertible.values() = newValues;
157 convertible.spreadAdjustedRate() = newSpreadAdjustedRate;
158 convertible.conversionProbability() = newConversionProbability;
162 convertible.adjustValues();
Binomial trees under the BSM model.
1-D array used in linear algebra.
Simple binomial lattice approximating the Black-Scholes model.
Rate riskFreeRate() const
Discretized asset class used by numerical methods.
Binomial lattice approximating the Tsiveriotis-Fernandes model.
void partialRollback(DiscretizedAsset &, Time to) const override
void rollback(DiscretizedAsset &, Time to) const override
Spread creditSpread() const
void stepback(Size i, const Array &values, const Array &conversionProbability, const Array &spreadAdjustedRate, Array &newValues, Array &newConversionProbability, Array &newSpreadAdjustedRate) const
TsiveriotisFernandesLattice(const ext::shared_ptr< T > &tree, Rate riskFreeRate, Time end, Size steps, Spread creditSpread, Volatility volatility, Spread divYield)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Real Time
continuous quantity with 1-year units
Real Volatility
volatility
QL_INTEGER Integer
integer number
Real Spread
spreads on interest rates
std::size_t Size
size of a container
bool close(const Quantity &m1, const Quantity &m2, Size n)