Skip to content

Commit 758ad71

Browse files
committed
added 1hrs pv1 modles and results
1 parent bdb9e79 commit 758ad71

File tree

42 files changed

+62697
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+62697
-0
lines changed

Diff for: 1hrs_pv1_report_generator.R

+320
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
source('funcs.R')
2+
3+
# benchmark models ----
4+
5+
report.full(model = 'snaive()',
6+
series = '1hrs pv1',
7+
transformation = 'identity()',
8+
traindays = 7,
9+
testdays = 1)
10+
11+
report.full(model = 'meanf()',
12+
series = '1hrs pv1',
13+
transformation = 'identity()',
14+
traindays = 7,
15+
testdays = 1)
16+
17+
report.full(model = 'naive()',
18+
series = '1hrs pv1',
19+
transformation = 'identity()',
20+
traindays = 7,
21+
testdays = 1)
22+
23+
# try to find the best ARIMA model ----
24+
report(model = 'Arima(order=c(1, 0, 0))',
25+
series = '1hrs pv1',
26+
transformation = 'identity()',
27+
diffs = 'identity()',
28+
sdiffs = 'identity()',
29+
startday = 0,
30+
traindays = 7,
31+
testdays = 3)
32+
33+
report(model = 'Arima(order=c(2, 0, 0))',
34+
series = '1hrs pv1',
35+
transformation = 'identity()',
36+
diffs = 'identity()',
37+
sdiffs = 'identity()',
38+
startday = 0,
39+
traindays = 7,
40+
testdays = 3)
41+
42+
report(model = 'Arima(order=c(3, 0, 0))',
43+
series = '1hrs pv1',
44+
transformation = 'identity()',
45+
diffs = 'identity()',
46+
sdiffs = 'identity()',
47+
startday = 0,
48+
traindays = 7,
49+
testdays = 3)
50+
51+
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0))',
52+
series = '1hrs pv1',
53+
transformation = 'identity()',
54+
diffs = 'identity()',
55+
sdiffs = 'identity()',
56+
startday = 0,
57+
traindays = 7,
58+
testdays = 3)
59+
60+
# add fourier terms
61+
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), xreg=fourier(., K=2))',
62+
series = '1hrs pv1',
63+
transformation = 'identity()',
64+
diffs = 'identity()',
65+
sdiffs = 'identity()',
66+
startday = 0,
67+
traindays = 7,
68+
testdays = 3,
69+
xreg='fourier(., K=2, h=h)')
70+
71+
# Find the best train:test days ratio for ARIMA(1,0,0)(1,0,0) ----
72+
scaler <- 1/100000000000
73+
best.fcast.1hrsPv1 <- NULL
74+
best.traindays <- 0
75+
best.testdays <- 0
76+
77+
for(traindays in 3:7)
78+
{
79+
for(testdays in 2:3)
80+
{
81+
print(paste("Trying", traindays, "train days and", testdays, "test days"))
82+
current <- fullforecast(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS")',
83+
dataset = datasets[['1hrs pv1']]$series * scaler,
84+
transformation = 'identity()',
85+
traindays = traindays,
86+
testdays = testdays,
87+
xreg=NULL)
88+
89+
if(is.null(best.fcast.1hrsPv1) || current$accuracy[[2]] < best.fcast.1hrsPv1$accuracy[[2]])
90+
{
91+
best.fcast.1hrsPv1 <- current
92+
best.traindays <- traindays
93+
best.testdays <- testdays
94+
}
95+
}
96+
}
97+
98+
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML")',
99+
series = '1hrs pv1',
100+
transformation = 'identity()',
101+
traindays = best.traindays, # 5
102+
testdays = best.testdays) # 2
103+
104+
# Skip over the step where I hardcode a fourier value ----
105+
# Find best K for the above model ARIMA(1,0,0)(1,0,0) ----
106+
107+
best.fcast.k.1hrsPv1 <- NULL
108+
best.k <- 0
109+
#K must be not be greater than period/2
110+
for(k in 1:(frequency(datasets[['1hrs pv1']]$series)/2))
111+
{
112+
print(paste("Trying k =", k))
113+
m <- paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=fourier(., K=', k, '))')
114+
xreg <- paste0('fourier(., h=h, K=', k, ')')
115+
current <- fullforecast(model = m,
116+
dataset = datasets[['1hrs pv1']]$series * scaler,
117+
transformation = 'identity()',
118+
traindays = best.traindays, # ?
119+
testdays = best.testdays, # ?
120+
xreg=xreg)
121+
122+
if(is.null(best.fcast.k.1hrsPv1) || current$accuracy[[2]] < best.fcast.k.1hrsPv1$accuracy[[2]])
123+
{
124+
best.fcast.k.1hrsPv1 <- current
125+
best.k <- k
126+
}
127+
}
128+
129+
report.full(model = paste('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=fourier(., K=', best.k, '))', sep=''),
130+
series = '1hrs pv1',
131+
transformation = 'identity()',
132+
traindays = best.traindays, # 5
133+
testdays = best.testdays, # 2
134+
xreg = paste('fourier(., h=h, K=', best.k, ')')) # 2
135+
136+
# Best model: 5:2, ARIMA(1, 0, 0)(1, 0, 0), K=2, RMSE=460 MAE=232 ----
137+
# 11th-17th obs dummies rmse=461, mae=230
138+
# without seasonal part, only fourier: rmse=460, mae=234
139+
# without seasonal part, 2AR, only fourier: rmse=460, mae=234
140+
# without seasonal part, 3AR, only fourier: rmse=460, mae=234
141+
# dummies without seasonal part, only fourier: rmse=460, mae=237
142+
# dummies without seasonal part, 2AR, only fourier: rmse=460, mae=237
143+
# dummies without seasonal part, 3AR, only fourier: rmse=460, mae=237
144+
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=fourier(., K=2))',
145+
series = '1hrs pv1',
146+
transformation = 'identity()',
147+
traindays = 5,
148+
testdays = 2,
149+
xreg = 'fourier(., h=h, K=2)')
150+
151+
dummies.fcast <- quote(
152+
{cbind(
153+
dummies=getNthObsDummies(11, 6, h, frequency(.)),
154+
fourier(., h=h, K=2)
155+
)}
156+
)
157+
158+
dummies.fit <- quote(
159+
{cbind(
160+
dummies=getNthObsDummies(11, 6, length(.), frequency(.)),
161+
fourier(., K=2)
162+
)}
163+
)
164+
165+
report.full(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=', paste0(deparse(dummies.fit), collapse='') ,')'),
166+
series = '1hrs pv1',
167+
transformation = 'identity()',
168+
traindays = 5,
169+
testdays = 2,
170+
xreg = paste0(deparse(dummies.fcast), collapse=''))
171+
172+
# NO SAR, with dummies
173+
# rmse=460, mae=234
174+
report.full(model = paste0('Arima(order=c(1, 0, 0), method="CSS", xreg=', paste0(deparse(dummies.fit), collapse='') ,')'),
175+
series = '1hrs pv1',
176+
transformation = 'identity()',
177+
traindays = 5,
178+
testdays = 2,
179+
xreg = paste0(deparse(dummies.fcast), collapse=''))
180+
181+
# no SAR with dummies
182+
# 2 AR terms
183+
# rmse=460, mae=234
184+
report.full(model = paste0('Arima(order=c(2, 0, 0), method="CSS", xreg=', paste0(deparse(dummies.fit), collapse='') ,')'),
185+
series = '1hrs pv1',
186+
transformation = 'identity()',
187+
traindays = 5,
188+
testdays = 2,
189+
xreg = paste0(deparse(dummies.fcast), collapse=''))
190+
191+
# no SAR with dummies
192+
# 3 AR terms
193+
# rmse=, mae=
194+
report.full(model = paste0('Arima(order=c(3, 0, 0), method="CSS", xreg=', paste0(deparse(dummies.fit), collapse='') ,')'),
195+
series = '1hrs pv1',
196+
transformation = 'identity()',
197+
traindays = 5,
198+
testdays = 2,
199+
xreg = paste0(deparse(dummies.fcast), collapse=''))
200+
201+
# no SAR, no dummies
202+
# rmse=460, mae=237
203+
report.full(model = 'Arima(order=c(1, 0, 0), method="CSS", xreg=fourier(., K=2))',
204+
series = '1hrs pv1',
205+
transformation = 'identity()',
206+
traindays = 5,
207+
testdays = 2,
208+
xreg = 'fourier(., h=h, K=2)')
209+
210+
# no SAR, no dummies, 2AR
211+
# rmse=460, mae=237
212+
report.full(model = 'Arima(order=c(2, 0, 0), method="CSS", xreg=fourier(., K=2))',
213+
series = '1hrs pv1',
214+
transformation = 'identity()',
215+
traindays = 5,
216+
testdays = 2,
217+
xreg = 'fourier(., h=h, K=2)')
218+
219+
# no SAR, no dummies, 3 AR terms
220+
# rmse=460, mae=237
221+
report.full(model = 'Arima(order=c(3, 0, 0), method="CSS", xreg=fourier(., K=2))',
222+
series = '1hrs pv1',
223+
transformation = 'identity()',
224+
traindays = 5,
225+
testdays = 2,
226+
xreg = 'fourier(., h=h, K=2)')
227+
228+
229+
# dummies on every weekday ----
230+
231+
dailyD.fcast <- quote(
232+
{cbind(
233+
dummies=getDailyDummies(h, frequency(.), start(.)[[1]]),
234+
fourier(., h=h, K=2)
235+
)}
236+
)
237+
238+
dailyD.fit <- quote(
239+
{cbind(
240+
dummies=getDailyDummies(length(.), frequency(.), start(.)[[1]]),
241+
fourier(., K=2)
242+
)}
243+
)
244+
245+
# 5:2 rmse=?, mae=?
246+
report.full(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=', paste0(deparse(dailyD.fit), collapse='') ,')'),
247+
series = '1hrs pv1',
248+
transformation = 'identity()',
249+
traindays = 5,
250+
testdays = 2,
251+
xreg = paste0(deparse(dailyD.fcast), collapse=''))
252+
253+
# dummies on the ?-?th+?-?th obs (the "outliers") ----
254+
255+
best.fcast.dummy.1hrsPv1 <- NULL
256+
best.startDummy <- 0
257+
best.lenDummy <- 0
258+
259+
for(startDummy in 8:11)
260+
{
261+
for(lenDummy in 5:9)
262+
{
263+
print(paste("Trying startDummy =", startDummy, ", length =", lenDummy))
264+
265+
obsDummies.fcast <- substitute(
266+
{cbind(
267+
dummies=getNthObsDummies(startDummy, lenDummy, h, frequency(.)),
268+
fourier(., h=h, K=2)
269+
)},
270+
list(startDummy=startDummy, lenDummy=lenDummy)
271+
)
272+
273+
obsDummies.fit <- substitute(
274+
{cbind(
275+
dummies=getNthObsDummies(startDummy, lenDummy, length(.), frequency(.)),
276+
fourier(., K=2)
277+
)},
278+
list(startDummy=startDummy, lenDummy=lenDummy)
279+
)
280+
281+
current <- fullforecast(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=', paste0(deparse(obsDummies.fit), collapse='') ,')'),
282+
dataset = datasets[['1hrs pv1']]$series,
283+
transformation = 'identity()',
284+
traindays = 5,
285+
testdays = 2,
286+
xreg = paste0(deparse(obsDummies.fcast), collapse=''))
287+
288+
if(is.null(best.fcast.dummy.1hrsPv1) || current$accuracy[[2]] < best.fcast.dummy.1hrsPv1$accuracy[[2]])
289+
{
290+
best.fcast.dummy.1hrsPv1 <- current
291+
best.startDummy <- startDummy
292+
best.lenDummy <- lenDummy
293+
}
294+
295+
}
296+
}
297+
298+
bestObsDummies.fcast <- substitute(
299+
{cbind(
300+
dummies=getNthObsDummies(best.startDummy, best.lenDummy, h, frequency(.)),
301+
fourier(., h=h, K=2)
302+
)},
303+
list(best.startDummy = best.startDummy, best.lenDummy = best.lenDummy)
304+
)
305+
306+
bestObsDummies.fit <- substitute(
307+
{cbind(
308+
dummies=getNthObsDummies(best.startDummy, best.lenDummy, length(.), frequency(.)),
309+
fourier(., K=2)
310+
)},
311+
list(best.startDummy = best.startDummy, best.lenDummy = best.lenDummy)
312+
)
313+
314+
# 5:2, dummies: 11:6, rmse=461, mae=230
315+
report.full(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=', paste0(deparse(bestObsDummies.fit), collapse='') ,')'),
316+
series = '1hrs pv1',
317+
transformation = 'identity()',
318+
traindays = 5,
319+
testdays = 2,
320+
xreg = paste0(deparse(bestObsDummies.fcast), collapse=''))

Diff for: best/1hrs pv1/1e07e618a51e523975363387d67d2bae.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
full_Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg={ cbind(dummies = getNthObsDummies(11, 6, length(.), frequency(.)), fourier(., K = 2))}).1hrs pv1.identity().5.2.{ cbind(dummies = getNthObsDummies(11, 6, h, frequency(.)), fourier(., h = h, K = 2))}.html

Diff for: best/1hrs pv1/21000db0d8995fa1ea3949958b8acb75.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
full_Arima(order=c(2, 0, 0), method="CSS", xreg=fourier(., K=2)).1hrs pv1.identity().5.2.fourier(., h=h, K=2).html

Diff for: best/1hrs pv1/3643576a3203796d26f7c165a0515045.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
full_Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=fourier(., K=2)).1hrs pv1.identity().5.2.fourier(., h=h, K=2).html

Diff for: best/1hrs pv1/613813527e6c0d041b96fca008699b79.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
full_Arima(order=c(1, 0, 0), method="CSS", xreg=fourier(., K=2)).1hrs pv1.identity().5.2.fourier(., h=h, K=2).html

Diff for: best/1hrs pv1/7ee9214facedc18fd3bbd7b5bf1323b7.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
full_Arima(order=c(2, 0, 0), method="CSS", xreg={ cbind(dummies = getNthObsDummies(11, 6, length(.), frequency(.)), fourier(., K = 2))}).1hrs pv1.identity().5.2.{ cbind(dummies = getNthObsDummies(11, 6, h, frequency(.)), fourier(., h = h, K = 2))}.html

Diff for: best/1hrs pv1/8d0ec1c268a442e02922b3d90f89bc0f.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
full_Arima(order=c(1, 0, 0), method="CSS", xreg={ cbind(dummies = getNthObsDummies(11, 6, length(.), frequency(.)), fourier(., K = 2))}).1hrs pv1.identity().5.2.{ cbind(dummies = getNthObsDummies(11, 6, h, frequency(.)), fourier(., h = h, K = 2))}.html

Diff for: best/1hrs pv1/aabd5c26fd0b178fccdcf68f471b5b77.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
full_Arima(order=c(3, 0, 0), method="CSS", xreg={ cbind(dummies = getNthObsDummies(11, 6, length(.), frequency(.)), fourier(., K = 2))}).1hrs pv1.identity().5.2.{ cbind(dummies = getNthObsDummies(11, 6, h, frequency(.)), fourier(., h = h, K = 2))}.html

Diff for: best/1hrs pv1/b6d7b1f4ccb94d8ace9a258b6f01ff7e.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
full_Arima(order=c(3, 0, 0), method="CSS", xreg=fourier(., K=2)).1hrs pv1.identity().5.2.fourier(., h=h, K=2).html

0 commit comments

Comments
 (0)