Created
March 24, 2024 08:27
-
-
Save JSzitas/e0da5133fc4cf3dd45c2e31634cc61b8 to your computer and use it in GitHub Desktop.
Description of multiple testing problems with many random processes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# discretised ornstein-uhlenbeck | |
ou <- function(steps, theta = 1.0, mu = 1.2, sigma = 0.3, dt = 0.01) { | |
x <- rep(NA, steps+1) | |
x[1] = 0 | |
for(i in 2:(steps+1)) { | |
x[i] = x[i-1] + theta * (mu - x[i-1]) * dt + sigma * sqrt(dt) * rnorm(1); | |
} | |
return(x) | |
} | |
# ~~2 years of simulated data if you account for weekends and holidays | |
snp = replicate(ou(520, 0.3), n = 500) | |
# compute correlations | |
corrs = cor(snp, method = 'spearman') | |
# drop diagonal elements since those are all 1 | |
corrs = corrs[c(lower.tri(corrs), upper.tri(corrs))] | |
# show 10 lowest | |
print(sort(corrs)[1:10]) | |
# show 10 highest | |
print(-sort(-corrs)[1:10]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So if you carry out this sort of multiple testing just on 2 years of S&P, you will get very high positive and negative correlations, driven by nothing but randomness (if you accept that individual stocks can be modeled by a OU-like stochastic process).