Skip to content

Commit c02c0fb

Browse files
fix basic structural with exogenous variables simulation
1 parent bea472c commit c02c0fb

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StateSpaceModels"
22
uuid = "99342f36-827c-5390-97c9-d7f9ee765c78"
33
authors = ["raphaelsaavedra <[email protected]>, guilhermebodin <[email protected]>, mariohsouto"]
4-
version = "0.6.2"
4+
version = "0.6.3"
55

66
[deps]
77
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

src/models/basicstructural_explanatory.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,17 @@ function simulate(
196196
standard_ε = randn(n)
197197
standard_η = randn(n + 1, size(sys.Q[1], 1))
198198

199+
num_exogenous = size(model.exogenous, 2)
200+
@assert num_exogenous == size(new_exogenous, 2) "You must have the same number of exogenous variables of the model."
201+
199202
# The first state of the simulation is the update of a_0
200203
alpha[1, :] .= initial_state
201-
sys.Z[1][14:end] .= new_exogenous[1, :]
204+
sys.Z[1][end-num_exogenous+1:end] .= new_exogenous[1, :]
202205
y[1] = dot(sys.Z[1], initial_state) + sys.d[1] + chol_H * standard_ε[1]
203206
alpha[2, :] = sys.T[1] * initial_state + sys.c[1] + sys.R[1] * chol_Q.L * standard_η[1, :]
204207
# Simulate scenarios
205208
for t in 2:n
206-
sys.Z[t][14:end] .= new_exogenous[t, :]
209+
sys.Z[t][end-num_exogenous+1:end] .= new_exogenous[t, :]
207210
y[t] = dot(sys.Z[t], alpha[t, :]) + sys.d[t] + chol_H * standard_ε[t]
208211
alpha[t + 1, :] = sys.T[t] * alpha[t, :] + sys.c[t] + sys.R[t] * chol_Q.L * standard_η[t, :]
209212
end

test/models/basicstructural_explanatory.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
y = CSV.File(StateSpaceModels.AIR_PASSENGERS) |> DataFrame
44
logap = log.(y.passengers)
55
X = rand(length(logap), 2)
6-
model = BasicStructuralExplanatory(logap, 10, X)
7-
fit!(model)
8-
model.results
96
model = BasicStructuralExplanatory(logap, 12, X)
107
fit!(model)
11-
model.results
8+
model = BasicStructuralExplanatory(logap, 10, X)
9+
fit!(model)
1210
# forecasting
1311
# For a fixed forecasting explanatory the variance must not decrease
1412
forec = forecast(model, ones(10, 2))

0 commit comments

Comments
 (0)