/src/quantlib/ql/experimental/finitedifferences/fdextoujumpvanillaengine.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
20 | | /*! \file fdoujumpvanillaengine.cpp |
21 | | \brief Finite Differences Ornstein Uhlenbeck plus exponential jumps engine |
22 | | for simple swing options |
23 | | */ |
24 | | |
25 | | #include <ql/exercise.hpp> |
26 | | #include <ql/experimental/finitedifferences/fdextoujumpvanillaengine.hpp> |
27 | | #include <ql/experimental/finitedifferences/fdmextoujumpmodelinnervalue.hpp> |
28 | | #include <ql/experimental/finitedifferences/fdmextoujumpsolver.hpp> |
29 | | #include <ql/experimental/processes/extendedornsteinuhlenbeckprocess.hpp> |
30 | | #include <ql/experimental/processes/extouwithjumpsprocess.hpp> |
31 | | #include <ql/methods/finitedifferences/meshers/exponentialjump1dmesher.hpp> |
32 | | #include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp> |
33 | | #include <ql/methods/finitedifferences/meshers/fdmsimpleprocess1dmesher.hpp> |
34 | | #include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp> |
35 | | #include <ql/methods/finitedifferences/stepconditions/fdmamericanstepcondition.hpp> |
36 | | #include <ql/methods/finitedifferences/stepconditions/fdmbermudanstepcondition.hpp> |
37 | | #include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp> |
38 | | #include <ql/termstructures/yieldtermstructure.hpp> |
39 | | #include <utility> |
40 | | |
41 | | namespace QuantLib { |
42 | | |
43 | | FdExtOUJumpVanillaEngine::FdExtOUJumpVanillaEngine( |
44 | | ext::shared_ptr<ExtOUWithJumpsProcess> process, |
45 | | ext::shared_ptr<YieldTermStructure> rTS, |
46 | | Size tGrid, |
47 | | Size xGrid, |
48 | | Size yGrid, |
49 | | ext::shared_ptr<Shape> shape, |
50 | | const FdmSchemeDesc& schemeDesc) |
51 | 0 | : process_(std::move(process)), rTS_(std::move(rTS)), shape_(std::move(shape)), tGrid_(tGrid), |
52 | 0 | xGrid_(xGrid), yGrid_(yGrid), schemeDesc_(schemeDesc) {} |
53 | | |
54 | 0 | void FdExtOUJumpVanillaEngine::calculate() const { |
55 | | // 1. Mesher |
56 | 0 | const Time maturity |
57 | 0 | = rTS_->dayCounter().yearFraction(rTS_->referenceDate(), |
58 | 0 | arguments_.exercise->lastDate()); |
59 | 0 | const ext::shared_ptr<StochasticProcess1D> ouProcess( |
60 | 0 | process_->getExtendedOrnsteinUhlenbeckProcess()); |
61 | 0 | const ext::shared_ptr<Fdm1dMesher> xMesher( |
62 | 0 | new FdmSimpleProcess1dMesher(xGrid_, ouProcess,maturity)); |
63 | |
|
64 | 0 | const ext::shared_ptr<Fdm1dMesher> yMesher( |
65 | 0 | new ExponentialJump1dMesher(yGrid_, |
66 | 0 | process_->beta(), |
67 | 0 | process_->jumpIntensity(), |
68 | 0 | process_->eta())); |
69 | |
|
70 | 0 | const ext::shared_ptr<FdmMesher> mesher( |
71 | 0 | new FdmMesherComposite(xMesher, yMesher)); |
72 | | |
73 | | // 2. Calculator |
74 | 0 | const ext::shared_ptr<FdmInnerValueCalculator> calculator( |
75 | 0 | new FdmExtOUJumpModelInnerValue(arguments_.payoff, mesher, shape_)); |
76 | | |
77 | | // 3. Step conditions |
78 | 0 | const ext::shared_ptr<FdmStepConditionComposite> conditions = |
79 | 0 | FdmStepConditionComposite::vanillaComposite( |
80 | 0 | DividendSchedule(), arguments_.exercise, |
81 | 0 | mesher, calculator, |
82 | 0 | rTS_->referenceDate(), rTS_->dayCounter()); |
83 | | |
84 | | // 4. Boundary conditions |
85 | 0 | const FdmBoundaryConditionSet boundaries; |
86 | | |
87 | | // 5. set-up solver |
88 | 0 | FdmSolverDesc solverDesc = { mesher, boundaries, conditions, |
89 | 0 | calculator, maturity, tGrid_, 0 }; |
90 | |
|
91 | 0 | const ext::shared_ptr<FdmExtOUJumpSolver> solver( |
92 | 0 | new FdmExtOUJumpSolver(Handle<ExtOUWithJumpsProcess>(process_), |
93 | 0 | rTS_, solverDesc, schemeDesc_)); |
94 | | |
95 | 0 | const Real x = process_->initialValues()[0]; |
96 | 0 | const Real y = process_->initialValues()[1]; |
97 | 0 | results_.value = solver->valueAt(x, y); |
98 | 0 | } |
99 | | } |