1 ## Copyright (C) 1995-2012 Kurt Hornik
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} arch_rnd (@var{a}, @var{b}, @var{t})
21 ## Simulate an ARCH sequence of length @var{t} with AR
22 ## coefficients @var{b} and CH coefficients @var{a}. I.e., the result
23 ## @math{y(t)} follows the model
24 ## @c Set example in small font to prevent overfull line
27 ## y(t) = b(1) + b(2) * y(t-1) + @dots{} + b(lb) * y(t-lb+1) + e(t),
31 ## where @math{e(t)}, given @var{y} up to time @math{t-1}, is
32 ## @math{N(0, h(t))}, with
33 ## @c Set example in small font to prevent overfull line
36 ## h(t) = a(1) + a(2) * e(t-1)^2 + @dots{} + a(la) * e(t-la+1)^2
40 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
41 ## Description: Simulate an ARCH process
43 function y = arch_rnd (a, b, t)
49 if (! ((min (size (a)) == 1) && (min (size (b)) == 1)))
50 error ("arch_rnd: A and B must both be scalars or vectors");
52 if (! (isscalar (t) && (t > 0) && (rem (t, 1) == 0)))
53 error ("arch_rnd: T must be a positive integer");
57 error ("arch_rnd: A(1) must be positive");
59 ## perhaps add a test for the roots of a(z) here ...
62 a = reshape (a, 1, la);
69 b = reshape (b, 1, lb);
81 e(1) = sqrt (h(1)) * randn;
86 h(t) = a(1) + a(2:ta) * e(t-ta+1:t-1).^2;
87 e(t) = sqrt (h(t)) * randn;
89 y(t) = b(1) + b(2:tb) * y(t-tb+1:t-1) + e(t);
94 h(t) = a(1) + a(2:la) * e(t-la+1:t-1).^2;
95 e(t) = sqrt (h(t)) * randn;
96 y(t) = b(1) + b(2:lb) * y(t-tb+1:t-1) + e(t);