Skip to content

Commit

Permalink
Run black on ConsPortfolioModel.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mnwhite committed Mar 8, 2024
1 parent 45d645c commit d9cda03
Showing 1 changed file with 86 additions and 76 deletions.
162 changes: 86 additions & 76 deletions HARK/ConsumptionSaving/ConsPortfolioModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
agents who must allocate their resources among consumption, saving in a risk-free
asset (with a low return), and saving in a risky asset (with higher average return).
"""

from copy import deepcopy

import numpy as np
Expand Down Expand Up @@ -182,7 +183,7 @@ def __init__(self, verbose=False, quiet=False, **kwds):
else:
solver = ConsPortfolioJointDistSolver
self.solve_one_period = make_one_period_oo_solver(solver)
#self.solve_one_period = solve_one_period_ConsPortfolio
# self.solve_one_period = solve_one_period_ConsPortfolio

self.update()

Expand Down Expand Up @@ -331,25 +332,27 @@ def __init__(self, verbose=False, quiet=False, **kwds):

# Set the solver for the portfolio model, and update various constructed attributes
self.solve_one_period = make_one_period_oo_solver(ConsSequentialPortfolioSolver)


def solve_one_period_ConsPortfolio( solution_next,
ShockDstn,
IncShkDstn,
RiskyDstn,
LivPrb,
DiscFac,
CRRA,
Rfree,
PermGroFac,
BoroCnstArt,
aXtraGrid,
ShareGrid,
AdjustPrb,
ShareLimit,
vFuncBool,
DiscreteShareBool,
IndepDstnBool,):


def solve_one_period_ConsPortfolio(
solution_next,
ShockDstn,
IncShkDstn,
RiskyDstn,
LivPrb,
DiscFac,
CRRA,
Rfree,
PermGroFac,
BoroCnstArt,
aXtraGrid,
ShareGrid,
AdjustPrb,
ShareLimit,
vFuncBool,
DiscreteShareBool,
IndepDstnBool,
):
"""
Solve one period of a consumption-saving problem with portfolio allocation
between a riskless and risky asset. This function handles various sub-cases
Expand Down Expand Up @@ -427,22 +430,22 @@ def solve_one_period_ConsPortfolio( solution_next,
raise ValueError(

Check warning on line 430 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L429-L430

Added lines #L429 - L430 were not covered by tests
"PortfolioConsumerType requires vFuncBool to be True when DiscreteShareBool is True!"
)

# Define the current period utility function and effective discount factor
uFunc = UtilityFuncCRRA(CRRA)
DiscFacEff = DiscFac * LivPrb # "effective" discount factor

Check warning on line 436 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L435-L436

Added lines #L435 - L436 were not covered by tests

# Unpack next period's solution for easier access
vPfuncAdj_next = solution_next.vPfuncAdj
dvdmFuncFxd_next = solution_next.dvdmFuncFxd
dvdsFuncFxd_next = solution_next.dvdsFuncFxd
vFuncAdj_next = solution_next.vFuncAdj
vFuncFxd_next = solution_next.vFuncFxd

Check warning on line 443 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L439-L443

Added lines #L439 - L443 were not covered by tests

# Set a flag for whether the natural borrowing constraint is zero, which
# depends on whether the smallest transitory income shock is zero
BoroCnstNat_iszero = np.min(IncShkDstn.atoms[1]) == 0.0
BoroCnstNat_iszero = np.min(IncShkDstn.atoms[1]) == 0.0

Check warning on line 447 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L447

Added line #L447 was not covered by tests

# Prepare to calculate end-of-period marginal values by creating an array
# of market resources that the agent could have next period, considering
# the grid of end-of-period assets and the distribution of shocks he might
Expand All @@ -469,15 +472,15 @@ def solve_one_period_ConsPortfolio( solution_next,

# Make tiled arrays to calculate future realizations of mNrm and Share when integrating over IncShkDstn
bNrmNext, ShareNext = np.meshgrid(bNrmGrid, ShareGrid, indexing="ij")

Check warning on line 474 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L474

Added line #L474 was not covered by tests

# Define functions that are used internally to evaluate future realizations
def calc_mNrm_next(S, b):

Check warning on line 477 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L477

Added line #L477 was not covered by tests
"""
Calculate future realizations of market resources mNrm from the income
shock distribution S and normalized bank balances b.
"""
return b / (S["PermShk"] * PermGroFac) + S["TranShk"]

Check warning on line 482 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L482

Added line #L482 was not covered by tests

def calc_dvdm_next(S, b, z):

Check warning on line 484 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L484

Added line #L484 was not covered by tests
"""
Evaluate realizations of marginal value of market resources next period,
Expand All @@ -486,7 +489,7 @@ def calc_dvdm_next(S, b, z):
"""
mNrm_next = calc_mNrm_next(S, b)
dvdmAdj_next = vPfuncAdj_next(mNrm_next)

Check warning on line 491 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L490-L491

Added lines #L490 - L491 were not covered by tests

if AdjustPrb < 1.0:

Check warning on line 493 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L493

Added line #L493 was not covered by tests
# Expand to the same dimensions as mNrm
Share_next_expanded = z + np.zeros_like(mNrm_next)
Expand All @@ -495,7 +498,7 @@ def calc_dvdm_next(S, b, z):
dvdm_next = AdjustPrb * dvdmAdj_next + (1.0 - AdjustPrb) * dvdmFxd_next

Check warning on line 498 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L498

Added line #L498 was not covered by tests
else: # Don't bother evaluating if there's no chance that portfolio share is fixed
dvdm_next = dvdmAdj_next

Check warning on line 500 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L500

Added line #L500 was not covered by tests

dvdm_next = (S["PermShk"] * PermGroFac) ** (-CRRA) * dvdm_next
return dvdm_next

Check warning on line 503 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L502-L503

Added lines #L502 - L503 were not covered by tests

Expand All @@ -506,10 +509,10 @@ def calc_dvds_next(S, b, z):
the risky share z.
"""
mNrm_next = calc_mNrm_next(S, b)

Check warning on line 511 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L511

Added line #L511 was not covered by tests

# No marginal value of Share if it's a free choice!
dvdsAdj_next = np.zeros_like(mNrm_next)

Check warning on line 514 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L514

Added line #L514 was not covered by tests

if AdjustPrb < 1.0:

Check warning on line 516 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L516

Added line #L516 was not covered by tests
# Expand to the same dimensions as mNrm
Share_next_expanded = z + np.zeros_like(mNrm_next)
Expand All @@ -518,10 +521,10 @@ def calc_dvds_next(S, b, z):
dvds_next = AdjustPrb * dvdsAdj_next + (1.0 - AdjustPrb) * dvdsFxd_next

Check warning on line 521 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L521

Added line #L521 was not covered by tests
else: # Don't bother evaluating if there's no chance that portfolio share is fixed
dvds_next = dvdsAdj_next

Check warning on line 523 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L523

Added line #L523 was not covered by tests

dvds_next = (S["PermShk"] * PermGroFac) ** (1.0 - CRRA) * dvds_next
return dvds_next

Check warning on line 526 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L525-L526

Added lines #L525 - L526 were not covered by tests

# Calculate end-of-period marginal value of assets and shares at each point
# in aNrm and ShareGrid. Does so by taking expectation of next period marginal
# values across income and risky return shocks.
Expand All @@ -538,51 +541,57 @@ def calc_dvds_next(S, b, z):

# Make tiled arrays to calculate future realizations of bNrm and Share when integrating over RiskyDstn
aNrmNow, ShareNext = np.meshgrid(aNrmGrid, ShareGrid, indexing="ij")

Check warning on line 543 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L543

Added line #L543 was not covered by tests

# Define functions for calculating end-of-period marginal value
def calc_EndOfPrd_dvda(S, a, z):

Check warning on line 546 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L546

Added line #L546 was not covered by tests
'''
"""
Compute end-of-period marginal value of assets at values a, conditional
on risky asset return S and risky share z.
'''
"""
# Calculate future realizations of bank balances bNrm
Rxs = S - Rfree # Excess returns
Rport = Rfree + z * Rxs # Portfolio return
bNrm_next = Rport * a

Check warning on line 554 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L552-L554

Added lines #L552 - L554 were not covered by tests

# Ensure shape concordance
z_rep = z + np.zeros_like(bNrm_next)

Check warning on line 557 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L557

Added line #L557 was not covered by tests

# Calculate and return dvda
EndOfPrd_dvda = Rport * dvdbFunc_intermed(bNrm_next, z_rep)
return EndOfPrd_dvda

Check warning on line 561 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L560-L561

Added lines #L560 - L561 were not covered by tests

def EndOfPrddvds_dist(S, a, z):

Check warning on line 563 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L563

Added line #L563 was not covered by tests
'''
"""
Compute end-of-period marginal value of risky share at values a, conditional
on risky asset return S and risky share z.
'''
"""
# Calculate future realizations of bank balances bNrm
Rxs = S - Rfree # Excess returns
Rport = Rfree + z * Rxs # Portfolio return
bNrm_next = Rport * a

Check warning on line 571 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L569-L571

Added lines #L569 - L571 were not covered by tests

# Make the shares match the dimension of b, so that it can be vectorized
z_rep = z + np.zeros_like(bNrm_next)

Check warning on line 574 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L574

Added line #L574 was not covered by tests

# Calculate and return dvds
EndOfPrd_dvds = Rxs * a * dvdbFunc_intermed(bNrm_next, z_rep) + dvdsFunc_intermed(bNrm_next, z_rep)
EndOfPrd_dvds = Rxs * a * dvdbFunc_intermed(

Check warning on line 577 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L577

Added line #L577 was not covered by tests
bNrm_next, z_rep
) + dvdsFunc_intermed(bNrm_next, z_rep)
return EndOfPrd_dvds

Check warning on line 580 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L580

Added line #L580 was not covered by tests

# Evaluate realizations of value and marginal value after asset returns are realized

# Calculate end-of-period marginal value of assets by taking expectations
EndOfPrd_dvda = DiscFacEff * expected(calc_EndOfPrd_dvda, RiskyDstn, args=(aNrmNow, ShareNext))
EndOfPrd_dvda = DiscFacEff * expected(

Check warning on line 585 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L585

Added line #L585 was not covered by tests
calc_EndOfPrd_dvda, RiskyDstn, args=(aNrmNow, ShareNext)
)
EndOfPrd_dvdaNvrs = uFunc.derinv(EndOfPrd_dvda)

Check warning on line 588 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L588

Added line #L588 was not covered by tests

# Calculate end-of-period marginal value of risky portfolio share by taking expectations
EndOfPrd_dvds = DiscFacEff * expected(EndOfPrddvds_dist, RiskyDstn, args=(aNrmNow, ShareNext))

EndOfPrd_dvds = DiscFacEff * expected(

Check warning on line 591 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L591

Added line #L591 was not covered by tests
EndOfPrddvds_dist, RiskyDstn, args=(aNrmNow, ShareNext)
)

# Now find the optimal (continuous) risky share on [0,1] by solving the first
# order condition EndOfPrd_dvds == 0.
FOC_s = EndOfPrd_dvds # Relabel for convenient typing

Check warning on line 597 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L597

Added line #L597 was not covered by tests
Expand All @@ -592,7 +601,7 @@ def EndOfPrddvds_dist(S, a, z):
share_idx = np.argmax(crossing, axis=1)

Check warning on line 601 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L600-L601

Added lines #L600 - L601 were not covered by tests
# This represents the index of the segment of the share grid where dvds flips
# from positive to negative, indicating that there's a zero *on* the segment

# Calculate the fractional distance between those share gridpoints where the
# zero should be found, assuming a linear function; call it alpha
a_idx = np.arange(aNrmCount)
Expand All @@ -603,7 +612,7 @@ def EndOfPrddvds_dist(S, a, z):
bot_c = EndOfPrd_dvdaNvrs[a_idx, share_idx]
top_c = EndOfPrd_dvdaNvrs[a_idx, share_idx + 1]
alpha = 1.0 - top_f / (top_f - bot_f)

Check warning on line 614 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L607-L614

Added lines #L607 - L614 were not covered by tests

# Calculate the continuous optimal risky share and optimal consumption
ShareAdj_now = (1.0 - alpha) * bot_s + alpha * top_s
cNrmAdj_now = (1.0 - alpha) * bot_c + alpha * top_c

Check warning on line 618 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L617-L618

Added lines #L617 - L618 were not covered by tests
Expand All @@ -624,10 +633,10 @@ def EndOfPrddvds_dist(S, a, z):
# grid, but there's no way to "optimize" the portfolio if a=0, and consumption
# can't depend on the risky share if it doesn't meaningfully exist. Apply
# a small fix to the bottom gridpoint (aNrm=0) when this happens.
if (not BoroCnstNat_iszero):
if not BoroCnstNat_iszero:
ShareAdj_now[0] = 1.0
cNrmAdj_now[0] = EndOfPrd_dvdaNvrs[0, -1]

Check warning on line 638 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L636-L638

Added lines #L636 - L638 were not covered by tests

# Construct functions characterizing the solution for this period

# Calculate the endogenous mNrm gridpoints when the agent adjusts his portfolio,
Expand Down Expand Up @@ -657,15 +666,15 @@ def EndOfPrddvds_dist(S, a, z):

# Construct the marginal value of mNrm function when the agent can't adjust his share
dvdmFuncFxd_now = MargValueFuncCRRA(cFuncFxd_now, CRRA)

Check warning on line 668 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L668

Added line #L668 was not covered by tests

# Construct the optimal risky share function when adjusting is possible
if BoroCnstNat_iszero:
Share_lower_bound = ShareLimit

Check warning on line 672 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L671-L672

Added lines #L671 - L672 were not covered by tests
else:
Share_lower_bound = 1.0
ShareAdj_now = np.insert(ShareAdj_now, 0, Share_lower_bound)
ShareFuncAdj_now = LinearInterp(mNrmAdj_now, ShareAdj_now, ShareLimit, 0.0)

Check warning on line 676 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L674-L676

Added lines #L674 - L676 were not covered by tests

# This is a point at which (a,c,share) have consistent length. Take the
# snapshot for storing the grid and values in the solution.
save_points = {

Check warning on line 680 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L680

Added line #L680 was not covered by tests
Expand All @@ -682,12 +691,12 @@ def EndOfPrddvds_dist(S, a, z):
# Create the value functions for this period, defined over market resources
# mNrm when agent can adjust his portfolio, and over market resources and
# fixed share when agent can not adjust his portfolio.

def calc_v_intermed(S, b, z):

Check warning on line 695 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L695

Added line #L695 was not covered by tests
'''
"""
Calculate "intermediate" value from next period's bank balances, the
income shocks S, and the risky asset share.
'''
"""
mNrm_next = calc_mNrm_next(S, b)

Check warning on line 700 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L700

Added line #L700 was not covered by tests

vAdj_next = vFuncAdj_next(mNrm_next)
Expand All @@ -697,7 +706,7 @@ def calc_v_intermed(S, b, z):
v_next = AdjustPrb * vAdj_next + (1.0 - AdjustPrb) * vFxd_next

Check warning on line 706 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L706

Added line #L706 was not covered by tests
else: # Don't bother evaluating if there's no chance that portfolio share is fixed
v_next = vAdj_next

Check warning on line 708 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L708

Added line #L708 was not covered by tests

v_intermed = (S["PermShk"] * PermGroFac) ** (1.0 - CRRA) * v_next
return v_intermed

Check warning on line 711 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L710-L711

Added lines #L710 - L711 were not covered by tests

Expand All @@ -708,7 +717,7 @@ def calc_v_intermed(S, b, z):
vNvrs_intermed = uFunc.inv(v_intermed)
vNvrsFunc_intermed = BilinearInterp(vNvrs_intermed, bNrmGrid, ShareGrid)
vFunc_intermed = ValueFuncCRRA(vNvrsFunc_intermed, CRRA)

Check warning on line 719 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L717-L719

Added lines #L717 - L719 were not covered by tests

def calc_EndOfPrd_v(S, a, z):

Check warning on line 721 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L721

Added line #L721 was not covered by tests
# Calculate future realizations of bank balances bNrm
Rxs = S - Rfree
Expand All @@ -723,7 +732,9 @@ def calc_EndOfPrd_v(S, a, z):
return EndOfPrd_v

Check warning on line 732 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L731-L732

Added lines #L731 - L732 were not covered by tests

# Calculate end-of-period value by taking expectations
EndOfPrd_v = DiscFacEff * expected(calc_EndOfPrd_v, RiskyDstn, args=(aNrmNow, ShareNext))
EndOfPrd_v = DiscFacEff * expected(

Check warning on line 735 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L735

Added line #L735 was not covered by tests
calc_EndOfPrd_v, RiskyDstn, args=(aNrmNow, ShareNext)
)
EndOfPrd_vNvrs = uFunc.inv(EndOfPrd_v)

Check warning on line 738 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L738

Added line #L738 was not covered by tests

# Now make an end-of-period value function over aNrm and Share
Expand Down Expand Up @@ -764,32 +775,31 @@ def calc_EndOfPrd_v(S, a, z):
)
vNvrsFuncFxd = LinearInterpOnInterp1D(vNvrsFuncFxd_by_Share, ShareGrid)
vFuncFxd_now = ValueFuncCRRA(vNvrsFuncFxd, CRRA)

Check warning on line 777 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L776-L777

Added lines #L776 - L777 were not covered by tests

else: # If vFuncBool is False, fill in dummy values
vFuncAdj_now = NullFunc()
vFuncFxd_now = NullFunc()

Check warning on line 781 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L780-L781

Added lines #L780 - L781 were not covered by tests

# Package and return the solution
solution_now = PortfolioSolution(

Check warning on line 784 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L784

Added line #L784 was not covered by tests
cFuncAdj=cFuncAdj_now,
ShareFuncAdj=ShareFuncAdj_now,
vPfuncAdj=vPfuncAdj_now,
vFuncAdj=vFuncAdj_now,
cFuncFxd=cFuncFxd_now,
ShareFuncFxd=ShareFuncFxd_now,
dvdmFuncFxd=dvdmFuncFxd_now,
dvdsFuncFxd=dvdsFuncFxd_now,
vFuncFxd=vFuncFxd_now,
AdjPrb=AdjustPrb,
# WHAT IS THIS STUFF FOR??
aGrid=save_points["a"],
Share_adj=save_points["share_adj"],
EndOfPrddvda_adj=save_points["eop_dvda_adj"],
ShareGrid=save_points["share_grid"],
EndOfPrddvda_fxd=save_points["eop_dvda_fxd"],
EndOfPrddvds_fxd=save_points["eop_dvds_fxd"],

)
cFuncAdj=cFuncAdj_now,
ShareFuncAdj=ShareFuncAdj_now,
vPfuncAdj=vPfuncAdj_now,
vFuncAdj=vFuncAdj_now,
cFuncFxd=cFuncFxd_now,
ShareFuncFxd=ShareFuncFxd_now,
dvdmFuncFxd=dvdmFuncFxd_now,
dvdsFuncFxd=dvdsFuncFxd_now,
vFuncFxd=vFuncFxd_now,
AdjPrb=AdjustPrb,
# WHAT IS THIS STUFF FOR??
aGrid=save_points["a"],
Share_adj=save_points["share_adj"],
EndOfPrddvda_adj=save_points["eop_dvda_adj"],
ShareGrid=save_points["share_grid"],
EndOfPrddvda_fxd=save_points["eop_dvda_fxd"],
EndOfPrddvds_fxd=save_points["eop_dvds_fxd"],
)
return solution_now

Check warning on line 803 in HARK/ConsumptionSaving/ConsPortfolioModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsPortfolioModel.py#L803

Added line #L803 was not covered by tests


Expand Down

0 comments on commit d9cda03

Please sign in to comment.