Take the 2-minute tour ×
Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. It's 100% free, no registration required.

Pseudorandom number generators are often tested using e.g. a test suite like Diehard tests or Dieharder. If one would run these tests e.g. on stock market time series or other financial data, would you expect your financial data to qualify as being a good random number generator or would it fail in many of these tests?

share|improve this question
    
Good question, may I ask what do you mean by random? Knuth in some of his book (probably Seminumerical Algorithms) mentioned something like this A person is insane if he thinks that computers can really generate something really "random". Now depending on your definition of random, you can make things as random or less random you like. Now it is extremely hard to devolop this kind of benchmarks, ad hoc per se. –  hhh Mar 26 '12 at 21:40
add comment

6 Answers 6

Variance ratio tests have been used numerous times to show that financial asset prices do not follow a random walk. You can for example look at

-Lo and MacKinlay : Stock market prices do not follow a random walk : http://press.princeton.edu/books/lo/chapt2.pdf (US Stocks)

-Hoque, Kim, Pyun: A comparison of variance ratio tests of random walk: A case of Asian emerging stock markets.

From a quick search, I haven't found any article using the kind of test you talk about. It seems like a new interesting approach so I completly agree with Dirk.

Furthermore, it would be interesting to change the time frame as asset can behave quite differently on different time frames. Liquidity should also be a factor.

Please keep us posted.

share|improve this answer
3  
In the same vein : financial time series have an econometric Hurst index that are usually above 1/2, which means that long memory phenomenons can be suspected. –  TheBridge Jun 21 '11 at 20:23
add comment

Why don't you try it and report back?

Recall, though, that while a random walk is often a rather competitive forecast, realized data is understood to have weak dependence especially in higher moments.

Having worked a bit with DieHarder, I'd suspect it to reject a number of series. But the proof is in the pudding...

share|improve this answer
    
I will try to do it, but it might take some time, since I'm still a beginner in R. Can you recommend a standard data series of financial data (which is freely available) which would be interesting to test and could be used as input for the RDieHarder package? –  asmaier Jun 24 '11 at 10:01
    
@asmaier: I just started reading about these tests but I think you may not have enough usable data finance. –  Zarbouzou Jun 28 '11 at 13:19
add comment

I have tested lots of forex data for randomness. Some currency pairs are very close to random walk. And the problem is open question, because there is no uniform explanation what the random walk is. According to Mandelbrot, Taleb and some other authors randomness can be different. Even if the data is not random it doesn't mean it can be effectively traded. In other words, test for existence of trade opportunity is more useful than randomness test.

share|improve this answer
    
- "no uniform explanation what the random walk is" is very inaccurate. A random walk is a very well defined object. –  Ryogi Oct 31 '11 at 20:50
1  
but good point about trade (betting) opportunities as the ultimate test. Casinos make quite a bit of money from stationary, independent, random time series. –  Pete Dec 16 '11 at 14:59
add comment

All the ideas above are great ideas.

Another kind of test would be an idea borrowed from Random Matrix Theory.

Assemble your time-series into a matrix. Evaluate the distribution of the eigenvalues of the matrix vs. the distribution of a random matrix. Turns out that the distribution of eigenvalues in a random matrix conforms to distributions such as the Marchenko-Pastur distribution.

If the distribution of eigenvalues conform to the eigenvalues predicted by a random matrix (where each entry corresponds to a draw from a standard normal random variable, for example), then there is probably not information in the time-series. Here is an illustration of Wigner's semi-circle law for a random matrix.

share|improve this answer
    
+1: Great answer! –  vonjd Dec 9 '11 at 16:18
add comment

would you expect your financial data to qualify as being a good random number generator

Financial time-series, specifically price-change series, would make terrible random number generators because they generally contain significant dependencies.

or would it fail in many of these tests?

If you test for randomness, meaning, initial conditions do not completely determine the subsequent values, you will generally find price-change series to be random. I say generally because you will also find situtations (which come and go, and are rare) where price-change series are measurably deterministic.

If you test for dependence, you will generally find serious serial dependencies in price-change series. For example, a price increase followed by a price increase is generally far more probable than one finds with artificially generated random, independent price-change series.

I say "generally" because the statistical characteristics can change with time and with market, back and forth.

So, to summarize, the fact that price-change series are normally dependent is why technical analysis works. The fact that the series are random is why many smart people are fooled into thinking technical analysis doesn't work.

share|improve this answer
add comment

There are also the NIST tests used to examine the random number generators used in cryptographic systems. http://csrc.nist.gov/groups/ST/toolkit/rng/index.html

I played around with it a little bit, here is the first test, the monobit test.

library(stats)
library(quantmod)

code_input <- function(sym, fn=Cl) {
    return(na.omit(as.vector(ifelse(ROC(fn(sym)) >= 0, 1, -1))))
}

#from help(stats)
erfc <- function(x) 2 * pnorm(x * sqrt(2), lower = FALSE)


monobit <- function(v) { 
    sobs <- abs(sum(v))/sqrt(length(v)) ; 
    return(erfc(sobs/sqrt(2)))
}

run_test_block <- function(input, n=100) {
    nrand <- 0
    nnonrand <- 0
    cnt <- 0
    for (i in seq(1, length(input), n)) {
        if ((i + n) < length(input)) {
            cnt <- cnt + 1
            pval <- monobit(input[i:(i+n)])
            if (pval < 0.01) {
                nnonrand <- nnonrand + 1
            } else {
                nrand <- nrand + 1          
            }
        }
    }
    sprintf("%d tests %d random, %d nonrandom", cnt, nrand, nnonrand)
}

run_test <- function(input, n=100) {

    nrand <- 0
    nnonrand <- 0
    cnt <- 0
    for (i in 1:(length(input) - n)) {
        cnt <- cnt + 1
        pval <- monobit(input[i:(i+n)])
        if (pval < 0.01) {
            nnonrand <- nnonrand + 1
        } else {
            nrand <- nrand + 1          
        }
    }

    sprintf("%d tests %d random, %d nonrandom", cnt, nrand, nnonrand)

}

getSymbols("^GSPC", from="1970-01-01")
run_test(code_input(GSPC))
#[1] "10491 tests 10143 random, 348 nonrandom"
run_test_block(code_input(GSPC))
#[1] "105 tests 101 random, 4 nonrandom"

Make of that what you will. The NIST paper recommended that only the cases determined to be random by the monobit test be subject to the additional tests.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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