/* Continued Fraction Interpolation(only for the data by a smoothed function without error terms) */ /* Notice: This is the case which wdoes not work. */ /* Data from Holton(2003)"Value-at-Risk" */ new; cls; let data[10,2]= 1.1 2.14 1.4 2.60 2.5 1.15 2.7 1.19 3.2 1.88 3.6 1.55 4.1 2.65 4.3 3.80 4.5 4.46 4.9 6.35 ; x=data[.,1]; y=data[.,2]; points=9; /* # of points between x[k] and x[k+1] */ call contfrainterp(y,x,points); proc contfrainterp(y,x,points); local z,n,xx,yy,x1,i; /* sort them out in terms of x */ z=x~y; z=sortc(z,1); x=z[.,1]; y=z[.,2]; n=rows(x); /* graph */ xx=zeros((points+1)*(n-1)+1,1); yy=zeros((points+1)*(n-1)+1,1); i=1; do while i<=n-1; x1=seqa(x[i],(x[i+1]-x[i])/(points+1),points+1); xx[(i-1)*(points+1)+1:i*(points+1)]=x1; i=i+1; endo; xx[rows(xx)]=x[n]; i=1; do while i<=rows(yy); yy[i]=contfra(y,x,xx[i]); i=i+1; endo; library pgraph; graphset; pqgwin auto; begwind; window(1,1,0); scale(-0.05*(maxc(x)-minc(x))+minc(x)|maxc(x)+0.05*(maxc(x)-minc(x)),-0.25*(maxc(y)-minc(y))+minc(y)|maxc(y)+0.25*(maxc(y)-minc(y))); setwind(1); title("Continued Fraction Interpolation"); xy(xx,yy); setwind(1); _plctrl=-1; _pcolor=15; _psymsiz=1; xy(x,y); endwind; retp(xx~yy); endp; proc contfra(y,x,x0); local z,n,i,j,y0; /* sort them out in terms of x */ z=x~y; z=sortc(z,1); x=z[.,1]; y=z[.,2]; n=rows(x); /* main */ j=1; do while j<=n; i=j+1; do while i<=n; y[i]=(x[i]-x[j])/(y[i]-y[j]); i=i+1; endo; j=j+1; endo; y0=0; i=n; do while i>1; y0=(x0-x[i-1])/(y0+y[i]); i=i-1; endo; y0=y0+y[1]; retp(y0); endp;