Home > wafo > wsim > sarmasim.m

sarmasim

PURPOSE

Simulates a switching ARMA-process.

SYNOPSIS

[x,z,e]=sarmasim(C,A,m,s2,P,T,Tinit,x0,z0)

DESCRIPTION

``` SARMASIM   Simulates a switching ARMA-process.
The regime process z has the state space {1,2,...,r}.
The process is governed by the system equation
A(q,z(t)) * x(t) = C(q,z(t)) * (m(z(t)) + s(z(t)) * e(t) )
with  s = sqrt(s2).

[x,z,e] = sarmasim(C,A,m,s2,P,T,Tinit,x0,z0);

x     = Simulated switching ARMA-process.
z     = Simulated regime process.
e     = Innovation process.

C     = Coefficients in C-polynomials.        [rxnc+1]
A     = Coefficients in A-polynomials.        [rxna+1]
m     = Means of subprocesses.                [rx1]
s2    = Innovation variances.                 [rx1]
P     = Transition matrix for regime process. [rxr]
T     = Length of simulation.
Tinit = Length of simulation. (Optional, default: Tinit=10*na)
x0    = Initial state of process x. If not given,
it will start from zeroes.            [1xna]
z0    = Initial state of regime process. If not given, it will start
from the stationary distribution of the Markov chain.

Example: Switching ARMA(4,2)-process (Example 5 in thesis)
p1=0.005; p2=0.003; P = [1-p1 p1; p2 1-p2];
C = [1.00 1.63 0.65; 1.00 0.05 -0.88];
A = [1.00 -0.55 0.07 -0.26 -0.02; 1.00 -2.06 1.64 -0.98 0.41];
m = [46.6; 7.4]*1e-3;
s2 = [0.5; 2.2]*1e-3;
[x,z]=sarmasim(C,A,m,s2,P,2000);
plothmm(x,z)```

CROSS-REFERENCE INFORMATION

This function calls:
 mcsim Simulates a Markov chain. error Display message and abort function.
This function is called by:
 rfcdemo1 Demo for switching AR(1)-processes.

SOURCE CODE

```001 function [x,z,e]=sarmasim(C,A,m,s2,P,T,Tinit,x0,z0)
002 %SARMASIM   Simulates a switching ARMA-process.
003 %   The regime process z has the state space {1,2,...,r}.
004 %   The process is governed by the system equation
005 %     A(q,z(t)) * x(t) = C(q,z(t)) * (m(z(t)) + s(z(t)) * e(t) )
006 %   with  s = sqrt(s2).
007 %
008 % [x,z,e] = sarmasim(C,A,m,s2,P,T,Tinit,x0,z0);
009 %
010 % x     = Simulated switching ARMA-process.
011 % z     = Simulated regime process.
012 % e     = Innovation process.
013 %
014 % C     = Coefficients in C-polynomials.        [rxnc+1]
015 % A     = Coefficients in A-polynomials.        [rxna+1]
016 % m     = Means of subprocesses.                [rx1]
017 % s2    = Innovation variances.                 [rx1]
018 % P     = Transition matrix for regime process. [rxr]
019 % T     = Length of simulation.
020 % Tinit = Length of simulation. (Optional, default: Tinit=10*na)
021 % x0    = Initial state of process x. If not given,
022 %         it will start from zeroes.            [1xna]
023 % z0    = Initial state of regime process. If not given, it will start
024 %         from the stationary distribution of the Markov chain.
025 %
026 % Example: Switching ARMA(4,2)-process (Example 5 in thesis)
027 %   p1=0.005; p2=0.003; P = [1-p1 p1; p2 1-p2];
028 %   C = [1.00 1.63 0.65; 1.00 0.05 -0.88];
029 %   A = [1.00 -0.55 0.07 -0.26 -0.02; 1.00 -2.06 1.64 -0.98 0.41];
030 %   m = [46.6; 7.4]*1e-3;
031 %   s2 = [0.5; 2.2]*1e-3;
032 %   [x,z]=sarmasim(C,A,m,s2,P,2000);
033 %   plothmm(x,z)
034
035 % Copyright (c) 1997 by Pär Johannesson
036 % Toolbox: Rainflow Cycles for Switching Processes V.1.0, 2-Oct-1997
037
038 if nargin < 6
039   error('More input arguments needed. See help.')
040 end
041 if nargin<7, Tinit = []; end
042 if nargin<8, x0 = []; end
043 if nargin<9, z0 = []; end
044
045 r=size(P,1);
046 ma=size(A,2)-1;
047 mc=size(C,2)-1;
048 m_max=max([ma mc]);
049
050 if ma < 1
051   A =[ones(r,1) zeros(r,1)];
052   ma = 1;
053 end
054 if mc < 0
055   C = ones(r,1);
056   mc = 0;
057 end
058
059 if isempty(Tinit)
060   Tinit=10*ma;
061 end
062 T1 = Tinit+T;
063 z=mcsim(P,T1,z0);
064
065 mx = (sum(C')'./sum(A')'.*m)';
066 x=zeros(T1,1);
067 if isempty(x0)
068   x(1:ma) = ones(ma,1).*mx(z(1:ma))';
069 else
070   x(1:ma) = x0;
071 end
072
073 e=randn(T1,1);
074 s=sqrt(s2);
075
076 for t=m_max+1:T1
077   x(t)=-A(z(t),2:ma+1)*x(t-1:-1:t-ma) + C(z(t),:)*(m(z(t))+s(z(t))*e(t:-1:t-mc));
078 end
079
080 x = x(Tinit+1:T1);
081 z = z(Tinit+1:T1);
082
083
084```

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group

Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003