/
GBM.m
74 lines (66 loc) · 2.19 KB
/
GBM.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%% Geometric Brownian motion
% Nick Trefethen, May 2017
%%
% (Chebfun example ode-random/GBM.m)
%%
% Random ODEs and stochastic DEs may include _additive noise_ and/or
% _multiplicative noise_. A linear, constant-coefficient equation of the
% latter kind is the equation of _geometric Brownian motion_,
% $$ dX_t = \mu X_t dt + \sigma X_t dW_t, ~~~ (1) $$
% where $W_t$ is the Wiener process (Brownian motion). With Chebfun's
% smooth random functions the analogous equation is
% $$ y' = \mu y + \sigma f y, ~~~ (2) $$
% where $f$ is a smooth random function. As usual, $f$ will have a
% wavelength parameter $\lambda>0$, and the SDE limit corresponds to
% $\lambda \to 0$. Actually in this limit one will get a Stratonovich
% (rather than Itô) SDE, written
% $$ dX_t = \mu X_t dt + \sigma X_t \circ dW_t. ~~~ (3) $$
%%
% $\mu$ is called the _drift_ coefficient and $\sigma$ is
% the _diffusion_ (or sometimes _volatility_) coefficient.
%%
% Geometric Brownian motion is easy to analyze by taking the
% logarithm. For example, dividing (2) by $y$ gives
% $$ (\log y)' = \mu + \sigma f , $$
% which now involves just additive noise.
%
%%
% For example, here are five trajectories with $\mu = 0$
% and $\sigma = 1$. On a log scale there would be no
% bias up or down, but on a linear scale we see some large
% amplitudes.
tic
dom = [0,20]; L = chebop(dom); L.lbc = 1; L.maxnorm = 100;
rng(0), lambda = 0.2;
f = randnfun(lambda,dom,'big',5);
mu = 0; sigma = 1;
for k = 1:5
L.op = @(t,y) diff(y) - mu*y - sigma*f(:,k)*y;
y = L\0; plot(y), hold on
end
grid on, hold off
xlabel('t'), ylabel('y')
title('zero drift')
%%
% If we increase $\mu$ to $0.2$, there is now an
% upward bias on any scale.
mu = 0.2;
for k = 1:5
L.op = @(t,y) diff(y) - mu*y - sigma*f(:,k)*y;
y = L\0; plot(y), hold on
end
grid on, hold off, ylim([0 70])
xlabel('t'), ylabel('y')
title('positive drift')
%%
% Setting $\mu = -0.2$, on the other hand, leads to decay.
mu = -0.2;
for k = 1:5
L.op = @(t,y) diff(y) - mu*y - sigma*f(:,k)*y;
y = L\0; plot(y), hold on
end
grid on, hold off
xlabel('t'), ylabel('y')
title('negative drift')
%%
total_time_in_seconds = toc