Skip to content

Commit 9940034

Browse files
committed
Ensure stationary initialization for UnrestrictedStationaryIdentified model
1 parent 4b5e6a4 commit 9940034

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/fit/utilities.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,19 @@ function init!(F::UnrestrictedStationaryIdentified, method::Symbol, y::AbstractM
9292

9393
# factor dynamics
9494
for (r, f) in pairs(eachrow(factors(F)))
95-
ϕi = dot(f[1:(end - 1)], f[2:end]) / sum(abs2, f[1:(end - 1)])
96-
dynamics(F).diag[r] = max(-0.99, min(0.99, ϕi))
95+
# objective function
96+
function objective(x)
97+
obj = zero(eltype(x))
98+
for t in 2:nobs(model)
99+
obj += (f[t] - x * f[t - 1])^2
100+
end
101+
102+
return obj
103+
end
104+
105+
# optimize
106+
res = optimize(objective, -1.0, 1.0)
107+
dynamics(F).diag[r] = Optim.minimizer(res)
97108
end
98109
end
99110

0 commit comments

Comments
 (0)