Esempio n. 1
0
        public void testFlatTermVolatilityStripping2()
        {
            // Testing forward/forward vol stripping from flat term vol
            // surface using OptionletStripper2 class...");

            CommonVars vars = new CommonVars();

            Settings.setEvaluationDate(Date.Today);

            vars.setFlatTermVolCurve();
            vars.setFlatTermVolSurface();

            IborIndex iborIndex = new Euribor6M(vars.yieldTermStructure);

            // optionletstripper1
            OptionletStripper1 optionletStripper1 = new OptionletStripper1(vars.flatTermVolSurface,
                                                                           iborIndex, null, vars.accuracy);

            StrippedOptionletAdapter strippedOptionletAdapter1 = new StrippedOptionletAdapter(optionletStripper1);

            Handle <OptionletVolatilityStructure> vol1 = new Handle <OptionletVolatilityStructure>(strippedOptionletAdapter1);

            vol1.link.enableExtrapolation();

            // optionletstripper2
            OptionletStripper optionletStripper2 = new OptionletStripper2(optionletStripper1, vars.flatTermVolCurve);

            StrippedOptionletAdapter strippedOptionletAdapter2 = new StrippedOptionletAdapter(optionletStripper2);

            Handle <OptionletVolatilityStructure> vol2 = new Handle <OptionletVolatilityStructure>(strippedOptionletAdapter2);

            vol2.link.enableExtrapolation();

            // consistency check: diff(stripped vol1-stripped vol2)
            for (int strikeIndex = 0; strikeIndex < vars.strikes.Count; ++strikeIndex)
            {
                for (int tenorIndex = 0; tenorIndex < vars.optionTenors.Count; ++tenorIndex)
                {
                    double strippedVol1 = vol1.link.volatility(vars.optionTenors[tenorIndex], vars.strikes[strikeIndex], true);

                    double strippedVol2 = vol2.link.volatility(vars.optionTenors[tenorIndex], vars.strikes[strikeIndex], true);

                    // vol from flat vol surface (for comparison only)
                    double flatVol = vars.flatTermVolSurface.volatility(vars.optionTenors[tenorIndex], vars.strikes[strikeIndex], true);

                    double error = Math.Abs(strippedVol1 - strippedVol2);
                    if (error > vars.tolerance)
                    {
                        QAssert.Fail("\noption tenor:  " + vars.optionTenors[tenorIndex] +
                                     "\nstrike:        " + vars.strikes[strikeIndex] +
                                     "\nstripped vol1: " + strippedVol1 +
                                     "\nstripped vol2: " + strippedVol2 +
                                     "\nflat vol:      " + flatVol +
                                     "\nerror:         " + error +
                                     "\ntolerance:     " + vars.tolerance);
                    }
                }
            }
        }
Esempio n. 2
0
        public void testFlatTermVolatilityStripping1()
        {
            // Testing forward/forward vol stripping from flat term vol
            // surface using OptionletStripper1 class...

            CommonVars vars = new CommonVars();

            Settings.setEvaluationDate(new Date(28, Month.October, 2013));

            vars.setFlatTermVolSurface();

            IborIndex iborIndex = new Euribor6M(vars.yieldTermStructure);

            OptionletStripper optionletStripper1 = new OptionletStripper1(vars.flatTermVolSurface,
                                                                          iborIndex, null, vars.accuracy);

            StrippedOptionletAdapter strippedOptionletAdapter = new StrippedOptionletAdapter(optionletStripper1);

            Handle <OptionletVolatilityStructure> vol = new Handle <OptionletVolatilityStructure>(strippedOptionletAdapter);

            vol.link.enableExtrapolation();

            BlackCapFloorEngine strippedVolEngine = new BlackCapFloorEngine(vars.yieldTermStructure, vol);

            CapFloor cap;

            for (int tenorIndex = 0; tenorIndex < vars.optionTenors.Count; ++tenorIndex)
            {
                for (int strikeIndex = 0; strikeIndex < vars.strikes.Count; ++strikeIndex)
                {
                    cap = new MakeCapFloor(CapFloorType.Cap, vars.optionTenors[tenorIndex], iborIndex,
                                           vars.strikes[strikeIndex], new Period(0, TimeUnit.Days))
                          .withPricingEngine(strippedVolEngine);

                    double priceFromStrippedVolatility = cap.NPV();

                    IPricingEngine blackCapFloorEngineConstantVolatility = new BlackCapFloorEngine(vars.yieldTermStructure,
                                                                                                   vars.termV[tenorIndex, strikeIndex]);

                    cap.setPricingEngine(blackCapFloorEngineConstantVolatility);
                    double priceFromConstantVolatility = cap.NPV();

                    double error = Math.Abs(priceFromStrippedVolatility - priceFromConstantVolatility);
                    if (error > vars.tolerance)
                    {
                        QAssert.Fail("\noption tenor:       " + vars.optionTenors[tenorIndex] +
                                     "\nstrike:             " + vars.strikes[strikeIndex] +
                                     "\nstripped vol price: " + priceFromStrippedVolatility +
                                     "\nconstant vol price: " + priceFromConstantVolatility +
                                     "\nerror:              " + error +
                                     "\ntolerance:          " + vars.tolerance);
                    }
                }
            }
        }