public static double ImpliedVolatility(double S, double X, double t, double r, double P, EOptionType OptionType, EPutCall PutCall, EOptionPrice Method) { int n = 0; switch (Method) { case EOptionPrice.Binomial: n = 100; break; case EOptionPrice.MonteCarlo: n = 100000; break; } double Eps = 0.001; return FinMath.ImpliedVolatility(S, X, t, r, P, OptionType, PutCall, Method, n, Eps); }
public static double ImpliedVolatility(double S, double X, double t, double r, double P, EOptionType OptionType, EPutCall PutCall, EOptionPrice Method) { int n = 0; switch (Method) { case EOptionPrice.Binomial: n = 100; break; case EOptionPrice.MonteCarlo: n = 100000; break; } double Eps = 0.001; return(FinMath.ImpliedVolatility(S, X, t, r, P, OptionType, PutCall, Method, n, Eps)); }
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; }
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); }