5
$\begingroup$

I have a set of daily trading strategy returns and I am trying to prove whether the daily returns are autocorrelated at all. I am hoping to fail to reject the null hypothesis that they are not autocorrelated.

I have run and plotted autcorrelation and partial autocorrelation tests in python using the "statsmodels" module and receive the following results:

plt.plot(ts.acf(df2['weighted ret']))

enter image description here

plt.plot(ts.pacf(df2['weighted ret']),'b')

enter image description here

Firstly, am I correct in thinking that these plots show that there is no autorrelation as the value drops to insignificant levels at lag(1) and above?

Secondly, I have run a Ljun-Box test (which includes output for the Box-Pearce test):

tsd.acorr_ljungbox(df2['weighted ret'], lags=None, boxpierce=True)

and receive the following output:

(array([  0.9107039 ,   3.71074072,   3.75751082,   6.55811413,
     10.28498829,  10.37019583,  10.49468895,  10.68094649,
     10.69821754,  14.93764789,  17.78940399,  18.60913871,
     21.19375349,  22.00365345,  22.43366752,  24.68503463,
     25.24806264,  29.13640715,  29.15342754,  32.30758089,
     32.36711315,  32.37115194,  38.17234649,  38.38333067,
     39.60785921,  39.61326723,  43.97003771,  45.51169359,
     46.19633335,  46.98019209,  47.8911792 ,  49.02331688,
     60.11691436,  60.24143014,  61.54391802,  67.29109406,
     71.10596275,  71.2610596 ,  72.05509945,  73.21222911]),
 array([ 0.33992772,  0.15639501,  0.28886717,  0.16116535,  0.06755139,
     0.10990322,  0.16222948,  0.22044064,  0.29696304,  0.13435169,
     0.08659759,  0.09840785,  0.06918375,  0.07853933,  0.09692687,
     0.0755738 ,  0.08929334,  0.04673724,  0.06360978,  0.04012913,
     0.05372317,  0.0712848 ,  0.02440815,  0.03166241,  0.03198461,
     0.0425547 ,  0.0208257 ,  0.01956724,  0.02243155,  0.02499467,
     0.02695565,  0.02762183,  0.00268514,  0.00364675,  0.00366579,
     0.00119867,  0.00062994,  0.00086563,  0.00099989,  0.00104918]),
 array([  0.90941577,   3.704172  ,   3.75083185,   6.54351266,
     10.2580869 ,  10.34297305,  10.46693791,  10.6523173 ,
     10.66949877,  14.88494366,  17.71922083,  18.53354475,
     21.09988079,  21.90367118,  22.33023865,  24.56249938,
     25.12048377,  28.97216308,  28.98901495,  32.11045195,
     32.16933864,  32.17333173,  37.90614823,  38.11454609,
     39.32348657,  39.3288232 ,  43.62602444,  45.14587472,
     45.82050796,  46.59254045,  47.48935378,  48.6033431 ,
     59.51387792,  59.63628028,  60.91604678,  66.56025596,
     70.30497855,  70.45715043,  71.23584109,  72.37005729]),
 array([ 0.34026948,  0.15690951,  0.28965724,  0.1620693 ,  0.06824415,
     0.11093204,  0.1636201 ,  0.22218803,  0.29904496,  0.13631325,
     0.08832853,  0.1004245 ,  0.07097645,  0.08061545,  0.09943268,
     0.07791856,  0.09204512,  0.04872033,  0.06615811,  0.04213552,
     0.05627852,  0.07448855,  0.02606853,  0.03374738,  0.03417996,
     0.04533845,  0.02259248,  0.02132315,  0.02444703,  0.02725835,
     0.02943736,  0.03024447,  0.00313222,  0.0042381 ,  0.00427748,
     0.00144819,  0.00077836,  0.00106526,  0.00123137,  0.00129663]))

I am new to statistics and would be very greatful if someone could guide me as to how to interpret these results. I have tried looking online, but find the explanations confusing.

Many thanks!

$\endgroup$

2 Answers 2

4
$\begingroup$

Yes, as user333700's answered, the 2nd list in the returned array is p-values from the ljungbox test and the 4th list is the p-values from the boxpierce test. Since no p-value is below .05, both tests agree that you can not reject the null of no auto-correlation between the series and each of it's first 40 lags with > 95% confidence level. Now, the question is how did you end up choosing 40 as your max. lag? If your data is daily, as you said, 40 seems too low to my intuition. If there is a quarterly seasonality pattern, for example, in your data, you will miss that with a max. lag of 40.

Also, although you have understood the results correctly, it is not safe to base your judgement on pacf graphs with no confidence bands around them. A pacf may look small in such a graph but may actually be significant. It's wiser to get numeric test statistics, as you did, or use a graph with confidence bands (for example, by using plot_pacf function from statsmodels.graphics.tsaplots).

$\endgroup$
1
  • 2
    $\begingroup$ There are quite a few values below 0.05 in the second array, 0.04673724 being the first one. $\endgroup$
    – Chris Snow
    Commented Feb 14, 2019 at 9:24
1
$\begingroup$

The returns are ljung-box test statistic, it's pvalue, and box-pierce statistic and it's pvalue, for all lags up to 40.

Obviously, statsmodels leaves it currently up to the user to choose an appropriate lag length.

Hyndman http://robjhyndman.com/hyndsight/ljung-box-test/ recommends min(10, T/5) for non-seasonal time series. His simulations show that ljung-box overrejects if the lag length is too large.

Stata uses min(n/2 − 2, 40) http://www.stata.com/manuals13/tswntestq.pdf

It looks like in R the default number of lags depends on which package is used.

This http://www.r-bloggers.com/story-of-the-ljung-box-blues-progress-not-perfection/ shows a similar pattern of p-values decreasing with lag length.

(I never looked at the question of how many lags to use for ljung-box and it's small sample properties before.)

$\endgroup$
6
  • $\begingroup$ Hi, thanks for the reply. So looking at the results for the LjungBox test, I see that the test statistic gets larger and larger across higher numbers of lags, with the P-value dropping smaller and smaller. Some of the p-values at high lags are under 0.001!! Does this mean that those lags show autocorrelation? Or does a low p-value mean autocorrelation is disproved? $\endgroup$
    – s666
    Commented Mar 8, 2016 at 9:20
  • $\begingroup$ Also, can I interpret the two plots of of autocorrelation and partial autocorrelation as showing zero autocorrelation as the values drop close to zero at lag(1) and above? $\endgroup$
    – s666
    Commented Mar 8, 2016 at 9:23
  • $\begingroup$ I am trying to prove that the daily returns of a trading strategy are completely independent of each other. $\endgroup$
    – s666
    Commented Mar 8, 2016 at 9:34
  • $\begingroup$ ljung-box is a test on the cumulative sum of autocorrelations, so it's different from just looking at individual autocorrelation in the plots. E.g. there could be many individually insignificant autocorrelation coefficients but they are all positive so they add up. $\endgroup$
    – Josef
    Commented Mar 8, 2016 at 13:58
  • 2
    $\begingroup$ We reject the null of no autocorrelation if the p-value is small. You didn't specify how many observations you have. I would interpret your results as that in your data there is no autocorrelation for the first 10 or a bit more lags. For larger lags, the tests reject the no autocorrelation hypothesis, but my guess is that it's more likely that something else is going on, biased hypothesis test, sample size too small, violation of an assumption or similar. $\endgroup$
    – Josef
    Commented Mar 8, 2016 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.