PROGRAM PROG IMPLICIT REAL*8 (A-H,O-Z) C This program computes the hpfilter for the series Y C the result is written into the file prog.out C The deviations from the trend is the series D C the parameter MAXI should equal the maximum number of observations C you have in the data file random.out C Written by O. Mikhail C Oct 2002 C To change the number of observations, change the parameter MAXI C here we have 144 obs C S is lambda for quarterly data C if using annual data, change S to 100 C if using monthly data, change S to 14,400 PARAMETER(MAXI=144,S=1600) INTEGER*4 I,IOPT,N REAL*8 Y(MAXI),V(MAXI,3),D(MAXI) C give paramters here IOPT = 1 N = MAXI C The data Y to read are random numbers generated C using the program random.f and the data are in random.out OPEN(UNIT=9,FILE='random.out',STATUS='OLD') C Put the results in the file prog.out OPEN(UNIT=8,FILE='prog.out',STATUS='REPLACE') WRITE(8,*) 'Here goes the results' DO 12 I=1,MAXI READ(9,41) Y(I) V(I,1) = 0.D0 V(I,2) = 0.D0 V(I,3) = 0.D0 D(I) = 0.D0 12 CONTINUE 41 FORMAT(F13.9) C if you uncomment, you will write the series C into the file unit 8 C DO 14 I=1,MAXI C WRITE(8,41) Y(I) C14 CONTINUE C CALLING HPFILTER ROUTINE CALL HPFILT(Y,D,V,MAXI,S,IOPT) C WRITING RESULTS DO 14 I=1,MAXI WRITE(8,42) Y(I),D(I) 14 CONTINUE 42 FORMAT(F16.9,4X,F16.9) STOP END C ---------------------------------------------------------------------- C SR: hpfilt C Kalman smoothing routine for HP filter written by E Prescott. C y=data series, d=deviations from trend, t=trend, n=no. obs, C s=smoothing parameter (eg, 1600 for std HP). C Array v is scratch area and must have dimension at least 3n. C If IOPT=1 and n and s are the same as for the previous call, C the numbers in v are not recomputed. This reduces execution C time by about 30 percent. Note that if this option is exercised, C v cannot be used for other purposes between calls. C This version does NOT release the trend in order to save memory. C ---------------------------------------------------------------------- SUBROUTINE HPFILT(Y,D,V,N,S,IOPT) INTEGER*4 IOPT,NN,I,I1,IB,N REAL*8 Y(N),T(N),V(N,3),D(N),SS REAL*8 M1,M2,V11,V12,V22,X,Z,B11,B12,B22,DET,E1,E2,S DATA SS,NN/0.D0,0/ C C compute sequences of covariance matrix for f[x(t),x(t-1) | y(