QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdklugeextouspreadengine.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
21#include <ql/exercise.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
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Option exercise classes and payoff function.
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)
FD Kluge/extended Ornstein-Uhlenbeck engine for a simple power-gas spread option.
american step condition for multi dimensional problems
bermudan step condition for multi dimensional problems
const ext::shared_ptr< YieldTermStructure > rTS_
Kluge/extended Ornstein-Uhlenbeck FDM solver.
memory layout of a fdm linear operator
FdmMesher which is a composite of Fdm1dMesher.
One-dimensional grid mesher.
inner value calculator for a spread payoff
composite of fdm step conditions
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
std::size_t Size
size of a container
Definition: types.hpp:58
joint Kluge process an d Ornstein Uhlenbeck process
Definition: any.hpp:35
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
STL namespace.
Interest-rate term structure.