function forec = faar(y,x,h,m,p);
x=x(2:end,:)-x(1:end-1,:);
dy=y(2:end,:)-y(1:end-1,:);
y=y(2:end);
for j=1:size(x,2); x(:,j)=(x(:,j)-mean(x(:,j)))/std(x(:,j)); end;
[coeff, score] = princomp(x);
bigt=length(y);

b=h+p;
w=y(b:bigt)-y(b-h:bigt-h);

q=ones(bigt-b+1,1);
for j=1:p; q=[q dy(b+1-h-j:bigt+1-h-j)]; end;
q=[q score(b-h:bigt-h,1:m)]; 

bhat=inv(q'*q)*q'*w;

ql=1;
for j=1:p; ql=[ql dy(bigt+1-j)]; end;
ql=[ql score(bigt,1:m)]; 

forec=ql*bhat;