public void cpicapfloorpricesurface() { // check inflation leg vs calculation directly from inflation TS CommonVars common = new CommonVars(); double nominal = 1.0; InterpolatedCPICapFloorTermPriceSurface <Bilinear> cpiSurf = new InterpolatedCPICapFloorTermPriceSurface <Bilinear>( nominal, common.baseZeroRate, common.observationLag, common.calendar, common.convention, common.dcZCIIS, common.hii, common.nominalUK, common.cStrikesUK, common.fStrikesUK, common.cfMaturitiesUK, common.cPriceUK, common.fPriceUK); // test code - note order of indices for (int i = 0; i < common.fStrikesUK.Count; i++) { double qK = common.fStrikesUK[i]; int nMat = common.cfMaturitiesUK.Count; for (int j = 0; j < nMat; j++) { Period t = common.cfMaturitiesUK[j]; double a = common.fPriceUK[i, j]; double b = cpiSurf.floorPrice(t, qK); Utils.QL_REQUIRE(Math.Abs(a - b) < 1e-7, () => "cannot reproduce cpi floor data from surface: " + a + " vs constructed = " + b); } } for (int i = 0; i < common.cStrikesUK.Count; i++) { double qK = common.cStrikesUK[i]; int nMat = common.cfMaturitiesUK.Count; for (int j = 0; j < nMat; j++) { Period t = common.cfMaturitiesUK[j]; double a = common.cPriceUK[i, j]; double b = cpiSurf.capPrice(t, qK); QAssert.IsTrue(Math.Abs(a - b) < 1e-7, "cannot reproduce cpi cap data from surface: " + a + " vs constructed = " + b); } } // remove circular refernce common.hcpi.linkTo(null); }
public void cpicapfloorpricer() { CommonVars common = new CommonVars(); double nominal = 1.0; CPICapFloorTermPriceSurface cpiCFpriceSurf = new InterpolatedCPICapFloorTermPriceSurface <Bilinear>(nominal, common.baseZeroRate, common.observationLag, common.calendar, common.convention, common.dcZCIIS, common.hii, common.nominalUK, common.cStrikesUK, common.fStrikesUK, common.cfMaturitiesUK, common.cPriceUK, common.fPriceUK); common.cpiCFsurfUK = cpiCFpriceSurf; // interpolation pricer first // N.B. no new instrument required but we do need a new pricer Date startDate = Settings.evaluationDate(); Date maturity = (startDate + new Period(3, TimeUnit.Years)); Calendar fixCalendar = new UnitedKingdom(), payCalendar = new UnitedKingdom(); BusinessDayConvention fixConvention = BusinessDayConvention.Unadjusted, payConvention = BusinessDayConvention.ModifiedFollowing; double strike = 0.03; double baseCPI = common.hii.link.fixing(fixCalendar.adjust(startDate - common.observationLag, fixConvention)); InterpolationType observationInterpolation = InterpolationType.AsIndex; CPICapFloor aCap = new CPICapFloor(Option.Type.Call, nominal, startDate, // start date of contract (only) baseCPI, maturity, // this is pre-adjustment! fixCalendar, fixConvention, payCalendar, payConvention, strike, common.hii, common.observationLag, observationInterpolation); Handle <CPICapFloorTermPriceSurface> cpiCFsurfUKh = new Handle <CPICapFloorTermPriceSurface>(common.cpiCFsurfUK); IPricingEngine engine = new InterpolatingCPICapFloorEngine(cpiCFsurfUKh); aCap.setPricingEngine(engine); Date d = common.cpiCFsurfUK.cpiOptionDateFromTenor(new Period(3, TimeUnit.Years)); double cached = cpiCFsurfUKh.link.capPrice(d, strike); QAssert.IsTrue(Math.Abs(cached - aCap.NPV()) < 1e-10, "InterpolatingCPICapFloorEngine does not reproduce cached price: " + cached + " vs " + aCap.NPV()); // remove circular refernce common.hcpi.linkTo(null); }