예제 #1
0
        public SwapRateHelper(double rate,
                              SwapIndex swapIndex,
                              Handle <Quote> spread = null,
                              Period fwdStart       = null,
                              // exogenous discounting curve
                              Handle <YieldTermStructure> discount = null,
                              Pillar.Choice pillarChoice           = Pillar.Choice.LastRelevantDate,
                              Date customPillarDate = null)
            : base(rate)
        {
            settlementDays_  = swapIndex.fixingDays();
            tenor_           = swapIndex.tenor();
            pillarChoice_    = pillarChoice;
            calendar_        = swapIndex.fixingCalendar();
            fixedConvention_ = swapIndex.fixedLegConvention();
            fixedFrequency_  = swapIndex.fixedLegTenor().frequency();
            fixedDayCount_   = swapIndex.dayCounter();
            spread_          = spread ?? new Handle <Quote>();
            fwdStart_        = fwdStart ?? new Period(0, TimeUnit.Days);
            discountHandle_  = discount ?? new Handle <YieldTermStructure>();

            // take fixing into account
            iborIndex_ = swapIndex.iborIndex().clone(termStructureHandle_);
            // We want to be notified of changes of fixings, but we don't
            // want notifications from termStructureHandle_ (they would
            // interfere with bootstrapping.)
            iborIndex_.registerWith(update);
            spread_.registerWith(update);
            discountHandle_.registerWith(update);

            pillarDate_ = customPillarDate;
            initializeDates();
        }
예제 #2
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));
                }
            }
        }