Ejemplo n.º 1
0
        LiborForwardModelProcess makeProcess(Matrix volaComp)
        {
            int factors = (volaComp.empty() ? 1 : volaComp.columns());

            IborIndex index = makeIndex();
            LiborForwardModelProcess process= new LiborForwardModelProcess(len, index,null);

            LfmCovarianceParameterization fct=new LfmHullWhiteParameterization(
                                                    process,
                                                    makeCapVolCurve(Settings.evaluationDate()),
                                                    volaComp * Matrix.transpose(volaComp), factors);

            process.setCovarParam(fct);

            return process;
        }
Ejemplo n.º 2
0
        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);
        }