public static FdmSchemeDesc ModifiedHundsdorfer()
        {
            FdmSchemeDesc ret = new FdmSchemeDesc(NQuantLibcPINVOKE.FdmSchemeDesc_ModifiedHundsdorfer(), true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
        public static FdmSchemeDesc Douglas()
        {
            FdmSchemeDesc ret = new FdmSchemeDesc(NQuantLibcPINVOKE.FdmSchemeDesc_Douglas(), true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
 public FdBlackScholesBarrierEngine(GeneralizedBlackScholesProcess process, uint tGrid, uint xGrid, uint dampingSteps, FdmSchemeDesc schemeDesc) : this(NQuantLibcPINVOKE.new_FdBlackScholesBarrierEngine__SWIG_2(GeneralizedBlackScholesProcess.getCPtr(process), tGrid, xGrid, dampingSteps, FdmSchemeDesc.getCPtr(schemeDesc)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public FdBlackScholesBarrierEngine(GeneralizedBlackScholesProcess process, uint tGrid, uint xGrid, uint dampingSteps, FdmSchemeDesc schemeDesc, bool localVol, double illegalLocalVolOverwrite) : this(NQuantLibcPINVOKE.new_FdBlackScholesBarrierEngine__SWIG_0(GeneralizedBlackScholesProcess.getCPtr(process), tGrid, xGrid, dampingSteps, FdmSchemeDesc.getCPtr(schemeDesc), localVol, illegalLocalVolOverwrite), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public FdSabrVanillaEngine(double f0, double alpha, double beta, double nu, double rho, YieldTermStructureHandle rTS, uint tGrid, uint fGrid, uint xGrid, uint dampingSteps, double scalingFactor, double eps, FdmSchemeDesc schemeDesc) : this(NQuantLibcPINVOKE.new_FdSabrVanillaEngine__SWIG_0(f0, alpha, beta, nu, rho, YieldTermStructureHandle.getCPtr(rTS), tGrid, fGrid, xGrid, dampingSteps, scalingFactor, eps, FdmSchemeDesc.getCPtr(schemeDesc)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public FdHestonDoubleBarrierEngine(HestonModel model, uint tGrid, uint xGrid, uint vGrid, uint dampingSteps, FdmSchemeDesc schemeDesc) : this(NQuantLibcPINVOKE.new_FdHestonDoubleBarrierEngine__SWIG_1(HestonModel.getCPtr(model), tGrid, xGrid, vGrid, dampingSteps, FdmSchemeDesc.getCPtr(schemeDesc)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FdmSchemeDesc obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
 public HestonSLVFokkerPlanckFdmParams(uint xGrid, uint vGrid, uint tMaxStepsPerYear, uint tMinStepsPerYear, double tStepNumberDecay, uint nRannacherTimeSteps, uint predictionCorretionSteps, double x0Density, double localVolEpsProb, uint maxIntegrationIterations, double vLowerEps, double vUpperEps, double vMin, double v0Density, double vLowerBoundDensity, double vUpperBoundDensity, double leverageFctPropEps, FdmHestonGreensFct.Algorithm greensAlgorithm, FdmSquareRootFwdOp.TransformationType trafoType, FdmSchemeDesc schemeDesc) : this(NQuantLibcPINVOKE.new_HestonSLVFokkerPlanckFdmParams(xGrid, vGrid, tMaxStepsPerYear, tMinStepsPerYear, tStepNumberDecay, nRannacherTimeSteps, predictionCorretionSteps, x0Density, localVolEpsProb, maxIntegrationIterations, vLowerEps, vUpperEps, vMin, v0Density, vLowerBoundDensity, vUpperBoundDensity, leverageFctPropEps, (int)greensAlgorithm, (int)trafoType, FdmSchemeDesc.getCPtr(schemeDesc)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#9
0
 public Fd2dBlackScholesVanillaEngine(GeneralizedBlackScholesProcess p1, GeneralizedBlackScholesProcess p2, double correlation, uint xGrid, uint yGrid, uint tGrid, uint dampingSteps, FdmSchemeDesc schemeDesc) : this(NQuantLibcPINVOKE.new_Fd2dBlackScholesVanillaEngine__SWIG_2(GeneralizedBlackScholesProcess.getCPtr(p1), GeneralizedBlackScholesProcess.getCPtr(p2), correlation, xGrid, yGrid, tGrid, dampingSteps, FdmSchemeDesc.getCPtr(schemeDesc)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public FdG2SwaptionEngine(G2 model, uint tGrid, uint xGrid, uint yGrid, uint dampingSteps, double invEps, FdmSchemeDesc schemeDesc) : this(NQuantLibcPINVOKE.new_FdG2SwaptionEngine__SWIG_0(G2.getCPtr(model), tGrid, xGrid, yGrid, dampingSteps, invEps, FdmSchemeDesc.getCPtr(schemeDesc)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#11
0
        public void testFdmHestonConvergence()
        {
            /* convergence tests based on
             * ADI finite difference schemes for option pricing in the
             * Heston model with correlation, K.J. in t'Hout and S. Foulon
             */

            //Testing FDM Heston convergence...

            using (SavedSettings backup = new SavedSettings())
            {
                HestonTestData[] values = new HestonTestData[] {
                    new HestonTestData(1.5, 0.04, 0.3, -0.9, 0.025, 0.0, 1.0, 100),
                    new HestonTestData(3.0, 0.12, 0.04, 0.6, 0.01, 0.04, 1.0, 100),
                    new HestonTestData(0.6067, 0.0707, 0.2928, -0.7571, 0.03, 0.0, 3.0, 100),
                    new HestonTestData(2.5, 0.06, 0.5, -0.1, 0.0507, 0.0469, 0.25, 100)
                };

                FdmSchemeDesc[] schemes = new FdmSchemeDesc[] {
                    new FdmSchemeDesc().Hundsdorfer(),
                    new FdmSchemeDesc().ModifiedCraigSneyd(),
                    new FdmSchemeDesc().ModifiedHundsdorfer(),
                    new FdmSchemeDesc().CraigSneyd(),
                    new FdmSchemeDesc().TrBDF2(),
                    new FdmSchemeDesc().CrankNicolson(),
                };

                int[]    tn = new int[] { 60 };
                double[] v0 = new double[] { 0.04 };

                Date todaysDate = new Date(28, 3, 2004);
                Settings.Instance.setEvaluationDate(todaysDate);

                Handle <Quote> s0 = new Handle <Quote>(new SimpleQuote(75.0));

                for (int l = 0; l < schemes.Length; ++l)
                {
                    for (int i = 0; i < values.Length; ++i)
                    {
                        for (int j = 0; j < tn.Length; ++j)
                        {
                            for (int k = 0; k < v0.Length; ++k)
                            {
                                Handle <YieldTermStructure> rTS = new Handle <YieldTermStructure>(
                                    Utilities.flatRate(values[i].r, new Actual365Fixed()));
                                Handle <YieldTermStructure> qTS = new Handle <YieldTermStructure>(
                                    Utilities.flatRate(values[i].q, new Actual365Fixed()));

                                HestonProcess hestonProcess =
                                    new HestonProcess(rTS, qTS, s0,
                                                      v0[k],
                                                      values[i].kappa,
                                                      values[i].theta,
                                                      values[i].sigma,
                                                      values[i].rho);

                                Date exerciseDate = todaysDate
                                                    + new Period(Convert.ToInt32(values[i].T * 365), TimeUnit.Days);

                                Exercise          exercise = new EuropeanExercise(exerciseDate);
                                StrikedTypePayoff payoff   = new PlainVanillaPayoff(Option.Type.Call, values[i].K);

                                VanillaOption  option = new VanillaOption(payoff, exercise);
                                IPricingEngine engine =
                                    new FdHestonVanillaEngine(
                                        new HestonModel(hestonProcess),
                                        tn[j], 101, 51, 0,
                                        schemes[l]);

                                option.setPricingEngine(engine);

                                double calculated = option.NPV();

                                IPricingEngine analyticEngine =
                                    new AnalyticHestonEngine(
                                        new HestonModel(hestonProcess), 144);

                                option.setPricingEngine(analyticEngine);
                                double expected = option.NPV();
                                if (Math.Abs(expected - calculated) / expected > 0.02 &&
                                    Math.Abs(expected - calculated) > 0.002)
                                {
                                    QAssert.Fail("Failed to reproduce expected npv"
                                                 + "\n    calculated: " + calculated
                                                 + "\n    expected:   " + expected
                                                 + "\n    tolerance:  " + 0.01);
                                }
                            }
                        }
                    }
                }
            }
        }
 public FdSimpleExtOUJumpSwingEngine(ExtOUWithJumpsProcess process, YieldTermStructure rTS, uint tGrid, uint xGrid, uint yGrid, DoublePairVector shape, FdmSchemeDesc schemeDesc) : this(NQuantLibcPINVOKE.new_FdSimpleExtOUJumpSwingEngine__SWIG_0(ExtOUWithJumpsProcess.getCPtr(process), YieldTermStructure.getCPtr(rTS), tGrid, xGrid, yGrid, DoublePairVector.getCPtr(shape), FdmSchemeDesc.getCPtr(schemeDesc)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public FdHestonVanillaEngine(HestonModel model, uint tGrid, uint xGrid, uint vGrid, uint dampingSteps, FdmSchemeDesc schemeDesc, LocalVolTermStructure leverageFct) : this(NQuantLibcPINVOKE.new_FdHestonVanillaEngine__SWIG_0(HestonModel.getCPtr(model), tGrid, xGrid, vGrid, dampingSteps, FdmSchemeDesc.getCPtr(schemeDesc), LocalVolTermStructure.getCPtr(leverageFct)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public FdBatesVanillaEngine(BatesModel model, uint tGrid, uint xGrid, uint vGrid, uint dampingSteps, FdmSchemeDesc schemeDesc) : this(NQuantLibcPINVOKE.new_FdBatesVanillaEngine__SWIG_0(BatesModel.getCPtr(model), tGrid, xGrid, vGrid, dampingSteps, FdmSchemeDesc.getCPtr(schemeDesc)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#15
0
        static void Main(string[] args)
        {
            const int xSteps       = 100;
            const int tSteps       = 25;
            const int dampingSteps = 0;

            Date today = new Date(15, Month.January, 2020);

            Settings.instance().setEvaluationDate(today);

            DayCounter dc = new Actual365Fixed();

            YieldTermStructureHandle rTS = new YieldTermStructureHandle(
                new FlatForward(today, 0.06, dc));
            YieldTermStructureHandle qTS = new YieldTermStructureHandle(
                new FlatForward(today, 0.02, dc));

            const double      strike = 110.0;
            StrikedTypePayoff payoff = new PlainVanillaPayoff(Option.Type.Put, strike);

            Date   maturityDate = today.Add(new Period(1, TimeUnit.Years));
            double maturity     = dc.yearFraction(today, maturityDate);

            Exercise exercise = new AmericanExercise(today, maturityDate);

            Instrument vanillaOption = new VanillaOption(payoff, exercise);

            QuoteHandle spot = new QuoteHandle(new SimpleQuote(100.0));
            BlackVolTermStructureHandle volatility = new BlackVolTermStructureHandle(
                new BlackConstantVol(today, new TARGET(), 0.20, dc));

            BlackScholesMertonProcess process =
                new BlackScholesMertonProcess(spot, qTS, rTS, volatility);

            vanillaOption.setPricingEngine(new FdBlackScholesVanillaEngine(
                                               process, tSteps, xSteps, dampingSteps));

            double expected = vanillaOption.NPV();

            // build an PDE engine from scratch
            Fdm1dMesher equityMesher = new FdmBlackScholesMesher(
                xSteps, process, maturity, strike,
                nullDouble(), nullDouble(), 0.0001, 1.5,
                new DoublePair(strike, 0.1));

            FdmMesherComposite mesher = new FdmMesherComposite(equityMesher);

            FdmLinearOpComposite op = new FdmBlackScholesOp(mesher, process, strike);

            FdmInnerValueCalculator calc = new FdmLogInnerValue(payoff, mesher, 0);

            QlArray x   = new QlArray(equityMesher.size());
            QlArray rhs = new QlArray(equityMesher.size());

            FdmLinearOpIterator iter = mesher.layout().begin();

            for (uint i = 0; i < rhs.size(); ++i, iter.increment())
            {
                x.set(i, mesher.location(iter, 0));
                rhs.set(i, calc.avgInnerValue(iter, maturity));
            }

            FdmBoundaryConditionSet bcSet = new FdmBoundaryConditionSet();

            FdmStepConditionComposite stepCondition =
                FdmStepConditionComposite.vanillaComposite(
                    new DividendSchedule(), exercise, mesher, calc, today, dc);


            FdmLinearOpComposite proxyOp = new FdmLinearOpCompositeProxy(
                new FdmBSDelegate(op));

            FdmBackwardSolver solver = new FdmBackwardSolver(
                proxyOp, bcSet, stepCondition, FdmSchemeDesc.Douglas());

            solver.rollback(rhs, maturity, 0.0, tSteps, dampingSteps);

            double logS = Math.Log(spot.value());

            double calculated = new CubicNaturalSpline(x, rhs).call(logS);

            Console.WriteLine("Homebrew PDE engine        : {0:0.0000}", calculated);
            Console.WriteLine("FdBlackScholesVanillaEngine: {0:0.0000}", expected);
        }