@@ -2,11 +2,15 @@ export backtest
2
2
3
3
struct Backtest
4
4
abs_errors:: Matrix{Float64}
5
+ mae:: Vector{Float64}
5
6
crps_scores:: Matrix{Float64}
7
+ mean_crps:: Vector{Float64}
6
8
function Backtest (n:: Int , steps_ahead:: Int )
7
- abs_errors = Matrix {Float64} (undef, n, steps_ahead)
8
- crps_scores = Matrix {Float64} (undef, n, steps_ahead)
9
- return new (abs_errors, crps_scores)
9
+ abs_errors = Matrix {Float64} (undef, steps_ahead, n)
10
+ crps_scores = Matrix {Float64} (undef, steps_ahead, n)
11
+ mae = Vector {Float64} (undef, steps_ahead)
12
+ mean_crps = Vector {Float64} (undef, steps_ahead)
13
+ return new (abs_errors, mae, crps_scores, mean_crps)
10
14
end
11
15
end
12
16
36
40
"""
37
41
function backtest (gas:: Model{<:Distribution, T} , y:: Vector{T} , steps_ahead:: Int , start_idx:: Int ;
38
42
S:: Int = 10_000 ,
39
- initial_params = stationary_initial_params (gas),
40
- opt_method = NelderMead (gas, 3 )) where T
43
+ initial_params:: Matrix{T} = stationary_initial_params (gas),
44
+ opt_method = NelderMead (gas, DEFAULT_NUM_SEEDS )) where T
41
45
num_mle = length (y) - start_idx - steps_ahead
42
46
b = Backtest (num_mle, steps_ahead)
43
47
for i in 1 : num_mle
@@ -49,8 +53,12 @@ function backtest(gas::Model{<:Distribution, T}, y::Vector{T}, steps_ahead::Int,
49
53
forec = forecast (y_to_fit, gas_to_fit, steps_ahead; S= S, initial_params= initial_params)
50
54
abs_errors = evaluate_abs_error (y_to_verify, forec. observation_forecast)
51
55
crps_scores = evaluate_crps (y_to_verify, forec. observation_scenarios)
52
- b. abs_errors[i, :] = abs_errors
53
- b. crps_scores[i, :] = crps_scores
56
+ b. abs_errors[:, i] = abs_errors
57
+ b. crps_scores[:, i] = crps_scores
58
+ end
59
+ for i in 1 : steps_ahead
60
+ b. mae[i] = mean (b. abs_errors[i, :])
61
+ b. mean_crps[i] = mean (b. crps_scores[i, :])
54
62
end
55
63
return b
56
64
end
0 commit comments