QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
extendedbinomialtree.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb
5 Copyright (C) 2003 Ferdinando Ametrano
6 Copyright (C) 2005 StatPro Italia srl
7 Copyright (C) 2008 John Maiden
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
23/*! \file extendedbinomialtree.hpp
24 \brief Time-dependent binomial tree class
25*/
26
27#ifndef quantlib_extended_binomial_tree_hpp
28#define quantlib_extended_binomial_tree_hpp
29
33
34namespace QuantLib {
35
36 //! Binomial tree base class
37 /*! \ingroup lattices */
38 template <class T>
39 class ExtendedBinomialTree : public Tree<T> {
40 public:
41 enum Branches { branches = 2 };
43 const ext::shared_ptr<StochasticProcess1D>& process,
44 Time end,
45 Size steps)
46 : Tree<T>(steps+1), x0_(process->x0()), dt_(end/steps),
47 treeProcess_(process) {}
48 Size size(Size i) const {
49 return i+1;
50 }
51 Size descendant(Size, Size index, Size branch) const {
52 return index + branch;
53 }
54 protected:
55 //time dependent drift per step
56 Real driftStep(Time driftTime) const {
57 return this->treeProcess_->drift(driftTime, x0_) * dt_;
58 }
59
62
63
64 ext::shared_ptr<StochasticProcess1D> treeProcess_;
65 };
66
67
68 //! Base class for equal probabilities binomial tree
69 /*! \ingroup lattices */
70 template <class T>
72 : public ExtendedBinomialTree<T> {
73 public:
75 const ext::shared_ptr<StochasticProcess1D>& process,
76 Time end,
77 Size steps)
78 : ExtendedBinomialTree<T>(process, end, steps) {}
80
81 Real underlying(Size i, Size index) const {
82 Time stepTime = i*this->dt_;
83 BigInteger j = 2*BigInteger(index) - BigInteger(i);
84 // exploiting the forward value tree centering
85 return this->x0_*std::exp(i*this->driftStep(stepTime) + j*this->upStep(stepTime));
86 }
87
88 Real probability(Size, Size, Size) const { return 0.5; }
89 protected:
90 //the tree dependent up move term at time stepTime
91 virtual Real upStep(Time stepTime) const = 0;
93 };
94
95
96 //! Base class for equal jumps binomial tree
97 /*! \ingroup lattices */
98 template <class T>
100 public:
102 const ext::shared_ptr<StochasticProcess1D>& process,
103 Time end,
104 Size steps)
105 : ExtendedBinomialTree<T>(process, end, steps) {}
107
108 Real underlying(Size i, Size index) const {
109 Time stepTime = i*this->dt_;
110 BigInteger j = 2*BigInteger(index) - BigInteger(i);
111 // exploiting equal jump and the x0_ tree centering
112 return this->x0_*std::exp(j*this->dxStep(stepTime));
113 }
114
115 Real probability(Size i, Size, Size branch) const {
116 Time stepTime = i*this->dt_;
117 Real upProb = this->probUp(stepTime);
118 Real downProb = 1 - upProb;
119 return (branch == 1 ? upProb : downProb);
120 }
121 protected:
122 //probability of a up move
123 virtual Real probUp(Time stepTime) const = 0;
124 //time dependent term dx_
125 virtual Real dxStep(Time stepTime) const = 0;
126
128 };
129
130
131 //! Jarrow-Rudd (multiplicative) equal probabilities binomial tree
132 /*! \ingroup lattices */
134 : public ExtendedEqualProbabilitiesBinomialTree<ExtendedJarrowRudd> {
135 public:
136 ExtendedJarrowRudd(const ext::shared_ptr<StochasticProcess1D>&,
137 Time end,
138 Size steps,
139 Real strike);
140 protected:
141 Real upStep(Time stepTime) const override;
142 };
143
144
145 //! Cox-Ross-Rubinstein (multiplicative) equal jumps binomial tree
146 /*! \ingroup lattices */
148 : public ExtendedEqualJumpsBinomialTree<ExtendedCoxRossRubinstein> {
149 public:
150 ExtendedCoxRossRubinstein(const ext::shared_ptr<StochasticProcess1D>&,
151 Time end,
152 Size steps,
153 Real strike);
154 protected:
155 Real dxStep(Time stepTime) const override;
156 Real probUp(Time stepTime) const override;
157 };
158
159
160 //! Additive equal probabilities binomial tree
161 /*! \ingroup lattices */
164 ExtendedAdditiveEQPBinomialTree> {
165 public:
167 const ext::shared_ptr<StochasticProcess1D>&,
168 Time end,
169 Size steps,
170 Real strike);
171
172 protected:
173 Real upStep(Time stepTime) const override;
174 };
175
176
177 //! %Trigeorgis (additive equal jumps) binomial tree
178 /*! \ingroup lattices */
180 : public ExtendedEqualJumpsBinomialTree<ExtendedTrigeorgis> {
181 public:
182 ExtendedTrigeorgis(const ext::shared_ptr<StochasticProcess1D>&,
183 Time end,
184 Size steps,
185 Real strike);
186 protected:
187 Real dxStep(Time stepTime) const override;
188 Real probUp(Time stepTime) const override;
189 };
190
191
192 //! %Tian tree: third moment matching, multiplicative approach
193 /*! \ingroup lattices */
194 class ExtendedTian : public ExtendedBinomialTree<ExtendedTian> {
195 public:
196 ExtendedTian(const ext::shared_ptr<StochasticProcess1D>&,
197 Time end,
198 Size steps,
199 Real strike);
200
201 Real underlying(Size i, Size index) const;
202 Real probability(Size, Size, Size branch) const;
203 protected:
205 };
206
207 //! Leisen & Reimer tree: multiplicative approach
208 /*! \ingroup lattices */
210 : public ExtendedBinomialTree<ExtendedLeisenReimer> {
211 public:
212 ExtendedLeisenReimer(const ext::shared_ptr<StochasticProcess1D>&,
213 Time end,
214 Size steps,
215 Real strike);
216
217 Real underlying(Size i, Size index) const;
218 Real probability(Size, Size, Size branch) const;
219 protected:
223 };
224
225
226 class ExtendedJoshi4 : public ExtendedBinomialTree<ExtendedJoshi4> {
227 public:
228 ExtendedJoshi4(const ext::shared_ptr<StochasticProcess1D>&,
229 Time end,
230 Size steps,
231 Real strike);
232
233 Real underlying(Size i, Size index) const;
234 Real probability(Size, Size, Size branch) const;
235 protected:
236 Real computeUpProb(Real k, Real dj) const;
240 };
241
242
243}
244
245
246#endif
Additive equal probabilities binomial tree.
Real upStep(Time stepTime) const override
Real driftStep(Time driftTime) const
ExtendedBinomialTree(const ext::shared_ptr< StochasticProcess1D > &process, Time end, Size steps)
Size descendant(Size, Size index, Size branch) const
ext::shared_ptr< StochasticProcess1D > treeProcess_
Cox-Ross-Rubinstein (multiplicative) equal jumps binomial tree.
Real probUp(Time stepTime) const override
Real dxStep(Time stepTime) const override
Base class for equal jumps binomial tree.
Real probability(Size i, Size, Size branch) const
ExtendedEqualJumpsBinomialTree(const ext::shared_ptr< StochasticProcess1D > &process, Time end, Size steps)
virtual Real probUp(Time stepTime) const =0
virtual Real dxStep(Time stepTime) const =0
virtual ~ExtendedEqualJumpsBinomialTree()=default
Base class for equal probabilities binomial tree.
virtual Real upStep(Time stepTime) const =0
ExtendedEqualProbabilitiesBinomialTree(const ext::shared_ptr< StochasticProcess1D > &process, Time end, Size steps)
Jarrow-Rudd (multiplicative) equal probabilities binomial tree.
Real upStep(Time stepTime) const override
Real underlying(Size i, Size index) const
Real probability(Size, Size, Size branch) const
Real computeUpProb(Real k, Real dj) const
Leisen & Reimer tree: multiplicative approach.
Real underlying(Size i, Size index) const
Real probability(Size, Size, Size branch) const
Tian tree: third moment matching, multiplicative approach
Real underlying(Size i, Size index) const
Real probability(Size, Size, Size branch) const
Trigeorgis (additive equal jumps) binomial tree
Real probUp(Time stepTime) const override
Real dxStep(Time stepTime) const override
Tree approximating a single-factor diffusion
Definition: tree.hpp:51
Schedule of dividend dates.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
QL_BIG_INTEGER BigInteger
large integer number
Definition: types.hpp:39
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
stochastic processes
Tree class.