Skip to content

Commit

Permalink
Merge pull request #1343 from Mv77/plumbing/time-varying-rfree
Browse files Browse the repository at this point in the history
Let `ConsRiskyAssetModel` handle time-varying Rfree
  • Loading branch information
Mv77 authored Aug 21, 2023
2 parents b18c71f + 39abdcd commit 7ce7138
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
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

0 comments on commit 7ce7138

Please sign in to comment.