-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_bounded_random_walk.m
50 lines (40 loc) · 1.14 KB
/
sample_bounded_random_walk.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
function p = sample_bounded_random_walk(sd_e, beta, alpha1, alpha2, N, ...
tau, phi, xkm1)
% p = sample_bounded_random_walk(sd_e, beta, alpha1, alpha2, N, ...
% tau, phi)
% Simulate the Bounded Random Walk stochastic process proposed by
% J. Nicolau:
%
% Referemce:
% - J. Nicolau, Stationary Processes That Look Like Random
% Walks - The Bounded Random Walk Process in Discrete and
% Continuous Time, Econometric Theory, 18, 2002, 99-118.
%
if nargin < 8
% Set initial state
xkm1 = tau;
end
if nargin < 7
% Regularization parameter (0.5 by default)
phi = 0.5;
end
% Noise
e = randn(N, 1);
p = zeros(N, 1);
% Simulate
for i = 1:N
% Stochastic input
alpha = sd_e * e(i);
% Reversion bias
bias = brw_reversion_bias(xkm1, alpha1, alpha2, beta, tau);
% Regularization step (to avoid instability)
if abs(bias) < 2 * abs(xkm1 - tau)
x = xkm1 + bias + alpha;
else
x = tau + phi * (xkm1 - tau) + alpha;
end
% Bounded process output
p(i) = x;
xkm1 = x;
end
end