public LeisenReimerBinomialTree(BlackScholesProcess process, double x0, double strike, double tend, int steps = 200, int peizerPrattMethod = 1) : base(process, x0, tend, (steps % 2 == 0 ? steps + 1 : steps)) { _strike = strike; Dx = process.StdDeviation(0, X0, Dt); // sigma * sqrt(dt) var drift = process.Drift(0, X0, Dt); // r - q - 0.5 * sigma * sigma var sigma = process.Diffusion(0, X0); // sigma var d1 = (Math.Log(X0 / _strike) + (drift + sigma * sigma) * tend) / (sigma * Math.Sqrt(tend)); // d+ var d2 = (Math.Log(X0 / _strike) + drift * tend) / (sigma * Math.Sqrt(tend)); // d- var p1 = ProbabilityHelper(d1, NumberOfSteps, peizerPrattMethod); var p2 = ProbabilityHelper(d2, NumberOfSteps, peizerPrattMethod); var tmp = Math.Exp((drift + 0.5 * sigma * sigma) * Dt); var u = tmp * p1 / p2; var d = (tmp - p2 * u) / (1 - p2); PUp = p2; PDown = 1 - PUp; _steps = steps % 2 == 0 ? steps + 1 : steps; // only use odd number _stateValues = new double[_steps + 1][]; for (int i = 0; i < _steps + 1; ++i) { _stateValues[i] = new double[i + 1]; for (int j = 0; j < i + 1; ++j) { _stateValues[i][j] = X0 * Math.Pow(u, j) * Math.Pow(d, i - j); } } }
public CoxRossRubinsteinBinomialTree(BlackScholesProcess process, double x0, double tend, int steps = 200) : base(process, x0, tend, steps) { Dx = process.StdDeviation(0, X0, Dt); // sigma * sqrt(dt) // (exp(r*dt) - exp(-sigma*sqrt(dt)) / (exp(sigma*sqrt(dt)) - exp(-sigma*sqrt(dt))) PUp = 0.5 + 0.5 * DriftPerStep / Dx; //(Math.Exp((Process.GetDiscountRate(0.0) - Process.GetDividendRate(0.0)) * Dt) - Math.Exp(-Dx)) / (Math.Exp(Dx) - Math.Exp(-Dx)); PDown = 1 - PUp; _stateValues = new double[steps + 1][]; for (int i = 0; i < steps + 1; ++i) { _stateValues[i] = new double[i + 1]; for (int j = 0; j < i + 1; ++j) { _stateValues[i][j] = X0 * Math.Exp((2 * j - i) * Dx); } } }