I happened to notice that the Julia implementation of CRRA utility type is calculating a different value than what the docstring says. There is an extra -1.0
in the numerator that seems to be unnecessary to me. Is this intentionally written like this or a bug?
Here is the code that I am talking about in QuantEcon.jl/src/modeltools/utility.jl:
"""
Type used to evaluate CRRA utility. CRRA utility takes the form
u(c) = ξ c^(1 - γ) / (1 - γ)
Additionally, this code assumes that if c < 1e-10 then
u(c) = ξ (1e-10^(1 - γ) / (1 - γ) + 1e-10^(-γ) * (c - 1e-10))
"""
struct CRRAUtility <: AbstractUtility
γ::Float64
ξ::Float64
function CRRAUtility(γ, ξ=1.0)
if abs(γ - 1.0) < 1e-8
error("Your value for γ is very close to 1... Consider using LogUtility")
end
return new(γ, ξ)
end
end
(u::CRRAUtility)(c::Float64) =
c > 1e-10 ?
u.ξ * (c^(1.0 - u.γ) - 1.0) / (1.0 - u.γ) :
u.ξ * ((1e-10^(1.0 - u.γ) - 1.0) / (1.0 - u.γ) + 1e-10^(-u.γ)*(c - 1e-10))
derivative(u::CRRAUtility, c::Float64) =
c > 1e-10 ? u.ξ * c^(-u.γ) : u.ξ*1e-10^(-u.γ)