length(index(SP5))
# [1] 17519
- $SPX daily close pirce up to the date length is 17519.
- In order to render the array into the matrix whose colmn size =100.
- pick up the data from 21th element to 17420th. use matrix(data,ncol=100,byrow=T)
- use apply() to excute max() to each row respectively and put it to the w.
- pick up data from 22th to 1742th and do the same procedure.
- repeat 23th,24th,25,,,,,,until120th.
- the result is array w.
- run "matrix(w,ncol=174,byrow=T)" to create the matrix col=174 and row=100. with the parameter "byrow=T", the elemnet of w is filler by the order of row.
- run "as.vector(matrix(matrix(w,ncol=174,byrow=T),ncol=1,byrow = T))" to transform to the single dimention array. row and column are converted here.
w <- c();system.time(for(i in seq(0,99,1)){w <- append(w,
apply(
matrix(as.vector(SP5[,4])[(21+i):(17420+i)],ncol=100,byrow=T),1,max))})
# ユーザ システム 経過
# 3.223 0.345 3.586
matrix(w,ncol=174,byrow=T)[100,]
# [1] 20.12 22.20 23.28 24.66 24.60 25.55 26.66 25.06 26.09 29.19
# [11] 33.54 37.52 43.76 46.41 48.87 49.64 47.04 49.13 45.44 44.64
# [21] 51.62 56.67 60.71 60.39 58.40 58.07 64.86 68.68 72.64 71.06
# [31] 59.78 66.52 70.80 75.67 81.16 85.24 87.63 90.27 92.63 94.06
# [41] 87.61 88.29 94.75 97.59 98.91 104.99 108.37 106.16 98.33 90.23
# [51] 86.89 101.21 104.77 104.05 110.66 112.55 120.24 112.68 111.44 99.74
# [61] 93.10 86.01 95.61 93.53 103.51 107.83 107.46 102.17 98.92 99.60
# [71] 106.99 104.66 104.47 111.27 118.44 130.40 140.52 137.11 133.85 124.00
# [81] 124.88 148.93 170.99 172.65 169.28 168.87 182.19 192.43 201.52 244.74
# [91] 253.83 276.45 309.65 336.77 271.37 275.81 289.14 326.95 359.80 359.69
# [101] 368.95 331.75 390.45 396.64 420.77 425.09 441.28 456.33 469.50 482.00
# [111] 471.06 476.07 528.61 586.77 661.45 678.51 757.03 841.88 983.12 1052.02
# [121] 1186.75 1192.33 1362.80 1418.78 1469.25 1527.46 1520.77 1380.20 1312.83 1172.51
# [131] 1170.29 962.70 931.66 1039.58 1157.76 1156.86 1191.37 1225.31 1245.04 1294.18
# [141] 1325.76 1406.09 1495.42 1553.08 1565.15 1426.63 1305.32 934.70 1044.14 1150.23
# [151] 1217.28 1225.85 1343.01 1363.61 1326.06 1419.04 1465.77 1587.73 1709.67 1848.38
# [161] 1956.98 2031.92 2117.39 2130.82 2109.79 2119.12 2190.15 2395.96 2480.91 2786.24
# [171] 2872.87 2930.75 2854.88 3025.86
matrix(w,ncol=174,byrow=T)[,174]
# [1] 2854.88 2854.88 2854.88 2867.19 2867.24 2873.40 2879.39 2892.74 2895.77 2895.77
# [11] 2895.77 2895.77 2907.41 2907.41 2907.41 2907.41 2907.41 2907.97 2933.68 2933.68
# [21] 2933.68 2939.88 2943.03 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83
# [31] 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83
# [41] 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83
# [51] 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2954.18
# [61] 2954.18 2954.18 2954.18 2954.18 2954.18 2954.18 2964.33 2973.01 2995.82 2995.82
# [71] 2995.82 2995.82 2995.82 2999.91 3013.77 3014.30 3014.30 3014.30 3014.30 3014.30
# [81] 3014.30 3014.30 3019.56 3019.56 3025.86 3025.86 3025.86 3025.86 3025.86 3025.86
# [91] 3025.86 3025.86 3025.86 3025.86 3025.86 3025.86 3025.86 3025.86 3025.86 3025.86
as.vector(matrix(w,ncol=174,byrow=T))[17300:17400]
# [1] 2854.88 2854.88 2854.88 2854.88 2867.19 2867.24 2873.40 2879.39 2892.74 2895.77
# [11] 2895.77 2895.77 2895.77 2907.41 2907.41 2907.41 2907.41 2907.41 2907.97 2933.68
# [21] 2933.68 2933.68 2939.88 2943.03 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83
# [31] 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83
# [41] 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83
# [51] 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83 2945.83
# [61] 2954.18 2954.18 2954.18 2954.18 2954.18 2954.18 2954.18 2964.33 2973.01 2995.82
# [71] 2995.82 2995.82 2995.82 2995.82 2999.91 3013.77 3014.30 3014.30 3014.30 3014.30
# [81] 3014.30 3014.30 3014.30 3019.56 3019.56 3025.86 3025.86 3025.86 3025.86 3025.86
# [91] 3025.86 3025.86 3025.86 3025.86 3025.86 3025.86 3025.86 3025.86 3025.86 3025.86
# [101] 3025.86
matrix(w,ncol=174,byrow=T)[,173]
# [1] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [11] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [21] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [31] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [41] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [51] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [61] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [71] 2930.75 2930.75 2929.67 2925.51 2925.51 2925.51 2925.51 2925.51 2925.51 2925.51
# [81] 2925.51 2901.61 2885.57 2884.43 2880.34 2813.89 2813.89 2813.89 2813.89 2813.89
# [91] 2813.89 2813.89 2822.48 2832.94 2832.94 2832.94 2854.88 2854.88 2854.88
2854.88
max(as.vector(SP5[,4])[(173*100+20):(173*100+119)])
# [1]
2854.88
as.vector(matrix(w,ncol=174,byrow=T))[17201:17300]
# [1] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [11] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [21] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [31] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [41] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [51] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [61] 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75 2930.75
# [71] 2930.75 2930.75 2929.67 2925.51 2925.51 2925.51 2925.51 2925.51 2925.51 2925.51
# [81] 2925.51 2901.61 2885.57 2884.43 2880.34 2813.89 2813.89 2813.89 2813.89 2813.89
# [91] 2813.89 2813.89 2822.48 2832.94 2832.94 2832.94 2854.88 2854.88 2854.88 2854.88
> max(as.vector(SP5[,4])[(149*100+20):(149*100+119)])
[1]
1044.14
>
as.vector(matrix(matrix(w,ncol=174,byrow=T),ncol=1,byrow = T))[(149*100)]
[1]
1044.14
> max(as.vector(SP5[,4])[(19*100+20):(19*100+119)])
[1]
45.44
> as.vector(matrix(matrix(w,ncol=174,byrow=T),ncol=1,byrow = T))[(19*100)]
[1]
45.44