Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions scripts/tests/test_SS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import numpy as np
import demographics
import SS


def test_get_pop_objs():
"""
Test of the that omega_SS and the last period of omega_path_S are
close to each other.
"""
E = 20
S = 80
T = int(round(4.0 * S))
start_year = 2018

(omega, g_n_ss, omega_SS, surv_rate, rho, g_n_vector, imm_rates,
omega_S_preTP) = demographics.get_pop_objs(E, S, T, 1, 100,
start_year, False)
return omega_SS,imm_rates

omega_SS,imm_rates = test_get_pop_objs()

def test_SS():
"""
Test whether the SS funtion works well and what the returns look like
"""
r_init = 0.1
beta = 0.8
sigma = 1.5
alpha = 0.3
A = 1.0
delta = 0.1
xi = 0.1
S = 80
Copy link
Copy Markdown
Contributor

@saharnazb saharnazb Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend thinking of 3 periods as we did in class so you can compare the results with SS in that

For 3 periods:
'SS interest rate is ', 1.0036834614021983

The only problem that I can think of is the exogenous labor in that model. I am trying to figure out a solution for that.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right - the answer will be different with exogenous labor.

Maybe you could have your scripts (e.g., SS.py) raise an assertion if the SS is not obtained before the maximum iterations are reached. In that way, this test will fail if the SS isn't found and pass if it is.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdebacker Yes. OK. Milton n I are working on that

imm_rates_SS = imm_rates

(r,w,b_sp1,euler_errors) = SS.solve_ss(r_init,params=(beta, sigma, alpha,
A, delta, xi, omega_SS,
imm_rates_SS, S))
print("r = ",r)
print("w = ",w)
print("b_sp1 = ",b_sp1)
print("euler_errors = ",euler_errors)
Comment on lines +40 to +43
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need to print

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. The print was only for checking whether SS works in terms of executability. I would like to use the expected_r in Table 8.2 of Chapter 8 and add the assert statement. But I am still struggling on other parts. For example, there is a valueError issue in SS to apply HH module.


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test will run correctly. I believe it needs an assert statement that will raise an error if the assertion doesn't hold.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtregde Thanks for the comment. Yes, I should have to make the assert statement inside the function. The problem is I don't know what I can compare at this point. I will continue to think of it.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JLian401 You could solve the SS in the case that you know the answer of (either by finding it analytically (could be hard!) or by using the solution from a version fo the code you trust - then then you could have an assert statement like:

expected_r = r_ss found in previous run/analytical solution 
test_r,w,b_sp1,euler_errors = SS.solve_ss(r_init,params=(beta, sigma, alpha,
                                                           A, delta, xi, omega_SS,
                                                           imm_rates_SS, S))
assert np.allclose(test_r, expected_r)

test_SS()