Beispiel #1
0
        public static double ImpliedVolatility(double S, double X, double t, double r, double P, EOptionType OptionType, EPutCall PutCall, EOptionPrice Method, int n, double Eps)
        {
            double num1 = 0.0;
            double num2 = 10.0;
            double num3 = 0.0;
            double s    = 0.0;

            while (Math.Abs(num2 - num1) > Eps)
            {
                s = num1 + (num2 - num1) / 2.0;
                switch (Method)
                {
                case EOptionPrice.BlackScholes:
                    num3 = FinMath.BS(S, X, t, s, r, PutCall);
                    break;

                case EOptionPrice.Binomial:
                    num3 = FinMath.BM(S, X, t, s, r, PutCall, n);
                    break;

                case EOptionPrice.MonteCarlo:
                    num3 = FinMath.MC(S, X, t, s, r, PutCall, n);
                    break;
                }
                if (num3 > P)
                {
                    num2 = s;
                }
                else
                {
                    num1 = s;
                }
            }
            return(s);
        }