protected override void initializeDates() { // if the evaluation date is not a business day // then move to the next business day JointCalendar jc = new JointCalendar(calendar_, iborIndex_.fixingCalendar()); Date referenceDate = jc.adjust(evaluationDate_); earliestDate_ = calendar_.advance(referenceDate, new Period(settlementDays_, TimeUnit.Days), BusinessDayConvention.Following); Date maturity = earliestDate_ + tenor_; // dummy BMA index with curve/swap arguments BMAIndex clonedIndex = new BMAIndex(termStructureHandle_); Schedule bmaSchedule = new MakeSchedule().from(earliestDate_).to(maturity) .withTenor(bmaPeriod_) .withCalendar(bmaIndex_.fixingCalendar()) .withConvention(bmaConvention_) .backwards().value(); Schedule liborSchedule = new MakeSchedule().from(earliestDate_).to(maturity) .withTenor(iborIndex_.tenor()) .withCalendar(iborIndex_.fixingCalendar()) .withConvention(iborIndex_.businessDayConvention()) .endOfMonth(iborIndex_.endOfMonth()) .backwards().value(); swap_ = new BMASwap(BMASwap.Type.Payer, 100.0, liborSchedule, 0.75, // arbitrary 0.0, iborIndex_, iborIndex_.dayCounter(), bmaSchedule, clonedIndex, bmaDayCount_); swap_.setPricingEngine(new DiscountingSwapEngine(iborIndex_.forwardingTermStructure())); Date d = calendar_.adjust(swap_.maturityDate(), BusinessDayConvention.Following); int w = d.weekday(); Date nextWednesday = (w >= 4) ? d + new Period((11 - w), TimeUnit.Days) : d + new Period((4 - w), TimeUnit.Days); latestDate_ = clonedIndex.valueDate(clonedIndex.fixingCalendar().adjust(nextWednesday)); }
public void testBMACurveConsistency <T, I, B>(CommonVars vars, I interpolator, double tolerance) where T : ITraits <YieldTermStructure>, new() where I : IInterpolationFactory, new() where B : IBootStrap <PiecewiseYieldCurve>, new() { // readjust settlement vars.calendar = new JointCalendar(new BMAIndex().fixingCalendar(), new USDLibor(new Period(3, TimeUnit.Months)).fixingCalendar(), JointCalendar.JointCalendarRule.JoinHolidays); vars.today = vars.calendar.adjust(Date.Today); Settings.setEvaluationDate(vars.today); vars.settlement = vars.calendar.advance(vars.today, vars.settlementDays, TimeUnit.Days); Handle <YieldTermStructure> riskFreeCurve = new Handle <YieldTermStructure>( new FlatForward(vars.settlement, 0.04, new Actual360())); BMAIndex bmaIndex = new BMAIndex(); IborIndex liborIndex = new USDLibor(new Period(3, TimeUnit.Months), riskFreeCurve); for (int i = 0; i < vars.bmas; ++i) { Handle <Quote> f = new Handle <Quote>(vars.fractions[i]); vars.bmaHelpers.Add(new BMASwapRateHelper(f, new Period(vars.bmaData[i].n, vars.bmaData[i].units), vars.settlementDays, vars.calendar, new Period(vars.bmaFrequency), vars.bmaConvention, vars.bmaDayCounter, bmaIndex, liborIndex)); } int w = vars.today.weekday(); Date lastWednesday = (w >= 4) ? vars.today - (w - 4) : vars.today + (4 - w - 7); Date lastFixing = bmaIndex.fixingCalendar().adjust(lastWednesday); bmaIndex.addFixing(lastFixing, 0.03); vars.termStructure = new PiecewiseYieldCurve <T, I, B>(vars.settlement, vars.bmaHelpers, new Actual360(), new List <Handle <Quote> >(), new List <Date>(), 1.0e-12, interpolator); RelinkableHandle <YieldTermStructure> curveHandle = new RelinkableHandle <YieldTermStructure>(); curveHandle.linkTo(vars.termStructure); // check BMA swaps BMAIndex bma = new BMAIndex(curveHandle); IborIndex libor3m = new USDLibor(new Period(3, TimeUnit.Months), riskFreeCurve); for (int i = 0; i < vars.bmas; i++) { Period tenor = new Period(vars.bmaData[i].n, vars.bmaData[i].units); Schedule bmaSchedule = new MakeSchedule().from(vars.settlement) .to(vars.settlement + tenor) .withFrequency(vars.bmaFrequency) .withCalendar(bma.fixingCalendar()) .withConvention(vars.bmaConvention) .backwards() .value(); Schedule liborSchedule = new MakeSchedule().from(vars.settlement) .to(vars.settlement + tenor) .withTenor(libor3m.tenor()) .withCalendar(libor3m.fixingCalendar()) .withConvention(libor3m.businessDayConvention()) .endOfMonth(libor3m.endOfMonth()) .backwards() .value(); BMASwap swap = new BMASwap(BMASwap.Type.Payer, 100.0, liborSchedule, 0.75, 0.0, libor3m, libor3m.dayCounter(), bmaSchedule, bma, vars.bmaDayCounter); swap.setPricingEngine(new DiscountingSwapEngine(libor3m.forwardingTermStructure())); double expectedFraction = vars.bmaData[i].rate / 100, estimatedFraction = swap.fairLiborFraction(); double error = Math.Abs(expectedFraction - estimatedFraction); QAssert.IsTrue(error < tolerance, vars.bmaData[i].n + " year(s) BMA swap:\n" + "\n estimated libor fraction: " + estimatedFraction + "\n expected libor fraction: " + expectedFraction + "\n error: " + error + "\n tolerance: " + tolerance); } // this is a workaround for grabage collection // garbage collection needs a proper solution IndexManager.instance().clearHistories(); }