示例#1
0
        double IPricer.Price(BSParameter param)
        {
            double d1          = 0.0;
            double d2          = 0.0;
            double optionValue = 0.0;


            double         S          = param.Stock;
            double         X          = param.Strike;
            double         r          = param.InterestRate;
            double         T          = param.Day;
            double         v          = param.Vol;
            OptionTypeEnum optionType = param.OptionType;

            d1 = (Math.Log(S / X) + (r + v * v / 2.0) * T) / (v * Math.Sqrt(T));
            d2 = d1 - v * Math.Sqrt(T);
            if (optionType == OptionTypeEnum.CallOption)
            {
                optionValue = S * CumulativeNormalDistributionFun(d1) - X * Math.Exp(-r * T) * CumulativeNormalDistributionFun(d2);
            }
            else if (optionType == OptionTypeEnum.PutOption)
            {
                optionValue = X * Math.Exp(-r * T) * CumulativeNormalDistributionFun(-d2) - S * CumulativeNormalDistributionFun(-d1);
            }
            PricingTerminated?.Invoke(this, null);
            return(optionValue);
        }
        private void ConvertParamAndPrice()
        {
            // i don't want to pass the view Model to the code behind
            var bsParam = new BSParameter()
            {
                Strike       = Param.Strike,
                Stock        = Param.Stock,
                Day          = Param.Day,
                Vol          = Param.Vol,
                InterestRate = Param.InterestRate,
                OptionType   = OptionTypeEnum.CallOption
            };

            _pricer.Price(bsParam);
        }
示例#3
0
        public void TestPrice()
        {
            IPricer model   = new Pricer();
            var     bsParam = new BSParameter()
            {
                Strike       = 65,
                Stock        = 60,
                Day          = 0.25,
                Vol          = 0.3,
                InterestRate = 0.08,
                OptionType   = OptionTypeEnum.CallOption
            };

            double price = model.Price(bsParam);

            Assert.AreEqual(2.1333718619310424d, price);
        }