Coverage Report

Created: 2025-08-11 06:28

/src/quantlib/ql/stochasticprocess.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) 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
22
#include <ql/stochasticprocess.hpp>
23
#include <utility>
24
25
namespace QuantLib {
26
27
    // base class
28
29
    StochasticProcess::StochasticProcess(ext::shared_ptr<discretization> disc)
30
0
    : discretization_(std::move(disc)) {}
31
32
0
    Size StochasticProcess::factors() const {
33
0
        return size();
34
0
    }
35
36
    Array StochasticProcess::expectation(Time t0,
37
                                         const Array& x0,
38
0
                                         Time dt) const {
39
0
        return apply(x0, discretization_->drift(*this, t0, x0, dt));
40
0
    }
41
42
    Matrix StochasticProcess::stdDeviation(Time t0,
43
                                           const Array& x0,
44
0
                                           Time dt) const {
45
0
        return discretization_->diffusion(*this, t0, x0, dt);
46
0
    }
47
48
    Matrix StochasticProcess::covariance(Time t0,
49
                                         const Array& x0,
50
0
                                         Time dt) const {
51
0
        return discretization_->covariance(*this, t0, x0, dt);
52
0
    }
53
54
    Array StochasticProcess::evolve(Time t0, const Array& x0,
55
0
                                    Time dt, const Array& dw) const {
56
0
        return apply(expectation(t0,x0,dt), stdDeviation(t0,x0,dt)*dw);
57
0
    }
58
59
    Array StochasticProcess::apply(const Array& x0,
60
0
                                   const Array& dx) const {
61
0
        return x0 + dx;
62
0
    }
63
64
0
    Time StochasticProcess::time(const Date& ) const {
65
0
        QL_FAIL("date/time conversion not supported");
66
0
    }
67
68
783k
    void StochasticProcess::update() {
69
783k
        notifyObservers();
70
783k
    }
71
72
73
    // 1-D specialization
74
75
    StochasticProcess1D::StochasticProcess1D(ext::shared_ptr<discretization> disc)
76
979
    : discretization_(std::move(disc)) {}
77
78
0
    Real StochasticProcess1D::expectation(Time t0, Real x0, Time dt) const {
79
0
        return apply(x0, discretization_->drift(*this, t0, x0, dt));
80
0
    }
81
82
0
    Real StochasticProcess1D::stdDeviation(Time t0, Real x0, Time dt) const {
83
0
        return discretization_->diffusion(*this, t0, x0, dt);
84
0
    }
85
86
0
    Real StochasticProcess1D::variance(Time t0, Real x0, Time dt) const {
87
0
        return discretization_->variance(*this, t0, x0, dt);
88
0
    }
89
90
    Real StochasticProcess1D::evolve(Time t0, Real x0,
91
0
                                     Time dt, Real dw) const {
92
0
        return apply(expectation(t0,x0,dt), stdDeviation(t0,x0,dt)*dw);
93
0
    }
94
95
0
    Real StochasticProcess1D::apply(Real x0, Real dx) const {
96
0
        return x0 + dx;
97
0
    }
98
99
}