3191
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
3426
|
2 ## |
3191
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
3426
|
7 ## |
3191
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
11 ## General Public License for more details. |
|
12 ## |
3191
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this file. If not, write to the Free Software Foundation, |
|
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
16 |
3449
|
17 ## -*- texinfo -*- |
|
18 ## @deftypefn {Function File} {@var{y} =} arch_rnd (@var{a}, @var{b}, @var{t}) |
|
19 ## Simulate an ARCH sequence, @var{y}, of length @var{t} with AR |
|
20 ## coefficients @var{b} and CH coefficients @var{a}. I.e., the result |
|
21 ## follows the model |
3191
|
22 ## |
3449
|
23 ## @example |
|
24 ## y(t) = b(1) + b(2) * y(t-1) + ... + b(lb) * y(t-lb+1) + e(t), |
|
25 ## @end example |
|
26 ## |
|
27 ## @noindent |
|
28 ## where e(t), given @var{y} up to time @var{t}-1, is @var{N}(0, |
|
29 ## @var{h}(@var{t})), with |
|
30 ## |
|
31 ## @example |
|
32 ## h(t) = a(1) + a(2) * e(t-1)^2 + ... + a(la) * e(t-la+1)^2 |
|
33 ## @end example |
|
34 ## @end deftypefn |
3191
|
35 |
3457
|
36 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
37 ## Description: Simulate an ARCH process |
3191
|
38 |
|
39 function y = arch_rnd (a, b, T) |
3426
|
40 |
3191
|
41 if (nargin != 3) |
|
42 usage ("arch_rnd (a, b, T)"); |
|
43 endif |
3426
|
44 |
3457
|
45 if (! ((min (size (a)) == 1) && (min (size (b)) == 1))) |
|
46 error ("arch_rnd: a and b must both be scalars or vectors"); |
3191
|
47 endif |
3457
|
48 if (! (is_scalar (T) && (T > 0) && (rem (T, 1) == 0))) |
|
49 error ("arch_rnd: T must be a positive integer"); |
3191
|
50 endif |
3426
|
51 |
3457
|
52 if (! (a(1) > 0)) |
|
53 error ("arch_rnd: a(1) must be positive"); |
3191
|
54 endif |
|
55 ## perhaps add a test for the roots of a(z) here ... |
3426
|
56 |
3191
|
57 la = length (a); |
|
58 a = reshape (a, 1, la); |
|
59 if (la == 1) |
|
60 a = [a, 0]; |
|
61 la = la + 1; |
|
62 endif |
|
63 lb = length (b); |
|
64 b = reshape (b, 1, lb); |
|
65 if (lb == 1) |
|
66 b = [b, 0]; |
|
67 lb = lb + 1; |
|
68 endif |
3238
|
69 M = max([la, lb]); |
3426
|
70 |
3191
|
71 e = zeros (T, 1); |
|
72 h = zeros (T, 1); |
|
73 y = zeros (T, 1); |
3426
|
74 |
3191
|
75 h(1) = a(1); |
|
76 e(1) = sqrt (h(1)) * randn; |
|
77 y(1) = b(1) + e(1); |
3426
|
78 |
3191
|
79 for t= 2 : M; |
3238
|
80 ta = min ([t, la]); |
3191
|
81 h(t) = a(1) + a(2:ta) * e(t-1:t-ta+1).^2; |
|
82 e(t) = sqrt (h(t)) * randn; |
3238
|
83 tb = min ([t, lb]); |
3191
|
84 y(t) = b(1) + b(2:tb) * y(t-1:t-tb+1) + e(t); |
|
85 endfor |
|
86 if (T > M) |
|
87 for t = M+1 : T; |
|
88 h(t) = a(1) + a(2:la) * e(t-1:t-la+1).^2; |
|
89 e(t) = sqrt (h(t)) * randn; |
|
90 y(t) = b(1) + b(2:lb) * y(t-1:t-tb+1) + e(t); |
|
91 endfor |
|
92 endif |
3426
|
93 |
3191
|
94 y = y(1:T); |
3426
|
95 |
3191
|
96 endfunction |