QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmsimpleprocess1dmesher.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2009, 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#include <ql/stochasticprocess.hpp>
21#include <ql/math/distributions/normaldistribution.hpp>
22#include <ql/methods/finitedifferences/meshers/fdmsimpleprocess1dmesher.hpp>
23
24namespace QuantLib {
25
27 Size size,
28 const ext::shared_ptr<StochasticProcess1D>& process,
29 Time maturity, Size tAvgSteps, Real eps, Real mandatoryPoint)
30 : Fdm1dMesher(size) {
31
32 std::fill(locations_.begin(), locations_.end(), 0.0);
33 for (Size l=1; l<=tAvgSteps; ++l) {
34 const Real t = (maturity*l)/tAvgSteps;
35
36 const Real mp = (mandatoryPoint != Null<Real>()) ? mandatoryPoint
37 : process->x0();
38
39 const Real qMin = std::min(std::min(mp, process->x0()),
40 process->evolve(0, process->x0(), t,
42 const Real qMax = std::max(std::max(mp, process->x0()),
43 process->evolve(0, process->x0(), t,
44 InverseCumulativeNormal()(1-eps)));
45
46 const Real dp = (1-2*eps)/(size-1);
47 Real p = eps;
48 locations_[0] += qMin;
49
50 for (Size i=1; i < size-1; ++i) {
51 p += dp;
52 locations_[i] += process->evolve(0, process->x0(), t,
54 }
55 locations_.back() += qMax;
56 }
57 std::transform(locations_.begin(), locations_.end(), locations_.begin(),
58 [=](Real x) -> Real { return x / tAvgSteps; });
59 for (Size i=0; i < size-1; ++i) {
60 dminus_[i+1] = dplus_[i] = locations_[i+1] - locations_[i];
61 }
62 dplus_.back() = dminus_.front() = Null<Real>();
63 }
64}
std::vector< Real > locations_
Definition: fdm1dmesher.hpp:47
std::vector< Real > dplus_
Definition: fdm1dmesher.hpp:48
std::vector< Real > dminus_
Definition: fdm1dmesher.hpp:48
FdmSimpleProcess1dMesher(Size size, const ext::shared_ptr< StochasticProcess1D > &process, Time maturity, Size tAvgSteps=10, Real epsilon=0.0001, Real mandatoryPoint=Null< Real >())
Inverse cumulative normal distribution function.
template class providing a null value for a given type.
Definition: null.hpp:76
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