final Interpolator interpolator,
/*@Real*/ final double tolerance) {
// re-adjust settlement
vars.calendar = new JointCalendar(new BMAIndex().fixingCalendar(),
new USDLibor(new Period(3, TimeUnit.Months)).fixingCalendar(),
JointCalendarRule.JoinHolidays);
vars.today = vars.calendar.adjust(Date.todaysDate());
new Settings().setEvaluationDate(vars.today);
vars.settlement = vars.calendar.advance(vars.today, vars.settlementDays, TimeUnit.Days);
final Handle<YieldTermStructure> riskFreeCurve = new Handle<YieldTermStructure>(new FlatForward(vars.settlement, 0.04, new Actual360()));
final BMAIndex bmaIndex = new BMAIndex();
final IborIndex liborIndex = new USDLibor(new Period(3, TimeUnit.Months), riskFreeCurve);
for (int i=0; i<vars.bmas; ++i) {
final Handle<Quote> f = new Handle<Quote>(vars.fractions[i]);
vars.bmaHelpers[i] = // boost::shared_ptr<RateHelper>(
new BMASwapRateHelper(f, new Period(bmaData[i].n, bmaData[i].units),
vars.settlementDays,
vars.calendar,
new Period(vars.bmaFrequency),
vars.bmaConvention,
vars.bmaDayCounter,
bmaIndex,
liborIndex);
}
final Weekday w = vars.today.weekday();
final Date lastWednesday = (w.ordinal() >= 4) ? vars.today.sub(w.ordinal() - 4) : vars.today.add(4 - w.ordinal() - 7);
final Date lastFixing = bmaIndex.fixingCalendar().adjust(lastWednesday);
bmaIndex.addFixing(lastFixing, 0.03);
vars.termStructure = new PiecewiseYieldCurve<T,I,B>(
classT, classI, classB,
vars.settlement, vars.bmaHelpers,
new Actual360(),
new Handle/*<Quote>*/[0],
new Date[0],
1.0e-12,
interpolator);
final RelinkableHandle<YieldTermStructure> curveHandle = new RelinkableHandle<YieldTermStructure>();
curveHandle.linkTo(vars.termStructure);
// check BMA swaps
final BMAIndex bma = new BMAIndex(curveHandle);
final IborIndex libor3m = new USDLibor(new Period(3, TimeUnit.Months), riskFreeCurve);
for (int i=0; i<vars.bmas; i++) {
final Period tenor = new Period(bmaData[i].n, bmaData[i].units);
final Schedule bmaSchedule = new MakeSchedule(vars.settlement,
vars.settlement.add(tenor),
new Period(vars.bmaFrequency),
bma.fixingCalendar(),
vars.bmaConvention)
.backwards()
.schedule();
final Schedule liborSchedule = new MakeSchedule(vars.settlement,
vars.settlement.add(tenor),
libor3m.tenor(),
libor3m.fixingCalendar(),
libor3m.businessDayConvention())
.endOfMonth(libor3m.endOfMonth())
.backwards()
.schedule();
final 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.termStructure()));
/*@Real*/ final double expectedFraction = bmaData[i].rate/100;
/*@Real*/ final double estimatedFraction = swap.fairLiborFraction();
/*@Real*/ final double error = Math.abs(expectedFraction-estimatedFraction);
if (error > tolerance) {