QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmcev1dmesher.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2018 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
22#include <ql/shared_ptr.hpp>
23#include <ql/methods/finitedifferences/meshers/fdmcev1dmesher.hpp>
24#include <ql/methods/finitedifferences/meshers/uniform1dmesher.hpp>
25#include <ql/methods/finitedifferences/meshers/concentrating1dmesher.hpp>
26
27#include <ql/methods/finitedifferences/utilities/cevrndcalculator.hpp>
28
29
30namespace QuantLib {
31
33 Size size,
34 Real f0, Real alpha, Real beta,
35 Time maturity, Real eps,Real scaleFactor,
36 const std::pair<Real, Real>& cPoint)
37
38 : Fdm1dMesher(size) {
39
40 const CEVRNDCalculator rndCalculator(f0, alpha, beta);
41
42 const Real upperBound =
43 scaleFactor*rndCalculator.invcdf(1-eps, maturity);
44
45 const Real massAtZero = rndCalculator.massAtZero(maturity);
46
47 const Real lowerBound = (massAtZero > eps)
48 ? ((beta < 0)? QL_EPSILON : 0.0)
49 : Real(rndCalculator.invcdf(eps, maturity)/scaleFactor);
50
51
52 ext::shared_ptr<Fdm1dMesher> helper;
53 if ( cPoint.first != Null<Real>()
54 && cPoint.first >= lowerBound && cPoint.first <= upperBound) {
55
56 helper = ext::make_shared<Concentrating1dMesher>(
57 lowerBound, upperBound,size, cPoint);
58 }
59 else {
60 helper = ext::make_shared<Uniform1dMesher>(
61 lowerBound, upperBound, size );
62 }
63
64 std::copy(helper->locations().begin(),
65 helper->locations().end(),
66 locations_.begin());
67
68 for (Size i=0; i < locations_.size(); ++i) {
69 dplus_[i] = helper->dplus(i);
70 dminus_[i] = helper->dminus(i);
71 }
72 }
73}
74
constant elasticity of variance process (absorbing boundary at f=0)
Real massAtZero(Time t) const
Real invcdf(Real q, Time t) const override
std::vector< Real > locations_
Definition: fdm1dmesher.hpp:47
std::vector< Real > dplus_
Definition: fdm1dmesher.hpp:48
std::vector< Real > dminus_
Definition: fdm1dmesher.hpp:48
FdmCEV1dMesher(Size size, Real f0, Real alpha, Real beta, Time maturity, Real eps=0.0001, Real scaleFactor=1.5, const std::pair< Real, Real > &cPoint=(std::pair< Real, Real >(Null< Real >(), Null< Real >())))
template class providing a null value for a given type.
Definition: null.hpp:76
#define QL_EPSILON
Definition: qldefines.hpp:178
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