|
1 |
| -using ScoreDrivenModels, Plots |
2 |
| - |
3 |
| -# Convert data to vector |
4 |
| -y = Vector{Float64}(vec(readdlm("./test/data/ena_northeastern.csv")')) |
5 |
| -y_train = y[1:400] |
6 |
| -y_test = y[401:end] |
7 |
| - |
8 |
| -# Specify model: here we use lag 1 for trend characterization and lag 12 for seasonality characterization |
9 |
| -gas = Model([1, 2, 11, 12], [1, 2, 11, 12], LogNormal, 0.0; time_varying_params = [1]) |
10 |
| - |
11 |
| -# Define initial_params with |
12 |
| -initial_params = dynamic_initial_params(y_train, gas) |
13 |
| - |
14 |
| -# Estimate the model via MLE |
15 |
| -f = fit!(gas, y_train; initial_params = initial_params) |
16 |
| - |
17 |
| -# Compare observations and in-sample estimates |
18 |
| -plot(y_train, label = "In-sample ANE") |
19 |
| - |
20 |
| -# Forecasts with 95% confidence interval |
21 |
| -forecast = forecast_quantiles(y_train, gas, 60; S = 1_000, initial_params = initial_params) |
22 |
| - |
23 |
| -plot(forecast.scenarios, color = "grey", width = 0.05, label = "") |
24 |
| -plot!(y[360:460], label = "ANE", color = "black", xlabel = "Months", ylabel = "GWmed", legend = :topright) |
25 |
| -plot!(forecast.quantiles, label = ["Quantiles" "" ""], color = "red", line = :dash) |
26 |
| - |
| 1 | +using ScoreDrivenModels, Plots, DelimitedFiles, Dates, Random |
| 2 | + |
| 3 | +dates = collect(Date(1961):Month(1):Date(2000, 12)) |
| 4 | +Random.seed!(123); |
| 5 | +y = vec(readdlm("../test/data/ane_northeastern.csv")); |
| 6 | +y_train = y[1:400]; |
| 7 | +gas = Model([1, 2, 11, 12], [1, 2, 11, 12], LogNormal, 0.0; time_varying_params=[1]); |
| 8 | +initial_params = dynamic_initial_params(y_train, gas); |
| 9 | +f = ScoreDrivenModels.fit!(gas, y_train; initial_params=initial_params); |
| 10 | +estimation_stats = fit_stats(f) |
| 11 | + |
| 12 | +forec = ScoreDrivenModels.forecast(y_train, gas, 60; S=1_000, initial_params=initial_params) |
| 13 | + |
| 14 | +y_test = y[401:460] |
| 15 | +p2 = plot(dates[401:460], forec.observation_scenarios, color="grey", width=0.05, label="", ylims=(0, 70)) |
| 16 | +plot!(p2, dates[360:460], y[360:460], label="ANE", color="black", xlabel="Months", ylabel="GWmed", legend=:topright) |
| 17 | +plot!(p2, dates[401:460], forec.observation_quantiles, label=["Quantiles" "" ""], color="red", line=:dash) |
0 commit comments