예제 #1
0
    static void TestImpliedVol(double sigma = 0.1,  //volatilty
                               double S     = 100,  //underlying price
                               double K     = 100,  //strike price
                               double r     = 0.05, //risk free rate
                               double T     = 1)    //time to maturity in years
    {
        double CallOptionPrice = BlackScholesFormula.CalculateCallOptionPrice(sigma, S, K, r, T);
        double PutOptionPrice  = BlackScholesFormula.CalculatePutOptionPrice(sigma, S, K, r, T);

        System.Console.WriteLine("Price of a call option using Black Scholes formula is: {0}", BlackScholesFormula.CalculateCallOptionPrice(sigma, S, K, r, T));
        System.Console.WriteLine("Price of a put option using Black Scholes formula is: {0}", BlackScholesFormula.CalculatePutOptionPrice(sigma, S, K, r, T));

        System.Console.WriteLine("Implied volatiliy of a call option given the price from Black Scholes is: {0}", BlackScholesImpliedVolEuropean.CalculateImpliedVolCall(10, S, K, r, T));
        System.Console.WriteLine("Implied volatiliy of a put option given the price from Black Scholes is: {0}", BlackScholesImpliedVolEuropean.CalculateImpliedVolPut(3, S, K, r, T));
    }
        public static object DupireSsviEuropeanVanillaOptionPrice([ExcelArgument(Description = "the current risky asset price")] double S0,
                                                                  [ExcelArgument(Description = "constant continuously compounded rate of return")] double riskFreeRate,
                                                                  [ExcelArgument(Description = "parameter in theta(t) := alpha^2(e^(beta^2 t)  - 1)")] double alpha,
                                                                  [ExcelArgument(Description = "parameter in theta(t) := alpha^2(e^(beta^2 t)  - 1)")] double beta,
                                                                  [ExcelArgument(Description = "SSVI parameter")] double gamma,
                                                                  [ExcelArgument(Description = "SSVI parameter")] double eta,
                                                                  [ExcelArgument(Description = "SSVI parameter")] double rho,
                                                                  [ExcelArgument(Description = "option maturity (time to expiry)")] double maturity,
                                                                  [ExcelArgument(Description = "option strike")] double strike,
                                                                  [ExcelArgument(Description = "option type, 'C' for call 'P' for put")] string type)
        {
            try
            {
                Ssvi   SsviSurface = new Ssvi(alpha, beta, gamma, eta, rho);
                double k           = Math.Log(strike * Math.Exp(-riskFreeRate * maturity) / S0);
                double sigmaBs     = Math.Sqrt(SsviSurface.OmegaSsvi(maturity, k) / maturity);

                if (type == "Call" || type == "call" || type == "C" || type == "c")
                {
                    return(BlackScholesFormula.CalculateCallOptionPrice(sigmaBs, S0, k, riskFreeRate, maturity));
                }
                else if (type == "Put" || type == "put" || type == "P" || type == "p")
                {
                    return(BlackScholesFormula.CalculatePutOptionPrice(sigmaBs, S0, k, riskFreeRate, maturity));
                }
                else
                {
                    throw new ArgumentException("Input must be either Call, call, C, c, Put, put, P or p.");
                }
            }
            catch (Exception e)
            {
                XLInterfaceBase.AddErrorMessage("DupireSsviEuropeanVanillaOptionPrice error: " + e.Message);
            }

            return(FunctionError);
        }