# How does LR binomial Tree Model handle input values which would cause NA result?

I am using C++ to implement a LR binomial Tree algorithm to price American options, but I find it would constantly generate invalid output, which is "nan" value in C++, although the input value seems quite reasonable.

My code:

double lr_price(IN int putcall, double s,double k, double r, double vol, double bizt, ouble cldt, int steps)
{
if (steps % 2 == 0)
{
steps += 1;
}
double dt = cldt / steps;
double d1 = (std::log(s / k) + (r + vol * vol * 0.5) * bizt) / (vol * std::sqrt(bizt));
double d2 = d1 - vol * std::sqrt(bizt);
double hd1 = peizerpratt2(d1, steps);   //* <== 0 here when using the following input
double hd2 = peizerpratt2(d2, steps);
double p = hd2;
double u = std::exp(r * dt) * hd1 / hd2;
double d = (std::exp(r * dt) - p * u) / (1 - p);
for (int i = 0; i <= steps; i++)
{
asset_prices[steps][i] = s * std::pow(u, steps - i) * std::pow(d, i);
option_values[steps][i] = payoff(asset_prices[steps][i], k, putcall);
}

for (int step = steps - 1; step >= 0; step--)
{
for (int i = 0; i <= step; i++)
{
asset_prices[step][i] = asset_prices[step + 1][i] / u;
option_values[step][i] = std::max(
(option_values[step + 1][i] * p + option_values[step + 1][i + 1] * (1 - p)) * std::exp(0 - r * dt),
payoff(asset_prices[step][i], k, putcall));
}
}

return option_values[0][0];
}

double peizerpratt2(double z, double n)
{
return 0.5 + sgn(z) * std::sqrt(
0.25 - 0.25 * std::exp(0 - std::pow(z / (n + 1.0 / 3.0 + 0.1 / (n + 1.0)), 2) * (n + 1.0 / 6.0)));
}


And look at this group of input values:

s = 3328, k = 4100, bizt = 0.0932, cldt = 0.1328, vol = 0.0156, r=0.0011, steps = 10

it would make hd1 to the value of 0, and then the following steps are unable to compute.

I can easily provide such groups of input values. It occurs quite often when I running my tests.

I am wondering if there is some good way to handle such conditions in practice. It is unbelievable to me that a commonly used model has so many invalid points.

• You have an even number of steps, i.e steps=10. Is that allowed? I thought it had to be odd. – Alex C Dec 10 '18 at 2:21
• oh, I forget to provide the prepare phase in my code above. Actually it is 11 in computing. I would make it be odd first before running into lr_price(). But it does not matter much in this condition, cause the code will fail before running to the actual bi-tree-node. – Lord_WayneY Dec 10 '18 at 2:29
• @AlexC Anyway, now I added the lost making steps be odd part of code. Thks for pointing out. – Lord_WayneY Dec 10 '18 at 2:35