VRATIO89 beta (Lo and MacKinlay 1989) - Comments welcome

Use this forum to post complete RATS "procedures". Please be sure to include instructions on using the procedure and detailed references where applicable.
TedKury
Posts: 7
Joined: Tue Nov 14, 2006 8:38 am

VRATIO89 beta (Lo and MacKinlay 1989) - Comments welcome

Unread post by TedKury »

My debugging helpers are all in lower case. I would propose to delete them in the final version. Any comments, questions, or suggestions for improvement are welcome.

******************************************************************************
*
* @VRATIO89(OPTIONS) SERIES START END
*
* Parameters:
* SERIES The series to be tested
* START END The range of entries to use (optional -- defaults
* to full range of series).
*
* Options:
* LAGS=number Specifies the number of lags incorporated.
* The default is LAGS=2.
*
*
* This proc runs the variance ratio tests outlined in Lo and MacKinlay (1989),
* and returns the test statistics under both the assumptions of homoscedasticity
* and heteroscedasticity.
*
* Ted Kury
* The Energy Authority
* Jacksonville, FL
* tkury@teainc.org
*
* Reference:
* Lo A, and AC MacKinlay (1989), "The Size and Power of the Variance Ratio
* test in Finite Samples: A Monte Carlo Investigation"
* Journal of Econometrics 40:203-238.
*
* Programming References:
* VRATIO.SRC for RATS by Christopher Zorn, University of South Carolina
* vrt.m for MATLAB by Ben Hassen Anis, University of Tunis
* Dias JC, L Lopes, V Martins, and JM Benzinho, "Efficiency tests in the Iberian
* stock markets"
* Working paper.
*
******************************************************************************
PROCEDURE VRATIO89 SERIES START END
TYPE SERIES SERIES
TYPE INTEGER START END
*
OPTION INTEGER LAGS 2
*
LOCAL INTEGER STARTL ENDL STARTP ENDP NOBS T
LOCAL SERIES XDIFF XDFLAG XDFLAG2
LOCAL REAL VAR VR ZK ZHK MU M
LOCAL INTEGER T I
LOCAL VECTOR[REAL] AUX1 AUX2 AUX3 XDIFF2
*
DIM AUX1(LAGS-1)
DIM AUX2(LAGS-1)
DIM AUX3(LAGS-1)
*
IF %DEFINED(SERIES)==0
{
DISPLAY 'Syntax: @VRATIO89 series start end'
RETURN
}

INQUIRE(SERIES=SERIES) STARTP>>START ENDP>>END
*
STATISTICS(NOPRINT) SERIES STARTP ENDP
IF ( %NOBS < (ENDP-STARTP+1) )
{
DISPLAY 'VRATIO89 cannot be applied because the series contains missing values.'
RETURN
}
*
SET XDIFF STARTP+1 ENDP = SERIES - SERIES{1}
SET XDFLAG STARTP+LAGS ENDP = SERIES - SERIES{LAGS}
STATISTICS(NOPRINT) XDIFF
COMPUTE MU = %MEAN
COMPUTE VAR = %VARIANCE
COMPUTE T = %NOBS
*
DIM XDIFF2(T)
*
COMPUTE M = LAGS * (T - LAGS + 1) * (1 - LAGS/T)
*
* Compute Homoscedastic Test Statistic
SET XDFLAG2 = (XDFLAG - LAGS * MU) ** 2
print / xdiff xdflag xdflag2
COMPUTE VR = (1/M) * %SUM(XDFLAG2)/VAR
COMPUTE ZK = SQRT(T) * (VR - 1) / SQRT((2*(2*LAGS-1)*(LAGS-1))/(3*LAGS))
*
* Compute Heteroscedastic Test Statistic
EWISE XDIFF2(I) = (XDIFF(I + 1) - MU) ** 2
display 'mu' mu
display 't' t
display 'xdiff2' xdiff2
EWISE AUX1(I) = (2.0/LAGS * (LAGS-I)) ** 2
display 'aux1' aux1
DO I=1,LAGS-1
COMPUTE AUX3(I)=%DOT(%XSUBVEC(XDIFF2,I+1,T),%XSUBVEC(XDIFF2,1,T-I))
END DO I
display 'aux3' aux3
EWISE AUX2(I)=AUX3(I)/((T-1)*VAR)**2
display 'aux2' aux2
COMPUTE ZHK = (VR - 1) / SQRT(%DOT(AUX1,AUX2))
*
DISPLAY ' '
DISPLAY 'Variance-Ratio test with ' LAGS ' lags:'
DISPLAY 'Ratio = ' VR
DISPLAY 'Homoscedastic = ' ZK
DISPLAY 'Heteroscedastic = ' ZHK
DISPLAY ' '
DISPLAY '(N =' %NOBS ')'
DISPLAY ' '
*
END
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Unread post by TomDoan »

You have a couple of integer divide problems:

COMPUTE M = LAGS * (T - LAGS + 1) * (1 - LAGS/T)

and

COMPUTE ZK = SQRT(T) * (VR - 1) / SQRT((2*(2*LAGS-1)*(LAGS-1))/(3*LAGS))

In the first, LAGS/T will be zero. Use FLOAT(LAGS)/T instead. In the second, change any of the constants (2, 1, 3) to 2.0, 1.0 or 3.0 to force the calculation to be done as real-valued, not integer.
Post Reply