public BinomialTreeNode(double spot, double upFactor, double downFactor, double upProba, int currentRank, int targetRank)
        {
            _spot    = spot;
            _upProba = upProba;

            if (targetRank - currentRank != 0)
            {
                var nodeTasks = new List <Task>(2)
                {
                    Task.Run(
                        () => _upNode = new BinomialTreeNode(spot * upFactor, upFactor, downFactor, upProba, currentRank + 1, targetRank)),
                    Task.Run(
                        () =>
                        _downNode = new BinomialTreeNode(spot * downFactor, upFactor, downFactor, upProba, currentRank + 1, targetRank))
                };

                Parallel.ForEach(nodeTasks, t => t.Wait());
            }

            //Console.WriteLine(string.Format("Node rank:{0} spot:{1} created", currentRank, _spot));
        }
示例#2
0
        static void Main(string[] args)
        {
            const int    years      = 1;
            const int    steps      = 26;
            const double deltaT     = (double)years / (double)steps;
            const double volatility = 1.0 / 100.0;
            double       u          = Math.Exp(volatility * Math.Sqrt(deltaT));

            const double s0     = 100;
            const double strike = 90.0;
            const double sureTx = 5.0 / 100.0;

            double d = 1 / u;
            double p = (Math.Exp(sureTx * deltaT) - d) / (u - d);

            var node = new BinomialTreeNode(s0, u, d, p, 0, steps);

            var result = node.Evaluate((s) => Math.Max(s - strike, 0));

            System.Console.Write(result);
            //Console.ReadLine();
        }