public FdmAffineModelTermStructure( Vector r, Calendar cal, DayCounter dayCounter, Date referenceDate, Date modelReferenceDate, IAffineModel model) : base(referenceDate, cal, dayCounter) { r_ = r; t_ = dayCounter.yearFraction(modelReferenceDate, referenceDate); model_ = model; model_.registerWith(update); }
public void testCapletPricing() { //"Testing caplet pricing..."; //SavedSettings backup; const int size = 10; #if QL_USE_INDEXED_COUPON const double tolerance = 1e-5; #else const double tolerance = 1e-12; #endif IborIndex index = makeIndex(); LiborForwardModelProcess process = new LiborForwardModelProcess(size, index); // set-up pricing engine OptionletVolatilityStructure capVolCurve = makeCapVolCurve(Settings.evaluationDate()); Vector variances = new LfmHullWhiteParameterization(process, capVolCurve).covariance(0.0, null).diagonal(); LmVolatilityModel volaModel = new LmFixedVolatilityModel(Vector.Sqrt(variances), process.fixingTimes()); LmCorrelationModel corrModel = new LmExponentialCorrelationModel(size, 0.3); IAffineModel model = (IAffineModel)(new LiborForwardModel(process, volaModel, corrModel)); Handle <YieldTermStructure> termStructure = process.index().forwardingTermStructure(); AnalyticCapFloorEngine engine1 = new AnalyticCapFloorEngine(model, termStructure); Cap cap1 = new Cap(process.cashFlows(), new InitializedList <double>(size, 0.04)); cap1.setPricingEngine(engine1); const double expected = 0.015853935178; double calculated = cap1.NPV(); if (Math.Abs(expected - calculated) > tolerance) { Assert.Fail("Failed to reproduce npv" + "\n calculated: " + calculated + "\n expected: " + expected); } }