Ejemplo n.º 1
0
        public void GetPPDTest()
        {
            string[] rows = new string[] { "1 MONTH", "2 MONTH", "3 MONTH", "6 MONTH", "1 YEAR", "2 YEAR", "3 YEAR", "5 YEAR", "7 YEAR", "10 YEAR" };
            string[] cols = new string[] { "1YEAR", "2 YEAR", "3 YEAR", "4 YEAR", "5 YEAR", "6 YEAR", "7 YEAR", "8 YEAR", "9 YEAR", "10 YEAR" };

            object[][] data = new object[][]
            {
                new object[] { 6.4M, 6.4M, 6.6M, 7M, 7M, 7M, 6.9M, 6.9M, 6.9M, 6.8M },
                new object[] { 6.4M, 6.4M, 6.6M, 7M, 7M, 7M, 6.9M, 6.9M, 6.9M, 6.8M },
                new object[] { 6.5M, 6.6M, 6.7M, 6.8M, 6.8M, 6.8M, 6.7M, 6.7M, 6.7M, 6.6M },
                new object[] { 6.5M, 6.6M, 6.7M, 6.8M, 6.8M, 6.8M, 6.7M, 6.7M, 6.7M, 6.5M },
                new object[] { 6.5M, 6.5M, 6.4M, 6.35M, 6.4M, 6.4M, 6.3M, 6.3M, 6.3M, 6.2M },
                new object[] { 6.4M, 6.4M, 6.2M, 6.15M, 6.1M, 6.1M, 6M, 6M, 6M, 5.9M },
                new object[] { 6.1M, 6.25M, 5.8M, 5.55M, 5.3M, 5.3M, 5.2M, 5.2M, 5.2M, 5.1M },
                new object[] { 5.7M, 5.4M, 5.2M, 5M, 4.9M, 4.9M, 4.85M, 4.85M, 4.85M, 4.75M },
                new object[] { 5.7M, 5.4M, 5.2M, 5M, 4.9M, 4.9M, 4.85M, 4.85M, 4.85M, 4.75M },
                new object[] { 5.7M, 5.4M, 5.2M, 5M, 4.9M, 4.9M, 4.85M, 4.85M, 4.85M, 4.75M }
            };

            SwaptionPPDGrid target = new SwaptionPPDGrid(rows, cols, data);

            string  expiry   = "3M";
            string  tenor    = "3Y";
            decimal expected = 6.7m;
            decimal actual   = target.GetPPD(expiry, tenor);

            Assert.AreEqual(expected, actual);

            expiry   = "2Y";
            tenor    = "5Y";
            expected = 6.1m;
            actual   = target.GetPPD(expiry, tenor);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculate an ATM volatility given a Price Per Day (PPD) value and a swap curve
        /// The curve provides forward rates for the calculation
        /// </summary>
        private static decimal CalculateAtmVolatility(SwapRate rate, DateTime baseDate, SwaptionPPDGrid grid, double expiryYearFraction, double tenorYearFraction)
        {
            // Extract the forward rate
            var swapRate = rate.ComputeSwapRate(baseDate, tenorYearFraction);

            swapRate = swapRate * 100;

            // Extract the correct ppd from the grid (compensate for the swap rate being * 100)
            var ppd = grid.GetPPD(expiryYearFraction, tenorYearFraction) * 0.01m;

            // Calculate the volatility from the parameters
            var atmVolatility = (ppd * (decimal)System.Math.Sqrt(250.0)) / swapRate;

            return(atmVolatility);
        }