I'm self-learning python and it teaches concept of "Class" from https://python-programming.quantecon.org/python_oop.html
The below is full codes. I can understand that
But my question is: anybody can explain what def steady_state() is? I can't find where this computing is originated from.
(((s * z) / (n + δ))**(1 / (1 - α))
Am I lacking of understanding this equation, or understanding how class and methods are interacting?
class Solow:
r"""
Implements the Solow growth model with the update rule
k_{t+1} = [(s z k^α_t) + (1 - δ)k_t] /(1 + n)
"""
def __init__(self, n=0.05, # population growth rate
s=0.25, # savings rate
δ=0.1, # depreciation rate
α=0.3, # share of labor
z=2.0, # productivity
k=1.0): # current capital stock
self.n, self.s, self.δ, self.α, self.z = n, s, δ, α, z
self.k = k
def h(self):
"Evaluate the h function"
# Unpack parameters (get rid of self to simplify notation)
n, s, δ, α, z = self.n, self.s, self.δ, self.α, self.z
# Apply the update rule
return (s * z * self.k**α + (1 - δ) * self.k) / (1 + n)
def update(self):
"Update the current state (i.e., the capital stock)."
self.k = self.h()
def steady_state(self):
"Compute the steady state value of capital."
# Unpack parameters (get rid of self to simplify notation)
n, s, δ, α, z = self.n, self.s, self.δ, self.α, self.z
# Compute and return steady state
return ((s * z) / (n + δ))**(1 / (1 - α))
def generate_sequence(self, t):
"Generate and return a time series of length t"
path = []
for i in range(t):
path.append(self.k)
self.update()
return path
The code provided may not be correct. You are missing an explanation of how the formula was derived. solow.steady_state() essentially solves for k when k_t=k_t+1.
In the provided formula, we set all these k and solve for k:
k = ( sz(k**a) + (1 - δ)k ) / (1 + n)
Swap k and (1 + n):
1+n = ( sz(k**a) + (1 - δ)k ) / k
Simplify expression on the right:
1+n = sz(k**a)/k + 1 - δ
Again:
1+n = sz(k**(a-1)) + 1 - δ
Cancel the ones and move δ:
n + δ= sz(k**(a-1))
Move sz over:
(n + δ) / sz = k**(a-1)
From here, remove the exponent:
((n + δ) / sz)**(1 / (1 - α)) = k
The expression in the code is essentially similar:
((sz) / (n + δ))**(1 / (1 - α) = k
I do not know why this code has the expressions flipped from how I solved it, but if it works, I assume there is some reason I am not see that reversing those two terms works. Perhaps it is computing 1/k instead of k directly, which would be the best explanation if it produces the desired results. Or the other possibility is the k always equals 1/k for some logical reason in this equation.