Skip to content

Commit

Permalink
migrate supporting py file from lecture-python-advanced
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcky committed May 1, 2024
1 parent 0492174 commit 97cfbf4
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ def simulate(self, b0, s0, T, sHist=None):
# Time 1 onward
for t in range(1, T):
s, x = sHist[t], xHist[t-1]
cHist[t] = interp(self.x_grid, self.c1[:, s], x)
nHist[t] = interp(self.x_grid, self.n1[:, s], x)
cHist[t] = np.interp(x, self.x_grid, self.c1[:, s])
nHist[t] = np.interp(x, self.x_grid, self.n1[:, s])

τHist[t] = self.τ(cHist[t], nHist[t])

Bhist[t] = x / Uc(cHist[t], 1-nHist[t])

c, n = np.empty((2, self.S))
for sprime in range(self.S):
c[sprime] = interp(x_grid, self.c1[:, sprime], x)
n[sprime] = interp(x_grid, self.n1[:, sprime], x)
c[sprime] = np.interp(x, x_grid, self.c1[:, sprime])
n[sprime] = np.interp(x, x_grid, self.n1[:, sprime])
Euc = π[sHist[t-1]] @ Uc(c, 1-n)
RHist[t-1] = Uc(cHist[t-1], 1-nHist[t-1]) / (self.pref.β * Euc)

Expand All @@ -150,7 +150,7 @@ def simulate(self, b0, s0, T, sHist=None):

if t < T-1:
sprime = sHist[t+1]
xHist[t] = interp(self.x_grid, self.xprime1[:, s, sprime], x)
xHist[t] = np.interp(x, self.x_grid, self.xprime1[:, s, sprime])

return [cHist, nHist, Bhist, τHist, gHist, yHist, xHist, RHist]

Expand Down Expand Up @@ -209,7 +209,7 @@ def obj_V(z_sub, x, s, V, pref, π, g, x_grid, b0=None):
# prepare Vprime vector
Vprime = np.empty(S)
for sprime in range(S):
Vprime[sprime] = interp(x_grid, V[:, sprime], xprime[sprime])
Vprime[sprime] = np.interp(xprime[sprime], x_grid, V[:, sprime])

# compute the objective value
obj = U(c, l) + β * π[s] @ Vprime
Expand Down

0 comments on commit 97cfbf4

Please sign in to comment.