diff --git a/src/QuantEcon.jl b/src/QuantEcon.jl index 350215eb..77749da8 100644 --- a/src/QuantEcon.jl +++ b/src/QuantEcon.jl @@ -51,7 +51,7 @@ export simulate, simulate!, simulate_indices, simulate_indices!, period, is_irreducible, is_aperiodic, recurrent_classes, communication_classes, n_states, - discrete_var, Even, + discrete_var, Even, Quantile, # modeltools AbstractUtility, LogUtility, CRRAUtility, CFEUtility, EllipticalUtility, derivative, diff --git a/src/markov/markov_approx.jl b/src/markov/markov_approx.jl index 96ea4927..17b616a5 100644 --- a/src/markov/markov_approx.jl +++ b/src/markov/markov_approx.jl @@ -13,7 +13,7 @@ https://lectures.quantecon.org/jl/finite_markov.html import Optim import NLopt -import Distributions: pdf, Normal +import Distributions: pdf, Normal, quantile std_norm_cdf(x::T) where {T <: Real} = 0.5 * erfc(-x/sqrt(2)) std_norm_cdf(x::Array{T}) where {T <: Real} = 0.5 .* erfc(-x./sqrt(2)) @@ -231,7 +231,7 @@ types specifying the method for `discrete_var` """ abstract type VAREstimationMethod end struct Even <: VAREstimationMethod end -# immutable type Quantile <: VAREstimationMethod end +struct Quantile <: VAREstimationMethod end # immutable type Quadrature <: VAREstimationMethod end doc""" @@ -263,10 +263,9 @@ P, X = discrete_var(b, B, Psi, Nm, n_moments, method, n_sigmas) - `n_moments::Integer` : Desired number of moments to match. The default is 2. - `method::VAREstimationMethod` : Specify the method used to determine the grid - points. Accepted inputs are `Even()`. + points. Accepted inputs are `Even()` or `Quantile()`. Please see the paper for more details. - NOTE: `Quantile()` and `Quadrature()` are - not supported now. + NOTE: `Quadrature()` is not supported now. - `n_sigmas::Real` : If the `Even()` option is specified, `n_sigmas` is used to determine the number of unconditional standard deviations used to set the endpoints of the grid. The default is @@ -334,7 +333,7 @@ function discrete_var(b::Union{Real, AbstractVector}, A, C, mu, Sigma = standardize_var(b, B, Psi, M) # Construct 1-D grids - y1D = construct_1D_grid(Sigma, Nm, M, n_sigmas, method) + y1D, y1Dbounds = construct_1D_grid(Sigma, Nm, M, n_sigmas, method) # Construct all possible combinations of elements of the 1-D grids D = allcomb3(y1D')' @@ -356,7 +355,7 @@ function discrete_var(b::Union{Real, AbstractVector}, for ii = 1:(Nm^M) # Construct prior guesses for maximum entropy optimizations - q = construct_prior_guess(cond_mean[:, ii], Nm, y1D, method) + q = construct_prior_guess(cond_mean[:, ii], Nm, y1D, y1Dbounds, method) # Make sure all elements of the prior are stricly positive q[q.