QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
binomialtree.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003 Ferdinando Ametrano
5 Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb
6 Copyright (C) 2005 StatPro Italia srl
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
26#ifndef quantlib_binomial_tree_hpp
27#define quantlib_binomial_tree_hpp
28
29
30#include <ql/methods/lattices/tree.hpp>
31#include <ql/instruments/dividendschedule.hpp>
32#include <ql/stochasticprocess.hpp>
33
34namespace QuantLib {
35
37
38 template <class T>
39 class BinomialTree : public Tree<T> {
40 public:
41 enum Branches { branches = 2 };
42 BinomialTree(const ext::shared_ptr<StochasticProcess1D>& process,
43 Time end,
44 Size steps)
45 : Tree<T>(steps+1), x0_(process->x0()), dt_(end/steps) {
46 driftPerStep_ = process->drift(0.0, x0_) * dt_;
47 }
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:
57 };
58
59
61
62 template <class T>
64 public:
66 const ext::shared_ptr<StochasticProcess1D>& process,
67 Time end,
68 Size steps)
69 : BinomialTree<T>(process, end, steps) {}
70 Real underlying(Size i, Size index) const {
71 BigInteger j = 2*BigInteger(index) - BigInteger(i);
72 // exploiting the forward value tree centering
73 return this->x0_*std::exp(i*this->driftPerStep_ + j*this->up_);
74 }
75 Real probability(Size, Size, Size) const { return 0.5; }
76 protected:
78 };
79
80
82
83 template <class T>
85 public:
87 const ext::shared_ptr<StochasticProcess1D>& process,
88 Time end,
89 Size steps)
90 : BinomialTree<T>(process, end, steps) {}
91 Real underlying(Size i, Size index) const {
92 BigInteger j = 2*BigInteger(index) - BigInteger(i);
93 // exploiting equal jump and the x0_ tree centering
94 return this->x0_*std::exp(j*this->dx_);
95 }
96 Real probability(Size, Size, Size branch) const {
97 return (branch == 1 ? pu_ : pd_);
98 }
99 protected:
101 };
102
103
105
106 class JarrowRudd : public EqualProbabilitiesBinomialTree<JarrowRudd> {
107 public:
108 JarrowRudd(const ext::shared_ptr<StochasticProcess1D>&,
109 Time end,
110 Size steps,
111 Real strike);
112 };
113
114
116
118 : public EqualJumpsBinomialTree<CoxRossRubinstein> {
119 public:
120 CoxRossRubinstein(const ext::shared_ptr<StochasticProcess1D>&,
121 Time end,
122 Size steps,
123 Real strike);
124 };
125
126
128
130 : public EqualProbabilitiesBinomialTree<AdditiveEQPBinomialTree> {
131 public:
133 const ext::shared_ptr<StochasticProcess1D>&,
134 Time end,
135 Size steps,
136 Real strike);
137 };
138
139
141
142 class Trigeorgis : public EqualJumpsBinomialTree<Trigeorgis> {
143 public:
144 Trigeorgis(const ext::shared_ptr<StochasticProcess1D>&,
145 Time end,
146 Size steps,
147 Real strike);
148 };
149
150
152
153 class Tian : public BinomialTree<Tian> {
154 public:
155 Tian(const ext::shared_ptr<StochasticProcess1D>&,
156 Time end,
157 Size steps,
158 Real strike);
159 Real underlying(Size i, Size index) const {
160 return x0_ * std::pow(down_, Real(BigInteger(i)-BigInteger(index)))
161 * std::pow(up_, Real(index));
162 };
163 Real probability(Size, Size, Size branch) const {
164 return (branch == 1 ? pu_ : pd_);
165 }
166 protected:
168 };
169
171
172 class LeisenReimer : public BinomialTree<LeisenReimer> {
173 public:
174 LeisenReimer(const ext::shared_ptr<StochasticProcess1D>&,
175 Time end,
176 Size steps,
177 Real strike);
178 Real underlying(Size i, Size index) const {
179 return x0_ * std::pow(down_, Real(BigInteger(i)-BigInteger(index)))
180 * std::pow(up_, Real(index));
181 }
182 Real probability(Size, Size, Size branch) const {
183 return (branch == 1 ? pu_ : pd_);
184 }
185 protected:
187 };
188
189
190 class Joshi4 : public BinomialTree<Joshi4> {
191 public:
192 Joshi4(const ext::shared_ptr<StochasticProcess1D>&,
193 Time end,
194 Size steps,
195 Real strike);
196 Real underlying(Size i, Size index) const {
197 return x0_ * std::pow(down_, Real(BigInteger(i)-BigInteger(index)))
198 * std::pow(up_, Real(index));
199 }
200 Real probability(Size, Size, Size branch) const {
201 return (branch == 1 ? pu_ : pd_);
202 }
203 protected:
204 Real computeUpProb(Real k, Real dj) const;
206 };
207
208
209}
210
211
212#endif
Additive equal probabilities binomial tree.
Binomial tree base class.
Size descendant(Size, Size index, Size branch) const
BinomialTree(const ext::shared_ptr< StochasticProcess1D > &process, Time end, Size steps)
Size size(Size i) const
Cox-Ross-Rubinstein (multiplicative) equal jumps binomial tree.
Base class for equal jumps binomial tree.
EqualJumpsBinomialTree(const ext::shared_ptr< StochasticProcess1D > &process, Time end, Size steps)
Real underlying(Size i, Size index) const
Real probability(Size, Size, Size branch) const
Base class for equal probabilities binomial tree.
EqualProbabilitiesBinomialTree(const ext::shared_ptr< StochasticProcess1D > &process, Time end, Size steps)
Real probability(Size, Size, Size) const
Real underlying(Size i, Size index) const
Jarrow-Rudd (multiplicative) equal probabilities binomial tree.
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
Tree approximating a single-factor diffusion
Definition: tree.hpp:51
Trigeorgis (additive equal jumps) binomial tree
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