Exemplo n.º 1
0
    public static void SimpleCapletPrice()
    {
        #region Input Data
        Date   t0  = new Date(2013, 03, 4);
        Date   t_i = new Date(2014, 03, 4);
        Date   t_e = new Date(2014, 07, 4);
        double yf  = (t_e.SerialValue - t_i.SerialValue) / 360;
        double T   = (t_i.SerialValue - t0.SerialValue) / 365.0;;

        double sigma  = 0.335;
        double strike = 0.007;
        double df_i   = 0.9912;    // Df on t_i
        double df_e   = 0.9882;    // Df on t_e
        double fwd    = ((df_i / df_e) - 1) / yf;
        double N      = 100000000; // Notional amount
        #endregion
        // Calculate d1 and d2
        double d1 = ((Math.Log(fwd / strike) + (sigma * sigma * T * .5)) / (sigma * Math.Sqrt(T)));
        double d2 = ((Math.Log(fwd / strike) - (sigma * sigma * T * .5)) / (sigma * Math.Sqrt(T)));

        // Lambda Expression for Cumulative Normal Distribution
        Func <double, double> CND_1 = x => Formula.CND_1(x);
        Func <double, double> CND_2 = x => Formula.CND_2(x);
        Func <double, double> CND_3 = x => Formula.CND_3(x);
        Func <double, double> CND_4 = x => Formula.CND_4(x);

        // Single Caplet using CapletBlack
        double px = Formula.CapletBlack(T, yf, N, strike, sigma, df_e, fwd);

        // Price using different Cumulative normal distribution
        double px1 = N * df_e * yf * (fwd * CND_1(d1) - strike * CND_1(d2));
        double px2 = N * df_e * yf * (fwd * CND_2(d1) - strike * CND_2(d2));
        double px3 = N * df_e * yf * (fwd * CND_3(d1) - strike * CND_3(d2));
        double px4 = N * df_e * yf * (fwd * CND_4(d1) - strike * CND_4(d2));

        // Printing Output
        Console.WriteLine("(method CapletBlack) Price: {0}", px);
        Console.WriteLine("CND algo 1, Price: {0} ", px1);
        Console.WriteLine("CND algo 2, Price: {0} ", px2);
        Console.WriteLine("CND algo 3, Price: {0} ", px3);
        Console.WriteLine("CND algo 4, Price: {0} ", px4);
    }