25#ifndef quantlib_tree_lattice_2d_hpp
26#define quantlib_tree_lattice_2d_hpp
41 template <
class Impl,
class T = TrinomialTree>
62 template <
class Impl,
class T>
64 return tree1_->size(i)*tree2_->size(i);
70 template <
class Impl,
class T>
72 ext::shared_ptr<T> tree2,
74 :
TreeLattice<Impl>(tree1->timeGrid(),
T::branches *
T::branches), tree1_(tree1),
75 tree2_(
std::move(tree2)),
m_(
T::branches,
T::branches), rho_(
std::fabs(correlation)) {
78 if (correlation < 0.0 && T::branches == 3) {
102 template <
class Impl,
class T>
105 Size modulo = tree1_->size(i);
107 Size index1 = index % modulo;
108 Size index2 = index / modulo;
109 Size branch1 = branch % T::branches;
110 Size branch2 = branch / T::branches;
112 modulo = tree1_->size(i+1);
113 return tree1_->descendant(i, index1, branch1) +
114 tree2_->descendant(i, index2, branch2)*modulo;
117 template <
class Impl,
class T>
120 Size modulo = tree1_->size(i);
122 Size index1 = index % modulo;
123 Size index2 = index / modulo;
124 Size branch1 = branch % T::branches;
125 Size branch2 = branch / T::branches;
127 Real prob1 = tree1_->probability(i, index1, branch1);
128 Real prob2 = tree2_->probability(i, index2, branch2);
130 return prob1*prob2 + rho_*(
m_[branch1][branch2])/36.0;
1-D array used in linear algebra.
Matrix used in linear algebra.
Two-dimensional tree-based lattice.
ext::shared_ptr< T > tree1_
Size descendant(Size i, Size index, Size branch) const
Real probability(Size i, Size index, Size branch) const
Array grid(Time) const override
ext::shared_ptr< T > tree2_
TreeLattice2D(const ext::shared_ptr< T > &tree1, ext::shared_ptr< T > tree2, Real correlation)
Tree-based lattice-method base class.
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
Tree-based lattice-method class.
matrix used in linear algebra.