QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdsimpleextoujumpswingengine.cpp
Go to the documentation of this file.
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 fdsimpleextoujumpswingengine.cpp
21 \brief Finite Differences engine for simple swing options
22*/
23
24
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
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
mesher for a exponential jump mesher with high mean reversion rate and low jump intensity
extended Ornstein-Uhlenbeck process
Ornstein Uhlenbeck process plus exp jumps (Kluge Model)
1-d mesher for the Black-Scholes process (in ln(S))
const ext::shared_ptr< YieldTermStructure > rTS_
inner value calculator for the Ornstein Uhlenbeck plus exponential jumps model (Kluge Model)
memory layout of a fdm linear operator
FdmMesher which is a composite of Fdm1dMesher.
solver for simple swing options based on ext OU-Jump (Kluge) Model
One-dimensional grid mesher.
simple swing step condition
composite of fdm step conditions
Finite Differences engine for simple swing options.
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.
One-dimensional simple uniform grid mesher.
Interest-rate term structure.