-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrho_test.R
42 lines (34 loc) · 851 Bytes
/
rho_test.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
setwd(Sys.getenv("masters-thesis"))
source('Estimation/rho.R')
### Functions
simAR<-function(n, rho, sd){
X<-rep(NA,n)
X[1]<-rnorm(1, 0, sd/(1-rho))
eps<-rnorm(n-1,0,sd)
for(i in 2:n){
X[i] <- rho*X[i-1]+eps[i-1]
}
return(X)
}
T_star_func <- function(sim,m) {
out <- max(abs(sim[m:length(sim)]))
return(out)
}
### Simulate T_stars
paths <- 500 #One second pr. 10 path
rho <- 0
m <- 2500
sd <- sqrt(1-rho^2)
a_m <- sqrt(2*log(m))
b_m <- a_m - 1/2*log(pi*log(m))/a_m
T_stars <- numeric(length = paths)
Gumbels <- T_stars
p0 <- Sys.time()
for (i in 1:paths) {
sim <- simAR(10*m,rho,sd)
T_stars[i] <- T_star_func(sim,m)
Gumbels[i] <- (T_stars[i]-b_m)*a_m
}
print(Sys.time()-p0)
(my_T_quant <- quantile(T_stars,0.95)) # according to my simulation
(my_gumbel_quant <- quantile(Gumbels,0.95)) # according to my simulation