QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdextoujumpvanillaengine.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/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
41namespace QuantLib {
42
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 : process_(std::move(process)), rTS_(std::move(rTS)), shape_(std::move(shape)), tGrid_(tGrid),
52 xGrid_(xGrid), yGrid_(yGrid), schemeDesc_(schemeDesc) {}
53
55 // 1. Mesher
56 const Time maturity
57 = rTS_->dayCounter().yearFraction(rTS_->referenceDate(),
58 arguments_.exercise->lastDate());
59 const ext::shared_ptr<StochasticProcess1D> ouProcess(
60 process_->getExtendedOrnsteinUhlenbeckProcess());
61 const ext::shared_ptr<Fdm1dMesher> xMesher(
62 new FdmSimpleProcess1dMesher(xGrid_, ouProcess,maturity));
63
64 const ext::shared_ptr<Fdm1dMesher> yMesher(
66 process_->beta(),
67 process_->jumpIntensity(),
68 process_->eta()));
69
70 const ext::shared_ptr<FdmMesher> mesher(
71 new FdmMesherComposite(xMesher, yMesher));
72
73 // 2. Calculator
74 const ext::shared_ptr<FdmInnerValueCalculator> calculator(
76
77 // 3. Step conditions
78 const ext::shared_ptr<FdmStepConditionComposite> conditions =
81 mesher, calculator,
82 rTS_->referenceDate(), rTS_->dayCounter());
83
84 // 4. Boundary conditions
85 const FdmBoundaryConditionSet boundaries;
86
87 // 5. set-up solver
88 FdmSolverDesc solverDesc = { mesher, boundaries, conditions,
89 calculator, maturity, tGrid_, 0 };
90
91 const ext::shared_ptr<FdmExtOUJumpSolver> solver(
93 rTS_, solverDesc, schemeDesc_));
94
95 const Real x = process_->initialValues()[0];
96 const Real y = process_->initialValues()[1];
97 results_.value = solver->valueAt(x, y);
98 }
99}
FdExtOUJumpVanillaEngine(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< Shape > shape_
const ext::shared_ptr< YieldTermStructure > rTS_
static ext::shared_ptr< FdmStepConditionComposite > vanillaComposite(const DividendSchedule &schedule, const ext::shared_ptr< Exercise > &exercise, const ext::shared_ptr< FdmMesher > &mesher, const ext::shared_ptr< FdmInnerValueCalculator > &calculator, const Date &refDate, const DayCounter &dayCounter)
Shared handle to an observable.
Definition: handle.hpp:41
ext::shared_ptr< Exercise > exercise
Definition: option.hpp:65
ext::shared_ptr< Payoff > payoff
Definition: option.hpp:64
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
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
STL namespace.