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);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BinomialTree"/> class.
        /// The underlying process shall be a Black-Schole process with constant r, sigma
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="x0">The x0.</param>
        /// <param name="tend">The end time in years.</param>
        /// <param name="steps">The number of time steps.</param>
        //protected BinomialTree(BlackScholesProcess process, double x0, double tend, int steps = 200)
        protected BinomialTree(BlackScholesProcess process, double x0, double tend, int steps)
        {
            Process       = process;
            X0            = x0;
            Dt            = tend / steps;
            NumberOfSteps = steps;
            DriftPerStep  = process.Drift(0, x0, Dt) * Dt;

            AllBranchDirections = new List <BranchDirection> {
                BranchDirection.Down, BranchDirection.Up
            };
        }