Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
nils.koster
ptsfc_results
Commits
50b2e0b8
Commit
50b2e0b8
authored
Dec 09, 2021
by
jbracher
Browse files
Fixing evaluation codes so they work if no new DAX observation is available.
parent
b4a9c579
Changes
1
Hide whitespace changes
Inline
Side-by-side
code/evaluate_forecasts.R
View file @
50b2e0b8
...
...
@@ -6,7 +6,7 @@ library(quantmod)
# source functions:
source
(
"functions.R"
)
forecast_dates0
<-
Sys.Date
()
-
10
:
2
# as.Date("2021-11-17")
forecast_dates0
<-
Sys.Date
()
-
10
:
1
# as.Date("2021-11-17")
forecast_dates
<-
forecast_dates0
[
weekdays
(
forecast_dates0
)
%in%
c
(
"Mittwoch"
,
"Wednesday"
)]
# forecast_dates <- as.Date("2021-11-17")
...
...
@@ -23,13 +23,13 @@ for(i in seq_along(forecast_dates)){
# read in:
all_forecasts
<-
NULL
for
(
i
in
seq_along
(
files
)){
dat_temp
<-
read.csv
(
paste0
(
"../"
,
week_tag
,
"/"
,
files
[
i
]),
for
(
j
in
seq_along
(
files
)){
dat_temp
<-
read.csv
(
paste0
(
"../"
,
week_tag
,
"/"
,
files
[
j
]),
colClasses
=
c
(
forecast_date
=
"Date"
))
dat_temp
$
X
<-
NULL
dat_temp
$
model
<-
extract_name_from_file
(
files
[
i
])
dat_temp
$
model
<-
extract_name_from_file
(
files
[
j
])
if
(
!
is.null
(
all_forecasts
)){
all_forecasts
<-
rbind
(
all_forecasts
,
dat_temp
)
...
...
@@ -49,10 +49,6 @@ for(i in seq_along(forecast_dates)){
dat_dax
$
value
<-
100
*
(
log
(
dat_dax
$
value
)
-
log
(
reference_value
))
truths_dax
<-
subset
(
dat_dax
,
date
%in%
(
forecast_date
+
c
(
1
,
2
,
5
,
6
,
7
)))
truths_dax
<-
truths_dax
[
order
(
truths_dax
$
date
),
]
truths_dax
$
target
<-
"DAX"
truths_dax
$
horizon
<-
c
(
"1 day"
,
"2 day"
,
"5 day"
,
"6 day"
,
"7 day"
)[
1
:
nrow
(
truths_dax
)]
truths_dax
$
date
<-
NULL
# subset forecasts to DAX:
dax_forecasts
<-
subset
(
all_forecasts
,
target
==
"DAX"
)
...
...
@@ -61,9 +57,20 @@ for(i in seq_along(forecast_dates)){
dax_forecasts
<-
subset
(
dax_forecasts
,
horizon
%in%
c
(
"1 day"
,
"2 day"
,
"5 day"
,
"6 day"
,
"7 day"
))
# add truth data:
dax_forecasts
<-
merge
(
dax_forecasts
,
truths_dax
,
by
=
c
(
"target"
,
"horizon"
),
all.x
=
TRUE
)
# add truths:
if
(
nrow
(
truths_dax
)
>
0
){
truths_dax
<-
truths_dax
[
order
(
truths_dax
$
date
),
]
truths_dax
$
target
<-
"DAX"
truths_dax
$
horizon
<-
c
(
"1 day"
,
"2 day"
,
"5 day"
,
"6 day"
,
"7 day"
)[
1
:
nrow
(
truths_dax
)]
truths_dax
$
date
<-
NULL
# add truth data:
dax_forecasts
<-
merge
(
dax_forecasts
,
truths_dax
,
by
=
c
(
"target"
,
"horizon"
),
all.x
=
TRUE
)
}
else
{
# if no truth data available: add NA values:
dax_forecasts
$
value
<-
NA
}
# add truths to wind forecasts:
truth_wind
<-
read.csv
(
"../ptsfc_viz/plot_data/wind.csv"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment