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

Let ConsRiskyAssetModel handle time-varying Rfree #1343

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Documentation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Release Date: TBD
- Addresses [#1255](https://github.com/econ-ark/HARK/issues/1255). Makes age-varying stochastic returns possible and draws from their discretized version. [#1262](https://github.com/econ-ark/HARK/pull/1262)
- Fixes bug in the metric that compares dictionaries with the same keys. [#1260](https://github.com/econ-ark/HARK/pull/1260)
- Fixes bug in the calc_jacobian method. [#1342](https://github.com/econ-ark/HARK/pull/1342)
- Fixes bug that prevented risky-asset consumer types from working with time-varying interest rates `Rfree`. [1343](https://github.com/econ-ark/HARK/pull/1343)
### 0.13.0

Release Date: February, 16, 2023
Expand Down
20 changes: 14 additions & 6 deletions HARK/ConsumptionSaving/ConsRiskyAssetModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,21 @@ def update_ShareLimit(self):
-------
None
"""
if "RiskyDstn" in self.time_vary:
if "RiskyDstn" in self.time_vary or "Rfree" in self.time_vary:
self.ShareLimit = []
for t in range(self.T_cycle):
RiskyDstn = self.RiskyDstn[t]
if "RiskyDstn" in self.time_vary:
RiskyDstn = self.RiskyDstn[t]
else:
RiskyDstn = self.RiskyDstn
if "Rfree" in self.time_vary:
Rfree = self.Rfree[t]
else:
Rfree = self.Rfree

def temp_f(s):
return -((1.0 - self.CRRA) ** -1) * np.dot(
(self.Rfree + s * (RiskyDstn.atoms - self.Rfree))
** (1.0 - self.CRRA),
(Rfree + s * (RiskyDstn.atoms - Rfree)) ** (1.0 - self.CRRA),
RiskyDstn.pmv,
)

Expand Down Expand Up @@ -334,7 +340,9 @@ def get_Risky(self):
else:
# Make use of the IndexDistribution.draw() method
self.shocks["Risky"] = self.RiskyDstn.draw(
np.maximum(self.t_cycle - 1,0) if self.cycles == 1 else self.t_cycle
np.maximum(self.t_cycle - 1, 0)
if self.cycles == 1
else self.t_cycle
)

else:
Expand All @@ -360,7 +368,7 @@ def get_Adjust(self):
"""
if "AdjustPrb" in self.time_vary:
self.shocks["Adjust"] = self.AdjustDstn.draw(
np.maximum(self.t_cycle - 1,0) if self.cycles == 1 else self.t_cycle
np.maximum(self.t_cycle - 1, 0) if self.cycles == 1 else self.t_cycle
)
else:
self.shocks["Adjust"] = self.AdjustDstn.draw(self.AgentCount)
Expand Down
4 changes: 2 additions & 2 deletions HARK/ConsumptionSaving/tests/test_ConsPortfolioModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_simulation(self):
)


class test_time_varying_Risky_and_Adj(unittest.TestCase):
class test_time_varying_Risky_Rfree_and_Adj(unittest.TestCase):
def setUp(self):
# Create a parameter dictionary for a three period problem
self.params = cpm.init_portfolio.copy()
Expand All @@ -267,7 +267,7 @@ def setUp(self):
"cycles": 1,
"T_cycle": 3,
"T_age": 3,
"Rfree": 1.0,
"Rfree": [1.0, 0.99, 0.98],
"RiskyAvg": [1.01, 1.02, 1.03],
"RiskyStd": [0.0, 0.0, 0.0],
"RiskyCount": 1,
Expand Down