-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from floswald/main
testing euler equation
- Loading branch information
Showing
3 changed files
with
60 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
using Test | ||
using SSJ | ||
|
||
@testset "SSJ.jl tests" begin | ||
@test 1 == 1 | ||
|
||
@testset "all run" begin | ||
# not a real test, but breaks if breaks. | ||
main(); | ||
mainKS(); | ||
mainSSJ(); | ||
end | ||
end | ||
using TestItemRunner | ||
|
||
@run_package_tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
@testitem "Euler Error" begin | ||
|
||
# defining the parameters of the model | ||
rho = 0.966 | ||
s = 0.5 | ||
sig = s * sqrt(1 - rho^2) | ||
params = SSJ.Params(0.96, 1.0, sig, rho, 0.025, 0.11, 0.0001, [0.0, 200.0], 200, 7, 300) | ||
|
||
# set an r | ||
r = 0.04 | ||
|
||
# Setting up the model | ||
BaseModel = SSJ.setup_Aiyagari(params) | ||
|
||
agg_labor = SSJ.aggregate_labor(BaseModel.Π, BaseModel.shockgrid) | ||
aggregates, prices = SSJ.get_AggsPrices(r, agg_labor, BaseModel) | ||
policies = SSJ.EGM(BaseModel, prices) | ||
|
||
# now test that `policies` are consistent | ||
|
||
μ = zeros(params.n_a) # vector of marginal utilities | ||
iuprime = zeros(params.n_a,params.n_e) # matrix of inverse marginal utilities | ||
|
||
# basically does `consumptiongrid` | ||
for ie in 1:params.n_e | ||
fill!(μ , 0.0) | ||
for je in 1:params.n_e | ||
pr = BaseModel.Π[ie,je] # transprob | ||
|
||
# get next period consumption if state is je | ||
# cprime = (1+r) policygrid + w * shock[je] - policy[je] | ||
# (params.n_a by 1) | ||
cprimevec = ((1 + prices.r) * BaseModel.policygrid) .+ (prices.w .* BaseModel.shockgrid[je]) .- policies.saving[:,je] | ||
|
||
# Expected marginal utility at each state of tomorrow's income shock | ||
global μ += pr * (cprimevec .^ ((-1) * params.γ)) | ||
end | ||
# RHS of euler equation | ||
rhs = params.β * (1 + prices.r) * μ | ||
# today's consumption: inverse marginal utility over RHS | ||
iuprime[:,ie] = rhs .^ ((-1)/params.γ) | ||
end | ||
|
||
savings = SSJ.policyupdate(prices,BaseModel.policymat,BaseModel.shockmat,iuprime) | ||
cons = ((1 + prices.r) * BaseModel.policymat) + (prices.w * BaseModel.shockmat) - savings | ||
|
||
# checks reverse engineering of `consumptiongrid` | ||
@test maximum(abs,(cons ./ policies.consumption) .- 1) < 0.00001 | ||
end |