/src/quantlib/ql/methods/finitedifferences/meshers/fdmcev1dmesher.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
20 | | /*! \file fdmcev1dmesher.cpp */ |
21 | | |
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 | | |
30 | | namespace QuantLib { |
31 | | |
32 | | FdmCEV1dMesher::FdmCEV1dMesher( |
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 | 0 | : Fdm1dMesher(size) { |
39 | |
|
40 | 0 | const CEVRNDCalculator rndCalculator(f0, alpha, beta); |
41 | |
|
42 | 0 | const Real upperBound = |
43 | 0 | scaleFactor*rndCalculator.invcdf(1-eps, maturity); |
44 | |
|
45 | 0 | const Real massAtZero = rndCalculator.massAtZero(maturity); |
46 | |
|
47 | 0 | const Real lowerBound = (massAtZero > eps) |
48 | 0 | ? ((beta < 0)? QL_EPSILON : 0.0) |
49 | 0 | : Real(rndCalculator.invcdf(eps, maturity)/scaleFactor); |
50 | | |
51 | |
|
52 | 0 | ext::shared_ptr<Fdm1dMesher> helper; |
53 | 0 | if ( cPoint.first != Null<Real>() |
54 | 0 | && cPoint.first >= lowerBound && cPoint.first <= upperBound) { |
55 | |
|
56 | 0 | helper = ext::make_shared<Concentrating1dMesher>( |
57 | 0 | lowerBound, upperBound,size, cPoint); |
58 | 0 | } |
59 | 0 | else { |
60 | 0 | helper = ext::make_shared<Uniform1dMesher>( |
61 | 0 | lowerBound, upperBound, size ); |
62 | 0 | } |
63 | |
|
64 | 0 | std::copy(helper->locations().begin(), |
65 | 0 | helper->locations().end(), |
66 | 0 | locations_.begin()); |
67 | |
|
68 | 0 | for (Size i=0; i < locations_.size(); ++i) { |
69 | 0 | dplus_[i] = helper->dplus(i); |
70 | 0 | dminus_[i] = helper->dminus(i); |
71 | 0 | } |
72 | 0 | } |
73 | | } |
74 | | |