public YoYInflationCapFloor makeYoYCapFloor(CapFloorType type, List <CashFlow> leg, double strike, double volatility, int which) { YoYInflationCapFloor result = null; switch (type) { case CapFloorType.Cap: result = new YoYInflationCap(leg, new List <double>() { strike }); break; case CapFloorType.Floor: result = new YoYInflationFloor(leg, new List <double>() { strike }); break; default: Utils.QL_FAIL("unknown YoYInflation cap/floor type"); break; } result.setPricingEngine(makeEngine(volatility, which)); return(result); }
public void testConsistency() { // Testing consistency between yoy inflation cap,floor and collar... CommonVars vars = new CommonVars(); int[] lengths = { 1, 2, 3, 5, 7, 10, 15, 20 }; double[] cap_rates = { 0.01, 0.025, 0.029, 0.03, 0.031, 0.035, 0.07 }; double[] floor_rates = { 0.01, 0.025, 0.029, 0.03, 0.031, 0.035, 0.07 }; double[] vols = { 0.001, 0.005, 0.010, 0.015, 0.020 }; for (int whichPricer = 0; whichPricer < 3; whichPricer++) { for (int i = 0; i < lengths.Length; i++) { for (int j = 0; j < cap_rates.Length; j++) { for (int k = 0; k < floor_rates.Length; k++) { for (int l = 0; l < vols.Length; l++) { List <CashFlow> leg = vars.makeYoYLeg(vars.evaluationDate, lengths[i]); YoYInflationCapFloor cap = vars.makeYoYCapFloor(CapFloorType.Cap, leg, cap_rates[j], vols[l], whichPricer); YoYInflationCapFloor floor = vars.makeYoYCapFloor(CapFloorType.Floor, leg, floor_rates[k], vols[l], whichPricer); YoYInflationCollar collar = new YoYInflationCollar(leg, new List <double>() { cap_rates[j] }, new List <double>() { floor_rates[k] }); collar.setPricingEngine(vars.makeEngine(vols[l], whichPricer)); if (Math.Abs((cap.NPV() - floor.NPV()) - collar.NPV()) > 1e-6) { Assert.Fail( "inconsistency between cap, floor and collar:\n" + " length: " + lengths[i] + " years\n" + " volatility: " + "\n" + " cap value: " + cap.NPV() + " at strike: " + "\n" + " floor value: " + floor.NPV() + " at strike: " + "\n" + " collar value: " + collar.NPV()); } // test re-composition by optionlets, N.B. ONE per year double capletsNPV = 0.0; List <YoYInflationCapFloor> caplets = new List <YoYInflationCapFloor>(); for (int m = 0; m < lengths[i] * 1; m++) { caplets.Add(cap.optionlet(m)); caplets[m].setPricingEngine(vars.makeEngine(vols[l], whichPricer)); capletsNPV += caplets[m].NPV(); } if (Math.Abs(cap.NPV() - capletsNPV) > 1e-6) { Assert.Fail( "sum of caplet NPVs does not equal cap NPV:\n" + " length: " + lengths[i] + " years\n" + " volatility: " + "\n" + " cap value: " + cap.NPV() + " at strike: " + "\n" + " sum of caplets value: " + capletsNPV + " at strike (first): " + caplets[0].capRates()[0] + "\n" ); } double floorletsNPV = 0.0; List <YoYInflationCapFloor> floorlets = new List <YoYInflationCapFloor>(); for (int m = 0; m < lengths[i] * 1; m++) { floorlets.Add(floor.optionlet(m)); floorlets[m].setPricingEngine(vars.makeEngine(vols[l], whichPricer)); floorletsNPV += floorlets[m].NPV(); } if (Math.Abs(floor.NPV() - floorletsNPV) > 1e-6) { Assert.Fail( "sum of floorlet NPVs does not equal floor NPV:\n" + " length: " + lengths[i] + " years\n" + " volatility: " + "\n" + " cap value: " + floor.NPV() + " at strike: " + floor_rates[j] + "\n" + " sum of floorlets value: " + floorletsNPV + " at strike (first): " + floorlets[0].floorRates()[0] + "\n" ); } double collarletsNPV = 0.0; List <YoYInflationCapFloor> collarlets = new List <YoYInflationCapFloor>(); for (int m = 0; m < lengths[i] * 1; m++) { collarlets.Add(collar.optionlet(m)); collarlets[m].setPricingEngine(vars.makeEngine(vols[l], whichPricer)); collarletsNPV += collarlets[m].NPV(); } if (Math.Abs(collar.NPV() - collarletsNPV) > 1e-6) { Assert.Fail( "sum of collarlet NPVs does not equal floor NPV:\n" + " length: " + lengths[i] + " years\n" + " volatility: " + vols[l] + "\n" + " cap value: " + collar.NPV() + " at strike floor: " + floor_rates[j] + " at strike cap: " + cap_rates[j] + "\n" + " sum of collarlets value: " + collarletsNPV + " at strike floor (first): " + collarlets[0].floorRates()[0] + " at strike cap (first): " + collarlets[0].capRates()[0] + "\n" ); } } } } } } // pricer loop // remove circular refernce vars.hy.linkTo(new YoYInflationTermStructure()); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(YoYInflationCapFloor obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(YoYInflationCapFloor obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }