-
-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Description
While working in the Julia version of the lectures (they're awesome, by the way) in this chapter: https://lectures.quantecon.org/jl/types_methods.html I noticed that the solution of the exercise seems to be incomplete. While the definition of AR(1) includes the use of sigma, the implemented version doesn't:
using Distributions
struct AR1_ex1{T <: Real}
a::T
b::T
sigma::T
phi::Distribution
end
function simulate(m::AR1_ex1, n::Integer, x0::Real)
X = Array{Float64}(n)
X[1] = x0
for t in 1:(n-1)
X[t+1] = m.a * X[t] + m.b + rand(m.phi)
end
return X
endBecause the test is made using sigma=1, this isn't immediately obvious when looking at the output.
My solution:
struct AR1{T <: Real}
a::T
b::T
σ::T
ϕ::Distribution
end
function simulate(m::AR1, n::Integer, x0::Real)
X = Array{Float64}(n)
X[1] = x0
for t in 1:(n-1)
X[t+1] = m.a * X[t] + m.b + m.σ * rand(m.ϕ)
end
return X
endLet me know if I misunderstood the exercise!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels