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); } }
public FdmHullWhiteSolver( Handle <HullWhite> model, FdmSolverDesc solverDesc, FdmSchemeDesc schemeDesc = null) { solverDesc_ = solverDesc; schemeDesc_ = schemeDesc ?? new FdmSchemeDesc().Hundsdorfer(); model_ = model; model_.registerWith(update); }
public FdmBackwardSolver(FdmLinearOpComposite map, FdmBoundaryConditionSet bcSet, FdmStepConditionComposite condition, FdmSchemeDesc schemeDesc) { map_ = map; bcSet_ = bcSet; condition_ = condition; schemeDesc_ = schemeDesc; }
public MakeFdHestonVanillaEngine(HestonModel hestonModel) { hestonModel_ = hestonModel; tGrid_ = 100; xGrid_ = 100; vGrid_ = 50; dampingSteps_ = 0; schemeDesc_ = new FdmSchemeDesc().Hundsdorfer(); leverageFct_ = null; quantoHelper_ = null; }
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; }
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; }
public FdmHestonSolver( Handle <HestonProcess> process, FdmSolverDesc solverDesc, FdmSchemeDesc schemeDesc = null, Handle <FdmQuantoHelper> quantoHelper = null, LocalVolTermStructure leverageFct = null) { process_ = process; solverDesc_ = solverDesc; schemeDesc_ = schemeDesc ?? new FdmSchemeDesc().Douglas(); quantoHelper_ = quantoHelper == null ? new Handle <FdmQuantoHelper>() : quantoHelper; leverageFct_ = leverageFct; }
// Constructor public FdHestonRebateEngine( HestonModel model, int tGrid = 100, int xGrid = 100, int vGrid = 50, int dampingSteps = 0, FdmSchemeDesc schemeDesc = null, LocalVolTermStructure leverageFct = null) : base(model) { tGrid_ = tGrid; xGrid_ = xGrid; vGrid_ = vGrid; dampingSteps_ = dampingSteps; schemeDesc_ = schemeDesc == null ? new FdmSchemeDesc().Hundsdorfer() : schemeDesc; leverageFct_ = leverageFct; model_.registerWith(update); }
// Constructor public FdBlackScholesBarrierEngine( 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); }
public FdHestonVanillaEngine( HestonModel model, FdmQuantoHelper quantoHelper, int tGrid, int xGrid, int vGrid, int dampingSteps, FdmSchemeDesc schemeDesc, LocalVolTermStructure leverageFct) : base(model) { tGrid_ = tGrid; xGrid_ = xGrid; vGrid_ = vGrid; dampingSteps_ = dampingSteps; schemeDesc_ = schemeDesc; leverageFct_ = leverageFct; strikes_ = new List <double>(); cachedArgs2results_ = new List <Pair <DividendVanillaOption.Arguments, OneAssetOption.Results> >(); quantoHelper_ = quantoHelper; }
public FdHestonVanillaEngine( HestonModel model, int tGrid = 100, int xGrid = 100, int vGrid = 50, int dampingSteps = 0, FdmSchemeDesc schemeDesc = null, LocalVolTermStructure leverageFct = null) : base(model) { tGrid_ = tGrid; xGrid_ = xGrid; vGrid_ = vGrid; dampingSteps_ = dampingSteps; schemeDesc_ = schemeDesc == null ? new FdmSchemeDesc().Hundsdorfer() : schemeDesc; leverageFct_ = leverageFct; strikes_ = new List <double>(); cachedArgs2results_ = new List <Pair <DividendVanillaOption.Arguments, OneAssetOption.Results> >(); quantoHelper_ = null; model_.registerWith(update); }
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); }
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); }
public MakeFdHestonVanillaEngine withFdmSchemeDesc( FdmSchemeDesc schemeDesc) { schemeDesc_ = schemeDesc; return(this); }
public MakeFdBlackScholesVanillaEngine withFdmSchemeDesc(FdmSchemeDesc schemeDesc) { schemeDesc_ = schemeDesc; return(this); }
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; } }