public void testFairSpread() { // Testing Eonia-swap calculation of fair floating spread... CommonVars vars = new CommonVars(); Period[] lengths = { new Period(1, TimeUnit.Years), new Period(2, TimeUnit.Years), new Period(5, TimeUnit.Years), new Period(10, TimeUnit.Years), new Period(20, TimeUnit.Years) }; double[] rates = { 0.04, 0.05, 0.06, 0.07 }; for (int i = 0; i < lengths.Length; i++) { for (int j = 0; j < rates.Length; j++) { OvernightIndexedSwap swap = vars.makeSwap(lengths[i], rates[j], 0.0); double?fairSpread = swap.fairSpread(); swap = vars.makeSwap(lengths[i], rates[j], fairSpread.Value); if (Math.Abs(swap.NPV()) > 1.0e-10) { QAssert.Fail("Recalculating with implied spread:" + "\n length: " + lengths[i] + "\n fixed rate: " + rates[j] + "\nfair spread: " + fairSpread + "\n swap value: " + swap.NPV()); } } } }
public void testFairRate() { // Testing Eonia-swap calculation of fair fixed rate... CommonVars vars = new CommonVars(); Period[] lengths = new Period[] { new Period(1, TimeUnit.Years), new Period(2, TimeUnit.Years), new Period(5, TimeUnit.Years), new Period(10, TimeUnit.Years), new Period(20, TimeUnit.Years) }; double[] spreads = { -0.001, -0.01, 0.0, 0.01, 0.001 }; for (int i = 0; i < lengths.Length; i++) { for (int j = 0; j < spreads.Length; j++) { OvernightIndexedSwap swap = vars.makeSwap(lengths[i], 0.0, spreads[j]); swap = vars.makeSwap(lengths[i], swap.fairRate().Value, spreads[j]); if (Math.Abs(swap.NPV()) > 1.0e-10) { QAssert.Fail("recalculating with implied rate:\n" + " length: " + lengths[i] + " \n" + " floating spread: " + (spreads[j]) + "\n" + " swap value: " + swap.NPV()); } } } }
public void testCachedValue() { // Testing Eonia-swap calculation against cached value... CommonVars vars = new CommonVars(); Settings.setEvaluationDate(vars.today); vars.settlement = vars.calendar.advance(vars.today, vars.settlementDays, TimeUnit.Days); double flat = 0.05; vars.eoniaTermStructure.linkTo(Utilities.flatRate(vars.settlement, flat, new Actual360())); double fixedRate = Math.Exp(flat) - 1; OvernightIndexedSwap swap = vars.makeSwap(new Period(1, TimeUnit.Years), fixedRate, 0.0); double cachedNPV = 0.001730450147; double tolerance = 1.0e-11; if (Math.Abs(swap.NPV() - cachedNPV) > tolerance) { QAssert.Fail("\nfailed to reproduce cached swap value:" + "\ncalculated: " + swap.NPV() + "\n expected: " + cachedNPV + "\n tolerance:" + tolerance); } }