Ljung Box Test



I have an array that I want to use Ljung Box Test on. In Matlab, there is lbqtest function that works on array.

I want to know how I can do this in Julia.

nz = 1250
z =randn(nz,1)# randomly generated z distributed N[0,1]

sig=0.20*sqrt(1/252); #defining the trade day volatility
#of logarithmic change from annualized volatility 20-percent
cv = zeros(nz,1)
ep = zeros(nz,1)
G = 0.75
#weight on past conditional variance
A = 0.20
#weight on innovation
cv[1] = sig^2
ep[1] = 0
kappa = sig*sig*(1-(A+G)); #unconditional variance kappa/(1-(A+G))

for j = 2:nz #for loop creating conditional variance process
    cv[j] = kappa + G*cv[j-1] + A*(ep[j-1]^2)
    ep[j] = sqrt(cv[j])*z[j]  #process innovation

mcv = exp.(ep)
mcv[1] = P0
Pcv = cumprod(mcv)

xcv = log(Pcv[2:end])-log(Pcv[1:end-1])

using HypothesisTests

LjungBoxTest(xcv) # does not work


Not an expert at all (hadn’t heard of the Ljung-Box test before today, and I still don’t really know what it’s for), but it looks like HypothesisTests.LjungBoxTest requires you to pass in the lag as the second argument, whereas the matlab documentation for lbqtest shows that the single-argument lbqtest(res) uses “the default number of lags” while citing [3].

(BTW, P0 is undefined).

[3] Gourieroux, C. ARCH Models and Financial Applications. New York: Springer-Verlag, 1997.


Thanks. I missed that input. I thought I need to convert my array into a time series, but I have not worked with time series in Julia yet.