BookmarkSubscribeRSS Feed
Cnord
Calcite | Level 5

I have managed to get an output of this coding which indicates which model with parameter p,d and h is the best fit model. However, I am stucked on how to forecast the future price with lead=6 with the p=8, d=8 and h=1. Can anyone help me out ? I am using SAS 9.4 and this model is functional coefficient autoregressive model.

The coding for fiding the best fit model is as follow:

 

proc import out=pepper
datafile='C:\Downloads\WPJan97toDec15.xls'
dbms=excel replace;
sheet='Sheet1';
getnames=yes;
run;

 

proc print data=pepper;
run;

 

Proc iml;
use pepper;
read all into y;
pdh=j(1,4,999);
print pdh;
APEh=j(4,1,0);
print APEh;
u0=sum(y)/nrow(y);
n=nrow(y);
sum=sum(y);
print sum;
print n;
print u0;
do p=1 to 8;
             do d=1 to p;
                       x0=j(nrow(y),p,0);
                       do i= p+1 to nrow(y);
                                  x0[i,]=y[i-1:i-p]`;
                       end;
                       do h=0.1 to 1 by 0.1;
                                   do j=1 to 4;
                                               t=nrow(y)-(7*j);
                                               n=t-p;
                                               x=j(t,p,0);
                                               u=j(t,1,0);
                                               do i= p+1 to t;
                                                            x[i,]=y[i-1:i-p]`;
                                                            u[i]=y[i-d];
                                               end;
                                               x1=x[p+1:t,];
                                               u1=u[p+1:t,];
                                               w=j(n,n,0);
                                               w1=j(n,1,0);
                                               x2=j(n,p,1);
                                               do i=1 to n;
                                                           ind=(u1[i]-u0)/h;
                                                           if (ind<=1) then do;
                                                           w[i,i]=(0.75/h)*(1-((u1[i]-u0)*(u1[i]-u0))/(h*h));

                                                           w1[i,]=w[i,i];
                                                           x2[i,]=x1[i,]*(u1[i]-u0);
                                                           end;
                                                           else do;
                                                           w[i,i]=0;
                                                           w1[i,]=w[i,i];
                                                           x2[i,]=x1[i,]*(u1[i]-u0);
                                                           end;
                                               end;
                                               Xcurl=j(n,2*p,0);
                                               xcurl=xl||x2;
                                               y1=y[p+1:t,];
                                               beta=inv(xcurl`*w*xcurl)*(xcurl`*w*y1);
                                               beta1=beta[1: p,];
                                               yhat=xcurl*beta;
                                               error=y1-yhat;
                                               apeerror=j(7,1,0);
                                               apeerror=error[n-7*j+1:n-7*j+7,];
                                               APEh[j]=(1/7)*apeerror`*apeerror;
                                   end;
                                   APE=sum(APEh)/4;
                                   pdh=pdh//(p||d||h||APE);
                       end;
             end;
end;
pdh=pdh[2:nrow(pdh),];
minAPE=min(pdh[,4]);
do i=1 to nrow(pdh);
             if (pdh[i,4]=minAPE) then rw=i;
end;
result=pdh[rw,];
print beta1;

2 REPLIES 2
Cnord
Calcite | Level 5

I also facing a trouble that my result for beta1 and minAPE is extremely large. I don't know what causes it to be like this.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

Discussion stats
  • 2 replies
  • 1102 views
  • 0 likes
  • 2 in conversation