QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
stochasticprocess.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) 2003 Ferdinando Ametrano
5 Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb
6 Copyright (C) 2004, 2005 StatPro Italia srl
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
23#include <utility>
24
25namespace QuantLib {
26
27 // base class
28
29 StochasticProcess::StochasticProcess(ext::shared_ptr<discretization> disc)
30 : discretization_(std::move(disc)) {}
31
33 return size();
34 }
35
37 const Array& x0,
38 Time dt) const {
39 return apply(x0, discretization_->drift(*this, t0, x0, dt));
40 }
41
43 const Array& x0,
44 Time dt) const {
45 return discretization_->diffusion(*this, t0, x0, dt);
46 }
47
49 const Array& x0,
50 Time dt) const {
51 return discretization_->covariance(*this, t0, x0, dt);
52 }
53
55 Time dt, const Array& dw) const {
56 return apply(expectation(t0,x0,dt), stdDeviation(t0,x0,dt)*dw);
57 }
58
60 const Array& dx) const {
61 return x0 + dx;
62 }
63
65 QL_FAIL("date/time conversion not supported");
66 }
67
70 }
71
72
73 // 1-D specialization
74
75 StochasticProcess1D::StochasticProcess1D(ext::shared_ptr<discretization> disc)
76 : discretization_(std::move(disc)) {}
77
79 return apply(x0, discretization_->drift(*this, t0, x0, dt));
80 }
81
83 return discretization_->diffusion(*this, t0, x0, dt);
84 }
85
87 return discretization_->variance(*this, t0, x0, dt);
88 }
89
91 Time dt, Real dw) const {
92 return apply(expectation(t0,x0,dt), stdDeviation(t0,x0,dt)*dw);
93 }
94
96 return x0 + dx;
97 }
98
99}
1-D array used in linear algebra.
Definition: array.hpp:52
Concrete date class.
Definition: date.hpp:125
Matrix used in linear algebra.
Definition: matrix.hpp:41
virtual Real apply(Real x0, Real dx) const
ext::shared_ptr< discretization > discretization_
virtual Real variance(Time t0, Real x0, Time dt) const
virtual Real evolve(Time t0, Real x0, Time dt, Real dw) const
virtual Real x0() const =0
returns the initial value of the state variable
virtual Real stdDeviation(Time t0, Real x0, Time dt) const
virtual Real expectation(Time t0, Real x0, Time dt) const
virtual Size size() const =0
returns the number of dimensions of the stochastic process
virtual Matrix stdDeviation(Time t0, const Array &x0, Time dt) const
virtual Array evolve(Time t0, const Array &x0, Time dt, const Array &dw) const
virtual Matrix covariance(Time t0, const Array &x0, Time dt) const
ext::shared_ptr< discretization > discretization_
virtual Array apply(const Array &x0, const Array &dx) const
virtual Array expectation(Time t0, const Array &x0, Time dt) const
virtual Size factors() const
returns the number of independent factors of the process
virtual Time time(const Date &) const
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
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
STL namespace.
stochastic processes