-
Notifications
You must be signed in to change notification settings - Fork 0
/
02_out_of_sample_tests.R
187 lines (154 loc) · 7.95 KB
/
02_out_of_sample_tests.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#################################
### Out-of-sample tests ###
#################################
library(dplyr)
load("Results/Var/Var.RData")
load("Results/SharpeR/Sharpe.RData")
block <- 12
Ropt_ls_0 <- read.csv("Results/Rport_2_120_ls_0_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_1 <- read.csv("Results/Rport_2_120_ls_1_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_2 <- read.csv("Results/Rport_2_120_ls_2_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_3 <- read.csv("Results/Rport_2_120_ls_3_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_4 <- read.csv("Results/Rport_2_120_ls_4_ibrx.csv")[, c(2:10, 1)]
# Minimum Variance
p_values_mv <- matrix(NA, ncol = 5, nrow = 9)
for (i in 2:10) {
set.seed(i)
p_values_mv[i - 1, 1] <- boot.time.inference.log.var(Ropt_ls_0[, c(1, i)], b = block, M = 500)$p.Value
p_values_mv[i - 1, 2] <- boot.time.inference.log.var(Ropt_ls_1[, c(1, i)], b = block, M = 500)$p.Value
p_values_mv[i - 1, 3] <- boot.time.inference.log.var(Ropt_ls_2[, c(1, i)], b = block, M = 500)$p.Value
p_values_mv[i - 1, 4] <- boot.time.inference.log.var(Ropt_ls_3[, c(1, i)], b = block, M = 500)$p.Value
p_values_mv[i - 1, 5] <- boot.time.inference.log.var(Ropt_ls_4[, c(1, i)], b = block, M = 500)$p.Value
}
rownames(p_values_mv) <- colnames(Ropt_ls_0)[-1]
Ropt_mv <- cbind(Ropt_ls_0[, 1:9], Ropt_ls_1[, 1:9], Ropt_ls_2[, 1:9], Ropt_ls_3[, 1:9], Ropt_ls_4)
p_values_mv_full <- c()
for (i in 2:46) {
set.seed(i)
p_values_mv_full[i - 1] <- boot.time.inference.log.var(Ropt_mv[, c(1, i)], b = block, M = 500)$p.Value
}
# Lambda 2
Ropt_ls_0 <- read.csv("Results/Rport_2_120_ls_0_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_1 <- read.csv("Results/Rport_2_120_ls_1_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_2 <- read.csv("Results/Rport_2_120_ls_2_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_3 <- read.csv("Results/Rport_2_120_ls_3_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_4 <- read.csv("Results/Rport_2_120_ls_4_ibrx.csv")[, c(12:20, 11)]
p_values_2 <- matrix(NA, ncol = 5, nrow = 9)
for (i in 2:10) {
set.seed(i)
p_values_2[i - 1, 1] <- boot.time.inference(Ropt_ls_0[, c(1, i)], b = block, M = 500)$p.Value
p_values_2[i - 1, 2] <- boot.time.inference(Ropt_ls_1[, c(1, i)], b = block, M = 500)$p.Value
p_values_2[i - 1, 3] <- boot.time.inference(Ropt_ls_2[, c(1, i)], b = block, M = 500)$p.Value
p_values_2[i - 1, 4] <- boot.time.inference(Ropt_ls_3[, c(1, i)], b = block, M = 500)$p.Value
p_values_2[i - 1, 5] <- boot.time.inference(Ropt_ls_4[, c(1, i)], b = block, M = 500)$p.Value
}
rownames(p_values_2) <- colnames(Ropt_ls_0)[-1]
Ropt_mv <- cbind(Ropt_ls_0[, 1:9], Ropt_ls_1[, 1:9], Ropt_ls_2[, 1:9], Ropt_ls_3[, 1:9], Ropt_ls_4)
p_values_2_full <- c()
for (i in 2:46) {
set.seed(i)
p_values_2_full[i - 1] <- boot.time.inference.log.var(Ropt_mv[, c(1, i)], b = block, M = 500)$p.Value
}
# lambda 5
Ropt_ls_0 <- read.csv("Results/Rport_5_7_120_ls_0_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_1 <- read.csv("Results/Rport_5_7_120_ls_1_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_2 <- read.csv("Results/Rport_5_7_120_ls_2_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_3 <- read.csv("Results/Rport_5_7_120_ls_3_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_4 <- read.csv("Results/Rport_5_7_120_ls_4_ibrx.csv")[, c(2:10, 1)]
p_values_5 <- matrix(NA, ncol = 5, nrow = 9)
for (i in 2:10) {
set.seed(i)
p_values_5[i - 1, 1] <- boot.time.inference(Ropt_ls_0[, c(1, i)], b = block, M = 500)$p.Value
p_values_5[i - 1, 2] <- boot.time.inference(Ropt_ls_1[, c(1, i)], b = block, M = 500)$p.Value
p_values_5[i - 1, 3] <- boot.time.inference(Ropt_ls_2[, c(1, i)], b = block, M = 500)$p.Value
p_values_5[i - 1, 4] <- boot.time.inference(Ropt_ls_3[, c(1, i)], b = block, M = 500)$p.Value
p_values_5[i - 1, 5] <- boot.time.inference(Ropt_ls_4[, c(1, i)], b = block, M = 500)$p.Value
}
rownames(p_values_5) <- colnames(Ropt_ls_0)[-1]
Ropt_mv <- cbind(Ropt_ls_0[, 1:9], Ropt_ls_1[, 1:9], Ropt_ls_2[, 1:9], Ropt_ls_3[, 1:9], Ropt_ls_4)
p_values_5_full <- c()
for (i in 2:46) {
set.seed(i)
p_values_5_full[i - 1] <- boot.time.inference.log.var(Ropt_mv[, c(1, i)], b = block, M = 500)$p.Value
}
# lambda 7
Ropt_ls_0 <- read.csv("Results/Rport_5_7_120_ls_0_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_1 <- read.csv("Results/Rport_5_7_120_ls_1_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_2 <- read.csv("Results/Rport_5_7_120_ls_2_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_3 <- read.csv("Results/Rport_5_7_120_ls_3_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_4 <- read.csv("Results/Rport_5_7_120_ls_4_ibrx.csv")[, c(12:20, 11)]
# Tests within panel (panel = cov estimator)
p_values_7 <- matrix(NA, ncol = 5, nrow = 9)
for (i in 2:10) {
set.seed(i)
p_values_7[i - 1, 1] <- boot.time.inference(Ropt_ls_0[, c(1, i)], b = block, M = 500)$p.Value
p_values_7[i - 1, 2] <- boot.time.inference(Ropt_ls_1[, c(1, i)], b = block, M = 500)$p.Value
p_values_7[i - 1, 3] <- boot.time.inference(Ropt_ls_2[, c(1, i)], b = block, M = 500)$p.Value
p_values_7[i - 1, 4] <- boot.time.inference(Ropt_ls_3[, c(1, i)], b = block, M = 500)$p.Value
p_values_7[i - 1, 5] <- boot.time.inference(Ropt_ls_4[, c(1, i)], b = block, M = 500)$p.Value
}
rownames(p_values_7) <- colnames(Ropt_ls_0)[-1]
Ropt_mv <- cbind(Ropt_ls_0[, 1:9], Ropt_ls_1[, 1:9], Ropt_ls_2[, 1:9], Ropt_ls_3[, 1:9], Ropt_ls_4)
p_values_7_full <- c()
for (i in 2:46) {
set.seed(i)
p_values_7_full[i - 1] <- boot.time.inference.log.var(Ropt_mv[, c(1, i)], b = block, M = 500)$p.Value
}
# lambda 05
Ropt_ls_0 <- read.csv("Results/Rport_05_1_120_ls_0_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_1 <- read.csv("Results/Rport_05_1_120_ls_1_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_2 <- read.csv("Results/Rport_05_1_120_ls_2_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_3 <- read.csv("Results/Rport_05_1_120_ls_3_ibrx.csv")[, c(2:10, 1)]
Ropt_ls_4 <- read.csv("Results/Rport_05_1_120_ls_4_ibrx.csv")[, c(2:10, 1)]
# Tests within panel (panel = cov estimator)
p_values_05 <- matrix(NA, ncol = 5, nrow = 9)
for (i in 2:10) {
set.seed(i)
p_values_05[i - 1, 1] <- boot.time.inference(Ropt_ls_0[, c(1, i)], b = block, M = 500)$p.Value
p_values_05[i - 1, 2] <- boot.time.inference(Ropt_ls_1[, c(1, i)], b = block, M = 500)$p.Value
p_values_05[i - 1, 3] <- boot.time.inference(Ropt_ls_2[, c(1, i)], b = block, M = 500)$p.Value
p_values_05[i - 1, 4] <- boot.time.inference(Ropt_ls_3[, c(1, i)], b = block, M = 500)$p.Value
p_values_05[i - 1, 5] <- boot.time.inference(Ropt_ls_4[, c(1, i)], b = block, M = 500)$p.Value
}
rownames(p_values_05) <- colnames(Ropt_ls_0)[-1]
Ropt_mv <- cbind(Ropt_ls_0[, 1:9], Ropt_ls_1[, 1:9], Ropt_ls_2[, 1:9], Ropt_ls_3[, 1:9], Ropt_ls_4)
p_values_05_full <- c()
for (i in 2:46) {
set.seed(i)
p_values_05_full[i - 1] <- boot.time.inference.log.var(Ropt_mv[, c(1, i)], b = block, M = 500)$p.Value
}
# lambda 11
Ropt_ls_0 <- read.csv("Results/Rport_05_1_120_ls_0_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_1 <- read.csv("Results/Rport_05_1_120_ls_1_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_2 <- read.csv("Results/Rport_05_1_120_ls_2_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_3 <- read.csv("Results/Rport_05_1_120_ls_3_ibrx.csv")[, c(12:20, 11)]
Ropt_ls_4 <- read.csv("Results/Rport_05_1_120_ls_4_ibrx.csv")[, c(12:20, 11)]
# Tests within panel (panel = cov estimator)
p_values_1 <- matrix(NA, ncol = 5, nrow = 9)
for (i in 2:10) {
set.seed(i)
p_values_1[i - 1, 1] <- boot.time.inference(Ropt_ls_0[, c(1, i)], b = block, M = 500)$p.Value
p_values_1[i - 1, 2] <- boot.time.inference(Ropt_ls_1[, c(1, i)], b = block, M = 500)$p.Value
p_values_1[i - 1, 3] <- boot.time.inference(Ropt_ls_2[, c(1, i)], b = block, M = 500)$p.Value
p_values_1[i - 1, 4] <- boot.time.inference(Ropt_ls_3[, c(1, i)], b = block, M = 500)$p.Value
p_values_1[i - 1, 5] <- boot.time.inference(Ropt_ls_4[, c(1, i)], b = block, M = 500)$p.Value
}
rownames(p_values_1) <- colnames(Ropt_ls_0)[-1]
Ropt_mv <- cbind(Ropt_ls_0[, 1:9], Ropt_ls_1[, 1:9], Ropt_ls_2[, 1:9], Ropt_ls_3[, 1:9], Ropt_ls_4)
p_values_1_full <- c()
for (i in 2:46) {
set.seed(i)
p_values_1_full[i - 1] <- boot.time.inference.log.var(Ropt_mv[, c(1, i)], b = block, M = 500)$p.Value
}
p_values_mv
p_values_2
p_values_5
p_values_7
p_values_05
p_values_1
p_values_mv_full
p_values_2_full
p_values_5_full
p_values_7_full
p_values_05_full
p_values_1_full