QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdsimpleextoujumpswingengine.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2011 Klaus Spanderen
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
25#include <ql/experimental/finitedifferences/fdmextoujumpmodelinnervalue.hpp>
26#include <ql/experimental/finitedifferences/fdmsimple3dextoujumpsolver.hpp>
27#include <ql/experimental/finitedifferences/fdsimpleextoujumpswingengine.hpp>
28#include <ql/experimental/processes/extendedornsteinuhlenbeckprocess.hpp>
29#include <ql/experimental/processes/extouwithjumpsprocess.hpp>
30#include <ql/methods/finitedifferences/meshers/exponentialjump1dmesher.hpp>
31#include <ql/methods/finitedifferences/meshers/fdmblackscholesmesher.hpp>
32#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
33#include <ql/methods/finitedifferences/meshers/fdmsimpleprocess1dmesher.hpp>
34#include <ql/methods/finitedifferences/meshers/uniform1dmesher.hpp>
35#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
36#include <ql/methods/finitedifferences/solvers/fdm3dimsolver.hpp>
37#include <ql/methods/finitedifferences/stepconditions/fdmsimpleswingcondition.hpp>
38#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
39#include <ql/termstructures/yieldtermstructure.hpp>
40#include <utility>
41
42namespace QuantLib {
43
45 ext::shared_ptr<ExtOUWithJumpsProcess> process,
46 ext::shared_ptr<YieldTermStructure> rTS,
47 Size tGrid,
48 Size xGrid,
49 Size yGrid,
50 ext::shared_ptr<Shape> shape,
51 const FdmSchemeDesc& schemeDesc)
52 : process_(std::move(process)), rTS_(std::move(rTS)), shape_(std::move(shape)), tGrid_(tGrid),
53 xGrid_(xGrid), yGrid_(yGrid), schemeDesc_(schemeDesc) {}
54
56
57 // 1. Exercise
58 ext::shared_ptr<SwingExercise> swingExercise(
59 ext::dynamic_pointer_cast<SwingExercise>(arguments_.exercise));
60
61 QL_REQUIRE(swingExercise, "Swing exercise supported only");
62
63 // 2. Mesher
64 const std::vector<Time> exerciseTimes
65 = swingExercise->exerciseTimes(rTS_->dayCounter(),
66 rTS_->referenceDate());
67
68 const Time maturity = exerciseTimes.back();
69 const ext::shared_ptr<StochasticProcess1D> ouProcess(
70 process_->getExtendedOrnsteinUhlenbeckProcess());
71 const ext::shared_ptr<Fdm1dMesher> xMesher(
72 new FdmSimpleProcess1dMesher(xGrid_, ouProcess,maturity));
73
74 const ext::shared_ptr<Fdm1dMesher> yMesher(
76 process_->beta(),
77 process_->jumpIntensity(),
78 process_->eta()));
79 const ext::shared_ptr<Fdm1dMesher> exerciseMesher(
81 0, static_cast<Real>(arguments_.maxExerciseRights),
83
84 const ext::shared_ptr<FdmMesher> mesher(
85 new FdmMesherComposite(xMesher, yMesher, exerciseMesher));
86
87 // 3. Calculator
88 ext::shared_ptr<FdmInnerValueCalculator> calculator(
89 new FdmZeroInnerValue());
90 // 4. Step conditions
91 std::list<ext::shared_ptr<StepCondition<Array> > > stepConditions;
92 std::list<std::vector<Time> > stoppingTimes;
93
94 // 4.1 Bermudan step conditions
95 stoppingTimes.push_back(exerciseTimes);
96
97 ext::shared_ptr<FdmInnerValueCalculator> exerciseCalculator(
99
100 stepConditions.push_back(ext::shared_ptr<StepCondition<Array> >(
102 exerciseTimes, mesher, exerciseCalculator,
104
105 ext::shared_ptr<FdmStepConditionComposite> conditions(
106 new FdmStepConditionComposite(stoppingTimes, stepConditions));
107
108
109 // 5. Boundary conditions
110 const FdmBoundaryConditionSet boundaries;
111
112 // 6. set-up solver
113 FdmSolverDesc solverDesc = { mesher, boundaries, conditions,
114 calculator, maturity, tGrid_, 0 };
115
116 const ext::shared_ptr<FdmSimple3dExtOUJumpSolver> solver(
119 rTS_, solverDesc, schemeDesc_));
120
121 const Real x = process_->initialValues()[0];
122 const Real y = process_->initialValues()[1];
123
124 results_.value = solver->valueAt(x, y, 0.0);
125 }
126}
FdSimpleExtOUJumpSwingEngine(ext::shared_ptr< ExtOUWithJumpsProcess > p, ext::shared_ptr< YieldTermStructure > rTS, Size tGrid=50, Size xGrid=200, Size yGrid=50, ext::shared_ptr< Shape > shape=ext::shared_ptr< Shape >(), const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Hundsdorfer())
const ext::shared_ptr< ExtOUWithJumpsProcess > process_
const ext::shared_ptr< YieldTermStructure > rTS_
Shared handle to an observable.
Definition: handle.hpp:41
condition to be applied at every time step
ext::shared_ptr< SwingExercise > exercise
ext::shared_ptr< StrikedTypePayoff > payoff
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
STL namespace.