QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdklugeextouspreadengine.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
20
21#include <ql/exercise.hpp>
22#include <ql/experimental/finitedifferences/fdklugeextouspreadengine.hpp>
23#include <ql/experimental/finitedifferences/fdmklugeextousolver.hpp>
24#include <ql/experimental/finitedifferences/fdmspreadpayoffinnervalue.hpp>
25#include <ql/experimental/processes/extendedornsteinuhlenbeckprocess.hpp>
26#include <ql/experimental/processes/extouwithjumpsprocess.hpp>
27#include <ql/experimental/processes/klugeextouprocess.hpp>
28#include <ql/methods/finitedifferences/meshers/exponentialjump1dmesher.hpp>
29#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
30#include <ql/methods/finitedifferences/meshers/fdmsimpleprocess1dmesher.hpp>
31#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
32#include <ql/methods/finitedifferences/stepconditions/fdmamericanstepcondition.hpp>
33#include <ql/methods/finitedifferences/stepconditions/fdmbermudanstepcondition.hpp>
34#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
35#include <ql/termstructures/yieldtermstructure.hpp>
36#include <utility>
37
38namespace QuantLib {
39
41 ext::shared_ptr<KlugeExtOUProcess> klugeOUProcess,
42 ext::shared_ptr<YieldTermStructure> rTS,
43 Size tGrid,
44 Size xGrid,
45 Size yGrid,
46 Size uGrid,
47 ext::shared_ptr<GasShape> gasShape,
48 ext::shared_ptr<PowerShape> powerShape,
49 const FdmSchemeDesc& schemeDesc)
50 : klugeOUProcess_(std::move(klugeOUProcess)), rTS_(std::move(rTS)), tGrid_(tGrid),
51 xGrid_(xGrid), yGrid_(yGrid), uGrid_(uGrid), gasShape_(std::move(gasShape)),
52 powerShape_(std::move(powerShape)), 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<ExtOUWithJumpsProcess> klugeProcess
60 = klugeOUProcess_->getKlugeProcess();
61 const ext::shared_ptr<StochasticProcess1D> ouProcess
62 = klugeProcess->getExtendedOrnsteinUhlenbeckProcess();
63 const ext::shared_ptr<Fdm1dMesher> xMesher(
64 new FdmSimpleProcess1dMesher(xGrid_, ouProcess,maturity));
65
66 const ext::shared_ptr<Fdm1dMesher> yMesher(
68 klugeProcess->beta(),
69 klugeProcess->jumpIntensity(),
70 klugeProcess->eta()));
71
72 const ext::shared_ptr<Fdm1dMesher> uMesher(
74 klugeOUProcess_->getExtOUProcess(),
75 maturity));
76
77 const ext::shared_ptr<FdmMesher> mesher(
78 new FdmMesherComposite(xMesher, yMesher, uMesher));
79
80 // 2. Calculator
81 ext::shared_ptr<BasketPayoff> basketPayoff =
82 ext::dynamic_pointer_cast<BasketPayoff>(arguments_.payoff);
83 QL_REQUIRE(basketPayoff," basket payoff expected");
84
85 const ext::shared_ptr<Payoff> zeroStrikeCall(
87
88 const ext::shared_ptr<FdmInnerValueCalculator> gasPrice(
89 new FdmExpExtOUInnerValueCalculator(zeroStrikeCall,
90 mesher, gasShape_, 2));
91
92 const ext::shared_ptr<FdmInnerValueCalculator> powerPrice(
93 new FdmExtOUJumpModelInnerValue(zeroStrikeCall,mesher,powerShape_));
94
95 const ext::shared_ptr<FdmInnerValueCalculator> calculator(
96 new FdmSpreadPayoffInnerValue(basketPayoff, powerPrice, gasPrice));
97
98 // 3. Step conditions
99 const ext::shared_ptr<FdmStepConditionComposite> conditions =
102 mesher, calculator,
103 rTS_->referenceDate(), rTS_->dayCounter());
104
105 // 4. Boundary conditions
106 const FdmBoundaryConditionSet boundaries;
107
108 // 5. set-up solver
109 FdmSolverDesc solverDesc = { mesher, boundaries, conditions,
110 calculator, maturity, tGrid_, 0 };
111
112 const ext::shared_ptr<FdmKlugeExtOUSolver<3> > solver(
115 rTS_, solverDesc, schemeDesc_));
116
117 std::vector<Real> x(3);
118 x[0] = klugeOUProcess_->initialValues()[0];
119 x[1] = klugeOUProcess_->initialValues()[1];
120 x[2] = klugeOUProcess_->initialValues()[2];
121
122 results_.value = solver->valueAt(x);
123 }
124}
const ext::shared_ptr< GasShape > gasShape_
const ext::shared_ptr< KlugeExtOUProcess > klugeOUProcess_
const ext::shared_ptr< PowerShape > powerShape_
FdKlugeExtOUSpreadEngine(ext::shared_ptr< KlugeExtOUProcess > klugeOUProcess, ext::shared_ptr< YieldTermStructure > rTS, Size tGrid=25, Size xGrid=50, Size yGrid=10, Size uGrid=25, ext::shared_ptr< GasShape > gasShape=ext::shared_ptr< GasShape >(), ext::shared_ptr< PowerShape > powerShape=ext::shared_ptr< PowerShape >(), const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Hundsdorfer())
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
Plain-vanilla payoff.
Definition: payoffs.hpp:105
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
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.