Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add stable points for PortfolioConsumerType #1259

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
add stable points for PortfolioConsumerType
  • Loading branch information
alanlujan91 committed Apr 20, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
commit 24881329c66d849fe03ea495e966e1b5b21e5601
34 changes: 30 additions & 4 deletions HARK/ConsumptionSaving/ConsPortfolioModel.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@

from HARK import AgentType, NullFunc, make_one_period_oo_solver
from HARK.ConsumptionSaving.ConsIndShockModel import (
ConsIndShockSolver,
IndShockConsumerType,
init_idiosyncratic_shocks,
utility,
@@ -238,6 +239,11 @@ def update_solution_terminal(self):
dvdsFuncFxd=dvdsFuncFxd_terminal,
)

self.solution_terminal.mNrmMin = 0.0
self.solution_terminal.hNrm = 0.0
self.solution_terminal.MPCmin = 1.0
self.solution_terminal.MPCmax = 1.0

def initialize_sim(self):
"""
Initialize the state of simulation attributes. Simply calls the same method
@@ -330,7 +336,7 @@ def __init__(self, verbose=False, quiet=False, **kwds):
self.solve_one_period = make_one_period_oo_solver(ConsSequentialPortfolioSolver)


class ConsPortfolioSolver(MetricObject):
class ConsPortfolioSolver(ConsIndShockSolver):
"""
Define an object-oriented one period solver.
Solve the one period problem for a portfolio-choice consumer.
@@ -433,6 +439,8 @@ def __init__(
self.ShareLimit = ShareLimit
self.IndepDstnBool = IndepDstnBool

self.CubicBool = False # This solver doesn't use cubic interpolation

# Make sure the individual is liquidity constrained. Allowing a consumer to
# borrow *and* invest in an asset with unbounded (negative) returns is a bad mix.
if BoroCnstArt != 0.0:
@@ -447,6 +455,9 @@ def __init__(

self.def_utility_funcs()

self.solution_next.vFunc = self.solution_next.vFuncAdj # this is a hack
self.solution_next.vPfunc = self.solution_next.vPfuncAdj # this is a hack

def def_utility_funcs(self):
"""
Define temporary functions for utility and its derivative and inverse
@@ -458,12 +469,16 @@ def def_utility_funcs(self):
self.uinv = lambda x: utility_inv(x, self.CRRA)
self.uinvP = lambda x: utility_invP(x, self.CRRA)

def set_and_update_values(self):
def set_and_update_values(self, solution_next, IncShkDstn, LivPrb, DiscFac):
"""
Unpacks some of the inputs (and calculates simple objects based on them),
storing the results in self for use by other methods.
"""

super().set_and_update_values(
self.solution_next, self.IncShkDstn, self.LivPrb, self.DiscFac
)

# Unpack next period's solution
self.vPfuncAdj_next = self.solution_next.vPfuncAdj
self.dvdmFuncFxd_next = self.solution_next.dvdmFuncFxd
@@ -482,7 +497,10 @@ def prepare_to_solve(self):
Perform preparatory work.
"""

self.set_and_update_values()
self.set_and_update_values(
self.solution_next, self.IncShkDstn, self.LivPrb, self.DiscFac
)
self.def_BoroCnst(self.BoroCnstArt)

def prepare_to_calc_EndOfPrdvP(self):
"""
@@ -925,6 +943,10 @@ def solve(self):

self.make_porfolio_solution()

self.solution = self.add_MPC_and_human_wealth(self.solution)
self.solution.mNrmMin = self.mNrmMinNow
self.solution = self.add_stable_points(self.solution)

return self.solution


@@ -1007,12 +1029,16 @@ class ConsPortfolioJointDistSolver(ConsPortfolioDiscreteSolver, ConsPortfolioSol
discrete.
"""

def set_and_update_values(self):
def set_and_update_values(self, solution_next, IncShkDstn, LivPrb, DiscFac):
"""
Unpacks some of the inputs (and calculates simple objects based on them),
storing the results in self for use by other methods.
"""

super().set_and_update_values(
self.solution_next, self.IncShkDstn, self.LivPrb, self.DiscFac
)

# Unpack next period's solution
self.vPfuncAdj_next = self.solution_next.vPfuncAdj
self.dvdmFuncFxd_next = self.solution_next.dvdmFuncFxd
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsRiskyAssetModel.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
from scipy.optimize import minimize_scalar, root_scalar

from HARK import make_one_period_oo_solver
from HARK.ConsumptionSaving.ConsIndShockModel import ( # PortfolioConsumerType inherits from it; Baseline dictionary to build on
from HARK.ConsumptionSaving.ConsIndShockModel import (
ConsIndShockSolver,
ConsumerSolution,
IndShockConsumerType,