Skip to content

Instantly share code, notes, and snippets.

@pkofod
Created September 15, 2017 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkofod/10e31b7cf341083453e106ce382ef9af to your computer and use it in GitHub Desktop.
Save pkofod/10e31b7cf341083453e106ce382ef9af to your computer and use it in GitHub Desktop.
tauchen
function tauchen(ρ, σₛ, m, N)
const Φ = normcdf # CDF of standard normal
s̃₁, s̃ₙ = -m*σₛ, m*σₛ # end points
s̃ = linspace(s̃₁, s̃ₙ, N) # grid
w = (s̃[2]-s̃[1])/2 # half distance between grid points
F = zeros(N, N) # empty transition matrix
F[:, 1] = Φ.((s̃[1]-ρ.*s̃+w)/sqrt(σₛ))
F[:, N] = 1-Φ.((s̃[end]-ρ.*s̃-w)/sqrt(σₛ))
for j = 2:N-1
for i = 1:N
F[i, j] = Φ.((s̃[j]-ρ*s̃[i]+w)/sqrt(σₛ))-Φ.((s̃[j]-ρ*s̃[i]-w)/sqrt(σₛ))
end
end
F
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment