proc (1)=infMA(ar,ma,koeff_nr);

/*
infMA.src is written by Kristian Jönsson (April 10, 2003), Department of Economics, Lund University.
Contact info:  kristian.jonsson@nek.lu.se

This procedure calculates the infinite order moving average coefficients of a mixed ARMA(p,q) model.
To be able to calculate the coefficients it has to be assumed that the infinite order moving average coefficients
can be represented as a rational lag polynomial.

Inputs: 
  ar		: A px1 vector with AR coefficients
  ma 		: A qx1 vector with MA coefficients
  koeff_nr	: The number of coefficients of the infinite order MA that is to be calculated.

Output:
  psi		: A koeff_nrx1 matrix of coefficients for the infinite order MA representation.
		  Note that the first element, which is to be equal to 1, is omitted.

Note:
This code can be used freely as long as proper reference is given.
No performance guarantee is made.
Bugreports are welcome.
*/

local p,q;
local psi,psi_dim;
local sumprod;
local min_jp;
local i,j;

p=rows(ar);
q=rows(ma);

psi=zeros(koeff_nr,1);
psi_dim=zeros(koeff_nr+1,1);

psi_dim[1]=1;

for j (1,koeff_nr,1);
min_jp=minc(j|p);
if j<=q;
  sumprod=0;
  for i (1,min_jp,1);
   sumprod=sumprod+ar[i]*psi_dim[j+1-i];
  endfor;
  psi[j]=ma[j]+sumprod;
  psi_dim[j+1]=ma[j]+sumprod;
elseif j>q;
  sumprod=0;
  for i (1,min_jp,1);
   sumprod=sumprod+ar[i]*psi_dim[j+1-i];
  endfor;
  psi[j]=sumprod;
  psi_dim[j+1]=sumprod;
endif;
endfor;

psi=trimr(psi_dim,1,0);

retp(psi);
endp;
