Пример #1
0
        public Fdm1DimSolver(FdmSolverDesc solverDesc,
                             FdmSchemeDesc schemeDesc,
                             FdmLinearOpComposite op)
        {
            solverDesc_     = solverDesc;
            schemeDesc_     = schemeDesc;
            op_             = op;
            thetaCondition_ = new FdmSnapshotCondition(
                0.99 * Math.Min(1.0 / 365.0,
                                solverDesc.condition.stoppingTimes().empty()
                            ? solverDesc.maturity
                            : solverDesc.condition.stoppingTimes().First()));

            conditions_ = FdmStepConditionComposite.joinConditions(thetaCondition_,
                                                                   solverDesc.condition);
            x_             = new InitializedList <double>(solverDesc.mesher.layout().size());
            initialValues_ = new InitializedList <double>(solverDesc.mesher.layout().size());
            resultValues_  = new Vector(solverDesc.mesher.layout().size());

            FdmMesher         mesher = solverDesc.mesher;
            FdmLinearOpLayout layout = mesher.layout();

            FdmLinearOpIterator endIter = layout.end();

            for (FdmLinearOpIterator iter = layout.begin(); iter != endIter;
                 ++iter)
            {
                initialValues_[iter.index()]
                    = solverDesc_.calculator.avgInnerValue(iter,
                                                           solverDesc.maturity);
                x_[iter.index()] = mesher.location(iter, 0);
            }
        }
Пример #2
0
 public FdmHullWhiteSolver(
     Handle <HullWhite> model,
     FdmSolverDesc solverDesc,
     FdmSchemeDesc schemeDesc = null)
 {
     solverDesc_ = solverDesc;
     schemeDesc_ = schemeDesc ?? new FdmSchemeDesc().Hundsdorfer();
     model_      = model;
     model_.registerWith(update);
 }
Пример #3
0
 public FdmBackwardSolver(FdmLinearOpComposite map,
                          FdmBoundaryConditionSet bcSet,
                          FdmStepConditionComposite condition,
                          FdmSchemeDesc schemeDesc)
 {
     map_        = map;
     bcSet_      = bcSet;
     condition_  = condition;
     schemeDesc_ = schemeDesc;
 }
Пример #4
0
 public MakeFdBlackScholesVanillaEngine(GeneralizedBlackScholesProcess process)
 {
     process_                  = process;
     tGrid_                    = 100;
     xGrid_                    = 100;
     dampingSteps_             = 0;
     schemeDesc_               = new FdmSchemeDesc().Douglas();
     localVol_                 = false;
     illegalLocalVolOverwrite_ = null;
     quantoHelper_             = null;
     cashDividendModel_        = FdBlackScholesVanillaEngine.CashDividendModel.Spot;
 }
Пример #5
0
 public FdHullWhiteSwaptionEngine(
     HullWhite model,
     int tGrid                = 100, int xGrid   = 100,
     int dampingSteps         = 0, double invEps = 1e-5,
     FdmSchemeDesc schemeDesc = null)
     : base(model)
 {
     tGrid_        = tGrid;
     xGrid_        = xGrid;
     dampingSteps_ = dampingSteps;
     schemeDesc_   = schemeDesc == null ? new FdmSchemeDesc().Douglas() : schemeDesc;
     invEps_       = invEps;
 }
Пример #6
0
 public FdmBlackScholesSolver(
     Handle <GeneralizedBlackScholesProcess> process,
     double strike,
     FdmSolverDesc solverDesc,
     FdmSchemeDesc schemeDesc        = null,
     bool localVol                   = false,
     double?illegalLocalVolOverwrite = null)
 {
     process_    = process;
     strike_     = strike;
     solverDesc_ = solverDesc;
     schemeDesc_ = schemeDesc ?? new FdmSchemeDesc().Douglas();
     localVol_   = localVol;
     illegalLocalVolOverwrite_ = illegalLocalVolOverwrite;
 }
Пример #7
0
        // Constructor
        public FdBlackScholesRebateEngine(
            GeneralizedBlackScholesProcess process,
            int tGrid = 100, int xGrid = 100, int dampingSteps = 0,
            FdmSchemeDesc schemeDesc        = null,
            bool localVol                   = false,
            double?illegalLocalVolOverwrite = null)
        {
            process_                  = process;
            tGrid_                    = tGrid;
            xGrid_                    = xGrid;
            dampingSteps_             = dampingSteps;
            schemeDesc_               = schemeDesc == null ? new FdmSchemeDesc().Douglas() : schemeDesc;
            localVol_                 = localVol;
            illegalLocalVolOverwrite_ = illegalLocalVolOverwrite;

            process_.registerWith(update);
        }
Пример #8
0
        public FdBlackScholesVanillaEngine(
            GeneralizedBlackScholesProcess process,
            FdmQuantoHelper quantoHelper = null,
            int tGrid = 100, int xGrid = 100, int dampingSteps = 0,
            FdmSchemeDesc schemeDesc            = null,
            bool localVol                       = false,
            double?illegalLocalVolOverwrite     = null,
            CashDividendModel cashDividendModel = CashDividendModel.Spot)
        {
            process_                  = process;
            tGrid_                    = tGrid;
            xGrid_                    = xGrid;
            dampingSteps_             = dampingSteps;
            schemeDesc_               = schemeDesc == null ? new FdmSchemeDesc().Douglas() : schemeDesc;
            localVol_                 = localVol;
            illegalLocalVolOverwrite_ = illegalLocalVolOverwrite;
            quantoHelper_             = quantoHelper;

            process_.registerWith(update);
        }
Пример #9
0
        public FdmBlackScholesSolver(
            Handle <GeneralizedBlackScholesProcess> process,
            double strike,
            FdmSolverDesc solverDesc,
            FdmSchemeDesc schemeDesc              = null,
            bool localVol                         = false,
            double?illegalLocalVolOverwrite       = null,
            Handle <FdmQuantoHelper> quantoHelper = null)
        {
            process_    = process;
            strike_     = strike;
            solverDesc_ = solverDesc;
            schemeDesc_ = schemeDesc ?? new FdmSchemeDesc().Douglas();
            localVol_   = localVol;
            illegalLocalVolOverwrite_ = illegalLocalVolOverwrite;
            quantoHelper_             = quantoHelper;
            quantoHelper_             = quantoHelper ?? new Handle <FdmQuantoHelper>();

            process_.registerWith(update);
            quantoHelper_.registerWith(update);
        }
Пример #10
0
        public void rollback(ref object a,
                             double from, double to,
                             int steps, int dampingSteps)
        {
            double deltaT    = from - to;
            int    allSteps  = steps + dampingSteps;
            double dampingTo = from - (deltaT * dampingSteps) / allSteps;

            if (dampingSteps > 0 &&
                schemeDesc_.type != FdmSchemeDesc.FdmSchemeType.ImplicitEulerType)
            {
                ImplicitEulerScheme implicitEvolver = new ImplicitEulerScheme(map_, bcSet_);
                FiniteDifferenceModel <ImplicitEulerScheme> dampingModel
                    = new FiniteDifferenceModel <ImplicitEulerScheme>(implicitEvolver, condition_.stoppingTimes());

                dampingModel.rollback(ref a, from, dampingTo,
                                      dampingSteps, condition_);
            }

            switch (schemeDesc_.type)
            {
            case FdmSchemeDesc.FdmSchemeType.HundsdorferType:
            {
                HundsdorferScheme hsEvolver = new HundsdorferScheme(schemeDesc_.theta, schemeDesc_.mu,
                                                                    map_, bcSet_);
                FiniteDifferenceModel <HundsdorferScheme>
                hsModel = new FiniteDifferenceModel <HundsdorferScheme>(hsEvolver, condition_.stoppingTimes());
                hsModel.rollback(ref a, dampingTo, to, steps, condition_);
            }
            break;

            case FdmSchemeDesc.FdmSchemeType.DouglasType:
            {
                DouglasScheme dsEvolver = new DouglasScheme(schemeDesc_.theta, map_, bcSet_);
                FiniteDifferenceModel <DouglasScheme>
                dsModel = new FiniteDifferenceModel <DouglasScheme>(dsEvolver, condition_.stoppingTimes());
                dsModel.rollback(ref a, dampingTo, to, steps, condition_);
            }
            break;

            case FdmSchemeDesc.FdmSchemeType.CrankNicolsonType:
            {
                CrankNicolsonScheme cnEvolver = new CrankNicolsonScheme(schemeDesc_.theta, map_, bcSet_);
                FiniteDifferenceModel <CrankNicolsonScheme>
                cnModel = new FiniteDifferenceModel <CrankNicolsonScheme>(cnEvolver, condition_.stoppingTimes());
                cnModel.rollback(ref a, dampingTo, to, steps, condition_);
            }
            break;

            case FdmSchemeDesc.FdmSchemeType.CraigSneydType:
            {
                CraigSneydScheme csEvolver = new CraigSneydScheme(schemeDesc_.theta, schemeDesc_.mu,
                                                                  map_, bcSet_);
                FiniteDifferenceModel <CraigSneydScheme>
                csModel = new FiniteDifferenceModel <CraigSneydScheme>(csEvolver, condition_.stoppingTimes());
                csModel.rollback(ref a, dampingTo, to, steps, condition_);
            }
            break;

            case FdmSchemeDesc.FdmSchemeType.ModifiedCraigSneydType:
            {
                ModifiedCraigSneydScheme csEvolver = new ModifiedCraigSneydScheme(schemeDesc_.theta,
                                                                                  schemeDesc_.mu,
                                                                                  map_, bcSet_);
                FiniteDifferenceModel <ModifiedCraigSneydScheme>
                mcsModel = new FiniteDifferenceModel <ModifiedCraigSneydScheme>(csEvolver, condition_.stoppingTimes());
                mcsModel.rollback(ref a, dampingTo, to, steps, condition_);
            }
            break;

            case FdmSchemeDesc.FdmSchemeType.ImplicitEulerType:
            {
                ImplicitEulerScheme implicitEvolver = new ImplicitEulerScheme(map_, bcSet_);
                FiniteDifferenceModel <ImplicitEulerScheme>
                implicitModel = new FiniteDifferenceModel <ImplicitEulerScheme>(implicitEvolver, condition_.stoppingTimes());
                implicitModel.rollback(ref a, from, to, allSteps, condition_);
            }
            break;

            case FdmSchemeDesc.FdmSchemeType.ExplicitEulerType:
            {
                ExplicitEulerScheme explicitEvolver = new ExplicitEulerScheme(map_, bcSet_);
                FiniteDifferenceModel <ExplicitEulerScheme>
                explicitModel = new FiniteDifferenceModel <ExplicitEulerScheme>(explicitEvolver, condition_.stoppingTimes());
                explicitModel.rollback(ref a, dampingTo, to, steps, condition_);
            }
            break;

            case FdmSchemeDesc.FdmSchemeType.MethodOfLinesType:
            {
                MethodOfLinesScheme methodOfLines = new MethodOfLinesScheme(schemeDesc_.theta, schemeDesc_.mu, map_, bcSet_);
                FiniteDifferenceModel <MethodOfLinesScheme>
                molModel = new FiniteDifferenceModel <MethodOfLinesScheme>(methodOfLines, condition_.stoppingTimes());
                molModel.rollback(ref a, dampingTo, to, steps, condition_);
            }
            break;

            case FdmSchemeDesc.FdmSchemeType.TrBDF2Type:
            {
                FdmSchemeDesc    trDesc    = new FdmSchemeDesc().CraigSneyd();
                CraigSneydScheme hsEvolver = new CraigSneydScheme(trDesc.theta, trDesc.mu, map_, bcSet_);

                TrBDF2Scheme <CraigSneydScheme> trBDF2 = new TrBDF2Scheme <CraigSneydScheme>(
                    schemeDesc_.theta, map_, hsEvolver, bcSet_, schemeDesc_.mu);

                FiniteDifferenceModel <TrBDF2Scheme <CraigSneydScheme> >
                trBDF2Model = new FiniteDifferenceModel <TrBDF2Scheme <CraigSneydScheme> >(trBDF2, condition_.stoppingTimes());
                trBDF2Model.rollback(ref a, dampingTo, to, steps, condition_);
            }
            break;

            default:
                Utils.QL_FAIL("Unknown scheme type");
                break;
            }
        }
Пример #11
0
 public MakeFdBlackScholesVanillaEngine withFdmSchemeDesc(FdmSchemeDesc schemeDesc)
 {
     schemeDesc_ = schemeDesc;
     return(this);
 }