27 const ext::shared_ptr<StochasticProcess1D>& process,
34 QL_REQUIRE(nTimeSteps > 0,
"null time steps for trinomial tree");
39 for (
Size i=0; i<nTimeSteps; i++) {
44 Real v2 = process->variance(
t, 0.0, dt);
46 dx_.push_back(
v*std::sqrt(3.0));
49 for (
Integer j=jMin; j<=jMax; j++) {
51 Real m = process->expectation(
t, x, dt);
52 auto temp =
Integer(std::floor((m -
x0_) /
dx_[i + 1] + 0.5));
55 while (
x0_+(temp-1)*
dx_[i+1]<=0) {
62 Real e3 = e*std::sqrt(3.0);
64 Real p1 = (1.0 + e2/v2 - e3/
v)/6.0;
65 Real p2 = (2.0 - e2/v2)/3.0;
66 Real p3 = (1.0 + e2/v2 + e3/
v)/6.0;
68 branching.
add(temp, p1, p2, p3);
72 jMin = branching.
jMin();
73 jMax = branching.
jMax();
Tree approximating a single-factor diffusion
void add(Integer k, Real p1, Real p2, Real p3)
Recombining trinomial tree class.
TrinomialTree(const ext::shared_ptr< StochasticProcess1D > &process, const TimeGrid &timeGrid, bool isPositive=false)
std::vector< Branching > branchings_
const TimeGrid & timeGrid() const
#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
std::size_t Size
size of a container
ext::shared_ptr< BlackVolTermStructure > v