"\n expected rate: ", expectedRate));
}
}
// check swaps
final IborIndex euribor6m = new Euribor6M(curveHandle);
for (int i=0; i<vars.swaps; i++) {
final Period tenor = new Period(swapData[i].n, swapData[i].units);
final VanillaSwap swap = new MakeVanillaSwap(tenor, euribor6m, 0.0)
.withEffectiveDate(vars.settlement)
.withFixedLegDayCount(vars.fixedLegDayCounter)
.withFixedLegTenor(new Period(vars.fixedLegFrequency))
.withFixedLegConvention(vars.fixedLegConvention)
.withFixedLegTerminationDateConvention(vars.fixedLegConvention)
.value();
/*@Rate*/ final double expectedRate = swapData[i].rate/100;
/*@Rate*/ final double estimatedRate = swap.fairRate();
/*@Spread*/ final double error = Math.abs(expectedRate-estimatedRate);
if (error > tolerance) {
throw new RuntimeException(
String.format("%d %s %s %f %s %f %s %f %s %f",
swapData[i].n, " year(s) swap:\n",
"\n estimated rate: ", estimatedRate,
"\n expected rate: ", expectedRate,
"\n error: ", error,
"\n tolerance: ", tolerance));
}
}
// check bonds
vars.termStructure = new PiecewiseYieldCurve<T,I,B>(
classT, classI, classB,
vars.settlement, vars.bondHelpers,
new Actual360(),
new Handle/*<Quote>*/[0],
new Date[0],
1.0e-12,
interpolator);
curveHandle.linkTo(vars.termStructure);
for (int i=0; i<vars.bonds; i++) {
final Date maturity = vars.calendar.advance(vars.today, bondData[i].n, bondData[i].units);
final Date issue = vars.calendar.advance(maturity, -bondData[i].length, TimeUnit.Years);
/*@Rate*/ final double[] coupons = new double[1];
coupons[0] = bondData[i].coupon/100.0;
final FixedRateBond bond = new FixedRateBond(vars.bondSettlementDays, 100.0,
vars.schedules[i], coupons,
vars.bondDayCounter, vars.bondConvention,
vars.bondRedemption, issue);
final PricingEngine bondEngine = new DiscountingBondEngine(curveHandle);
bond.setPricingEngine(bondEngine);
/*@Real*/ final double expectedPrice = bondData[i].price, estimatedPrice = bond.cleanPrice();
/*@Real*/ final double error = Math.abs(expectedPrice-estimatedPrice);
if (error > tolerance) {
throw new RuntimeException(
String.format("#%d %s %s %f %s %f %s %f",
i+1, " bond failure:",
"\n estimated price: ", estimatedPrice,
"\n expected price: ", expectedPrice,
"\n error: ", error));
}
}
// check FRA
vars.termStructure = new PiecewiseYieldCurve<T,I,B>(
classT, classI, classB,
vars.settlement, vars.fraHelpers,
new Actual360(),
new Handle/*<Quote>*/[0],
new Date[0],
1.0e-12,
interpolator);
curveHandle.linkTo(vars.termStructure);
final IborIndex euribor3m = new Euribor3M(curveHandle);
for (int i=0; i<vars.fras; i++) {
final Date start = vars.calendar.advance(vars.settlement,
fraData[i].n,
fraData[i].units,
euribor3m.businessDayConvention(),
euribor3m.endOfMonth());
final Date end = vars.calendar.advance(start, 3, TimeUnit.Months,
euribor3m.businessDayConvention(),
euribor3m.endOfMonth());
final ForwardRateAgreement fra = new ForwardRateAgreement(start, end, Position.Long,
fraData[i].rate/100, 100.0,
euribor3m, curveHandle);
/*@Rate*/ final double expectedRate = fraData[i].rate/100;