QL.info("Testing use of today's LIBOR fixings in swap curve...");
final CommonVars vars = new CommonVars();
final RateHelper[] swapHelpers = new RateHelper[vars.swaps];
final IborIndex euribor6m = new Euribor6M();
for (int i=0; i<vars.swaps; i++) {
final Handle<Quote> r = new Handle<Quote>(vars.rates[i+vars.deposits]);
swapHelpers[i] = new SwapRateHelper(
r, new Period(swapData[i].n, swapData[i].units),
vars.calendar,
vars.fixedLegFrequency, vars.fixedLegConvention,
vars.fixedLegDayCounter, euribor6m);
}
vars.termStructure = new PiecewiseYieldCurve(
Discount.class, LogLinear.class, IterativeBootstrap.class,
vars.settlement,
swapHelpers,
new Actual360());
final Handle<YieldTermStructure> curveHandle = new Handle<YieldTermStructure>(vars.termStructure);
final IborIndex index = 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, index, 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();
/*@Real*/ final double tolerance = 1.0e-9;
if (Math.abs(expectedRate-estimatedRate) > tolerance) {
throw new RuntimeException(
String.format("%s %d %s %s %f %s %s %f",
"before LIBOR fixing:\n",
swapData[i].n, " year(s) swap:\n",
" estimated rate: ", estimatedRate, "\n",
" expected rate: ", expectedRate));
}
}
final Flag f = new Flag();
vars.termStructure.addObserver(f);
f.lower();
index.addFixing(vars.today, 0.0425);
if (!f.isUp())
throw new RuntimeException("Observer was not notified of rate fixing");
for (int i=0; i<vars.swaps; i++) {