{"word_count": 720, "character_count": 4960}
This summer, we have been told that some financial series broke some records (here, in French)For instance, the French CAC40 had negative return for 11 consecutive days (which has never been seen, so far).&#62; library(tseries)&#62; x&#60;-get.hist.quote("^FCHI")&#62; Y=x$Close&#62; Z=diff(log(Y))&#62; RUN=rle(as.character(Z&#62;=0))$lengths&#62; n=length(RUN)&#62; LOSS=RUN[seq(2,n,by=2)]&#62; GAIN=RUN[seq(1,n,by=2)]&#62; TG=sort(table(GIN))&#62; TG[as.character(1:13)]GAIN   1    2    3    4    5    6    7    8    9 &#60;NA&#62; &#60;NA&#62; &#60;NA&#62;   13 645  336  170   72   63   21    7    3    4   NA   NA   NA    1 &#62; TL=sort(table(LOSS))&#62; TL[as.character(1:15)]LOSS   1    2    3    4    5    6    7    8    9 &#60;NA&#62;   11 &#60;NA&#62; &#60;NA&#62;  664  337  186   68   42   14    5    3    1   NA    1   NA   NA  &#62; TR=sort(table(RUN))&#62; TR[as.character(1:15)]RUN   1    2    3    4    5    6    7    8    9 &#60;NA&#62;   11 &#60;NA&#62;   13 1309  673  356  140  105   35   12    6    5   NA    1   NA    1Indeed 11 consecutive days of negative returns is a record. But one should keep in mind the fact that the real records for runs is 13 consecutive days with positivereturns...But what does that mean ? Can we still assume time independence of log-returns (since today, a lot of financial models are still based on that assumption) ?Actually. if financial series were time-independence, such a probability, indeed, should be rather small. At least on 11 or 10 runs. Something like(assuming that each day, the probability to observe a negative return is 50%). But maybe not over 25 years (6250 trading days): the probability to observe a sub-sequence of 10 consecutive negative value (with daily probability of one half) over 6250 observations will be much larger. My guess is that is would bewhere at the numerator we have the number of favourable cases over the total number of cases. At the numerator, the first number the number of cases where the first 10 (at least) are negative, then for the second one, we count the number of cases where the first is positive, then the next 10 (at least) are negative (and then the second is positive and then the next 10 are negative, the third is positive etc). For those interested by more details (and a more general formula on runs), an answer can be found here.But note that the probability is quite large... So it is not that unlikely to observe such a sequence over 25 years.A classical idea when looking at time series is to look at the autocorrelation function of the returns,which might suggest that there is no correlation with past returns. But it should be possible to do more advanced tests.On the CAC40 series, we can run an independence run test on the latest 100 consecutive days, and look at the p-value,&#62; library(lawstat)&#62; u=as.vector(Z[(n-100):n])&#62; runs.test(u,plot=TRUE) Runs Test - Two sided data:  u Standardized Runs Statistic = -0.4991, p-value = 0.6177The B's here are returns lower than the median (almost null, so they might be considered as negative returns). With such a high p-value, we accept the null hypothesis, i.e. time independence.If we consider a moving-time windowwe can see that we accept the assumption of independence most the the time.Actually, here, the time window is 100 days (+/- 50 days). But it is possible to consider 200 days,or even 400 days,So, except if we focus on 2006, it looks like we should reject the idea of time dependence in financial markets.It is also possible to look more carefully at the distribution of runs, and to compare it with the case of independent samples (here we consider monte carlo generation of sequences having the same size),&#62; m=length(Z)&#62; ns=100000&#62; HIST=matrix(NA,ns,15)&#62; for(j in 1:ns){+ XX=sample(c("A","B"),size=m,replace=TRUE)+ RUNX=rle(as.character(XX))$lengths+ S=sort(table(RUNX))+ HIST[j,]=S[as.character(1:15)]+ }&#62; meana=function(x){sum(x[is.na(x)==FALSE])/length(x)}&#62; cbind(TR[as.character(1:15)],apply(HIST,2,meana),+       round(m/(2^(1+1:15))))      [,1]       [,2] [,3]1    1309 1305.12304 13052     673  652.46513  6523     356  326.21119  3264     140  163.05101  1635     105   81.52366   826      35   40.74539   417      12   20.38198   208       6   10.16383   109       5    5.09871    510     NA    2.56239    311      1    1.26939    112     NA    0.63731    113      1    0.31815    014     NA    0.15812    015     NA    0.08013    0The first column above is the empirical frequency of runs of length 1,2,3, etc. The second one is the average frequencies obtained on random simulation of independent sample. The third one is the theoretical frequency based on a (geometric distribution with mean 1).Here again, it looks like our time series behave like an independent sample. Here is also a nice paper by Mark Schilling on the longest run of heads.So it is not that odd to observe such a series of losses on financial markets....