1
- struct Backtest {Fl <: AbstractFloat }
1
+ struct CrossValidation {Fl <: AbstractFloat }
2
2
abs_errors:: Matrix{Fl}
3
3
mae:: Vector{Fl}
4
4
crps_scores:: Matrix{Fl}
5
5
mean_crps:: Vector{Fl}
6
- function Backtest {Fl} (n:: Int , steps_ahead:: Int ) where Fl
6
+ function CrossValidation {Fl} (n:: Int , steps_ahead:: Int ) where Fl
7
7
abs_errors = Matrix {Fl} (undef, steps_ahead, n)
8
8
crps_scores = Matrix {Fl} (undef, steps_ahead, n)
9
9
mae = Vector {Fl} (undef, steps_ahead)
@@ -34,27 +34,27 @@ function evaluate_crps(y::Vector{Fl}, scenarios::Matrix{Fl}) where {Fl}
34
34
end
35
35
36
36
"""
37
- backtest (model::StateSpaceModel, steps_ahead::Int, start_idx::Int;
37
+ cross_validation (model::StateSpaceModel, steps_ahead::Int, start_idx::Int;
38
38
n_scenarios::Int = 10_000,
39
39
filter::KalmanFilter=default_filter(model),
40
40
optimizer::Optimizer=default_optimizer(model)) where Fl
41
41
42
42
Makes rolling window estimating and forecasting to benchmark the forecasting skill of the model
43
43
in for different time periods and different lead times. The function returns a struct with the MAE
44
- and mean CRPS per lead time. See more on [Backtest the forecasts of a model](@ref)
44
+ and mean CRPS per lead time. See more on [CrossValidation the forecasts of a model](@ref)
45
45
46
46
# References
47
47
* DTU course "31761 - Renewables in electricity markets" available on youtube https://www.youtube.com/watch?v=Ffo8XilZAZw&t=556s
48
48
"""
49
- function backtest (model:: StateSpaceModel , steps_ahead:: Int , start_idx:: Int ;
49
+ function cross_validation (model:: StateSpaceModel , steps_ahead:: Int , start_idx:: Int ;
50
50
n_scenarios:: Int = 10_000 ,
51
51
filter:: KalmanFilter = default_filter (model),
52
52
optimizer:: Optimizer = default_optimizer (model))
53
53
Fl = typeof_model_elements (model)
54
54
num_mle = length (model. system. y) - start_idx - steps_ahead
55
- b = Backtest {Fl} (num_mle, steps_ahead)
55
+ cv = CrossValidation {Fl} (num_mle, steps_ahead)
56
56
for i in 1 : num_mle
57
- println (" Backtest : step $i of $num_mle " )
57
+ println (" CrossValidation : step $i of $num_mle " )
58
58
y_to_fit = model. system. y[1 : start_idx - 1 + i]
59
59
y_to_verify = model. system. y[start_idx + i: start_idx - 1 + i + steps_ahead]
60
60
model_to_fit = reinstantiate (model, y_to_fit)
@@ -64,12 +64,12 @@ function backtest(model::StateSpaceModel, steps_ahead::Int, start_idx::Int;
64
64
expected_value_vector = forecast_expected_value (forec)[:]
65
65
abs_errors = evaluate_abs_error (y_to_verify, expected_value_vector)
66
66
crps_scores = evaluate_crps (y_to_verify, scenarios[:, 1 , :])
67
- b . abs_errors[:, i] = abs_errors
68
- b . crps_scores[:, i] = crps_scores
67
+ cv . abs_errors[:, i] = abs_errors
68
+ cv . crps_scores[:, i] = crps_scores
69
69
end
70
70
for i in 1 : steps_ahead
71
- b . mae[i] = mean (b . abs_errors[i, :])
72
- b . mean_crps[i] = mean (b . crps_scores[i, :])
71
+ cv . mae[i] = mean (cv . abs_errors[i, :])
72
+ cv . mean_crps[i] = mean (cv . crps_scores[i, :])
73
73
end
74
- return b
74
+ return cv
75
75
end
0 commit comments