QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
fdmsimpleprocess1dmesher.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) 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 <algorithm>
24
25namespace QuantLib {
26
28 Size size,
29 const ext::shared_ptr<StochasticProcess1D>& process,
30 Time maturity, Size tAvgSteps, Real eps, Real mandatoryPoint)
31 : Fdm1dMesher(size) {
32
33 std::fill(locations_.begin(), locations_.end(), 0.0);
34 for (Size l=1; l<=tAvgSteps; ++l) {
35 const Real t = (maturity*l)/tAvgSteps;
36
37 const Real mp = (mandatoryPoint != Null<Real>()) ? mandatoryPoint
38 : process->x0();
39
40 const Real qMin = std::min({
41 mp,
42 process->x0(),
43 process->evolve(0, process->x0(), t,
45 });
46 const Real qMax = std::max({
47 mp,
48 process->x0(),
49 process->evolve(0, process->x0(), t,
51 });
52
53 const Real dp = (1-2*eps)/(size-1);
54 Real p = eps;
55 locations_[0] += qMin;
56
57 for (Size i=1; i < size-1; ++i) {
58 p += dp;
59 locations_[i] += process->evolve(0, process->x0(), t,
61 }
62 locations_.back() += qMax;
63 }
64 std::transform(locations_.begin(), locations_.end(), locations_.begin(),
65 [=](Real x) -> Real { return x / tAvgSteps; });
66 for (Size i=0; i < size-1; ++i) {
67 dminus_[i+1] = dplus_[i] = locations_[i+1] - locations_[i];
68 }
69 dplus_.back() = dminus_.front() = Null<Real>();
70 }
71}
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:59
const DefaultType & t
One-dimensional grid mesher.
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:37
normal, cumulative and inverse cumulative distributions
stochastic processes