Beispiel #1
0
        public void testParity()
        {
            // Testing put-call parity for capped-floored CMS coupons

            CommonVars vars = new CommonVars();

            List <Handle <SwaptionVolatilityStructure> > swaptionVols = new List <Handle <SwaptionVolatilityStructure> >();

            swaptionVols.Add(vars.atmVol);
            swaptionVols.Add(vars.SabrVolCube1);
            swaptionVols.Add(vars.SabrVolCube2);

            SwapIndex swapIndex = new EuriborSwapIsdaFixA(new Period(10, TimeUnit.Years),
                                                          vars.iborIndex.forwardingTermStructure());
            Date   startDate               = vars.termStructure.link.referenceDate() + new Period(20, TimeUnit.Years);
            Date   paymentDate             = startDate + new Period(1, TimeUnit.Years);
            Date   endDate                 = paymentDate;
            double nominal                 = 1.0;
            double?infiniteCap             = null;
            double?infiniteFloor           = null;
            double gearing                 = 1.0;
            double spread                  = 0.0;
            double discount                = vars.termStructure.link.discount(paymentDate);
            CappedFlooredCmsCoupon swaplet = new CappedFlooredCmsCoupon(nominal, paymentDate,
                                                                        startDate, endDate, swapIndex.fixingDays(), swapIndex, gearing, spread, infiniteCap, infiniteFloor,
                                                                        startDate, endDate, vars.iborIndex.dayCounter());

            for (double strike = .02; strike < .12; strike += 0.05)
            {
                CappedFlooredCmsCoupon caplet = new CappedFlooredCmsCoupon(nominal, paymentDate,
                                                                           startDate, endDate, swapIndex.fixingDays(), swapIndex, gearing, spread, strike, infiniteFloor,
                                                                           startDate, endDate, vars.iborIndex.dayCounter());
                CappedFlooredCmsCoupon floorlet = new CappedFlooredCmsCoupon(nominal, paymentDate,
                                                                             startDate, endDate, swapIndex.fixingDays(), swapIndex, gearing, spread, infiniteCap, strike,
                                                                             startDate, endDate, vars.iborIndex.dayCounter());

                for (int i = 0; i < swaptionVols.Count; ++i)
                {
                    for (int j = 0; j < vars.yieldCurveModels.Count; ++j)
                    {
                        vars.numericalPricers[j].setSwaptionVolatility(swaptionVols[i]);
                        vars.analyticPricers[j].setSwaptionVolatility(swaptionVols[i]);
                        List <CmsCouponPricer> pricers = new List <CmsCouponPricer>(2);
                        pricers.Add(vars.numericalPricers[j]);
                        pricers.Add(vars.analyticPricers[j]);
                        for (int k = 0; k < pricers.Count; ++k)
                        {
                            swaplet.setPricer(pricers[k]);
                            caplet.setPricer(pricers[k]);
                            floorlet.setPricer(pricers[k]);
                            double swapletPrice = swaplet.price(vars.termStructure) +
                                                  nominal * swaplet.accrualPeriod() * strike * discount;
                            double capletPrice   = caplet.price(vars.termStructure);
                            double floorletPrice = floorlet.price(vars.termStructure);
                            double difference    = Math.Abs(capletPrice + floorletPrice - swapletPrice);
                            double tol           = 2.0e-5;
                            bool   linearTsr     = k == 0 && j == vars.yieldCurveModels.Count - 1;
                            if (linearTsr)
                            {
                                tol = 1.0e-7;
                            }
                            if (difference > tol)
                            {
                                QAssert.Fail("\nCoupon payment date: " + paymentDate +
                                             "\nCoupon start date:   " + startDate +
                                             "\nCoupon gearing:      " + (gearing) +
                                             "\nCoupon swap index:   " + swapIndex.name() +
                                             "\nCoupon spread:       " + (spread) +
                                             "\nstrike:              " + (strike) +
                                             "\nCoupon DayCounter:   " + vars.iborIndex.dayCounter() +
                                             "\nYieldCurve Model:    " + vars.yieldCurveModels[j] +
                                             (k == 0 ? "\nNumerical Pricer" : "\nAnalytic Pricer") +
                                             (linearTsr ? " (Linear TSR Model)" : "") +
                                             "\nSwaplet price:       " + (swapletPrice) +
                                             "\nCaplet price:        " + (capletPrice) +
                                             "\nFloorlet price:      " + (floorletPrice) +
                                             "\ndifference:          " + difference +
                                             "\ntolerance:           " + (tol));
                            }
                        }
                    }
                }
            }
        }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(CappedFlooredCmsCoupon obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Beispiel #3
0
        public void testFairRate()
        {
            // Testing Hagan-pricer flat-vol equivalence for coupons
            CommonVars vars = new CommonVars();

            SwapIndex swapIndex = new SwapIndex("EuriborSwapIsdaFixA",
                                                new Period(10, TimeUnit.Years),
                                                vars.iborIndex.fixingDays(),
                                                vars.iborIndex.currency(),
                                                vars.iborIndex.fixingCalendar(),
                                                new Period(1, TimeUnit.Years),
                                                BusinessDayConvention.Unadjusted,
                                                vars.iborIndex.dayCounter(),//??
                                                vars.iborIndex);

            // FIXME
            //shared_ptr<SwapIndex> swapIndex(new
            //    EuriborSwapIsdaFixA(10*Years, vars.iborIndex->termStructure()));
            Date   startDate              = vars.termStructure.link.referenceDate() + new Period(20, TimeUnit.Years);
            Date   paymentDate            = startDate + new Period(1, TimeUnit.Years);
            Date   endDate                = paymentDate;
            double nominal                = 1.0;
            double?infiniteCap            = null;
            double?infiniteFloor          = null;
            double gearing                = 1.0;
            double spread                 = 0.0;
            CappedFlooredCmsCoupon coupon = new CappedFlooredCmsCoupon(nominal, paymentDate,
                                                                       startDate, endDate,
                                                                       swapIndex.fixingDays(), swapIndex,
                                                                       gearing, spread,
                                                                       infiniteCap, infiniteFloor,
                                                                       startDate, endDate,
                                                                       vars.iborIndex.dayCounter());

            for (int j = 0; j < vars.yieldCurveModels.Count; ++j)
            {
                vars.numericalPricers[j].setSwaptionVolatility(vars.atmVol);
                coupon.setPricer(vars.numericalPricers[j]);
                double rate0 = coupon.rate();

                vars.analyticPricers[j].setSwaptionVolatility(vars.atmVol);
                coupon.setPricer(vars.analyticPricers[j]);
                double rate1 = coupon.rate();

                double difference = Math.Abs(rate1 - rate0);
                double tol        = 2.0e-4;
                bool   linearTsr  = j == vars.yieldCurveModels.Count - 1;

                if (difference > tol)
                {
                    QAssert.Fail("\nCoupon payment date: " + paymentDate +
                                 "\nCoupon start date:   " + startDate +
                                 "\nCoupon floor:        " + (infiniteFloor) +
                                 "\nCoupon gearing:      " + (gearing) +
                                 "\nCoupon swap index:   " + swapIndex.name() +
                                 "\nCoupon spread:       " + (spread) +
                                 "\nCoupon cap:          " + (infiniteCap) +
                                 "\nCoupon DayCounter:   " + vars.iborIndex.dayCounter() +
                                 "\nYieldCurve Model:    " + vars.yieldCurveModels[j] +
                                 "\nNumerical Pricer:    " + (rate0) + (linearTsr ? " (Linear TSR Model)" : "") +
                                 "\nAnalytic Pricer:     " + (rate1) +
                                 "\ndifference:          " + (difference) +
                                 "\ntolerance:           " + (tol));
                }
            }
        }
Beispiel #4
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(CappedFlooredCmsCoupon obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }