From c3e2691e63100ba232a09b4bc0aad90f2a868f79 Mon Sep 17 00:00:00 2001 From: Mateo VG Date: Sat, 19 Aug 2023 12:32:02 -0400 Subject: [PATCH 1/2] Make share limit compatible with time-varying Rfree --- HARK/ConsumptionSaving/ConsRiskyAssetModel.py | 20 +++++++++++++------ .../tests/test_ConsPortfolioModel.py | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/HARK/ConsumptionSaving/ConsRiskyAssetModel.py b/HARK/ConsumptionSaving/ConsRiskyAssetModel.py index e2143c444..a18fce177 100644 --- a/HARK/ConsumptionSaving/ConsRiskyAssetModel.py +++ b/HARK/ConsumptionSaving/ConsRiskyAssetModel.py @@ -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, ) @@ -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: @@ -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) diff --git a/HARK/ConsumptionSaving/tests/test_ConsPortfolioModel.py b/HARK/ConsumptionSaving/tests/test_ConsPortfolioModel.py index 96b047a60..f7bbcb19a 100644 --- a/HARK/ConsumptionSaving/tests/test_ConsPortfolioModel.py +++ b/HARK/ConsumptionSaving/tests/test_ConsPortfolioModel.py @@ -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() @@ -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, From 39abdcdf705bd2041b25166a4bbbeeacb47f3ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Vel=C3=A1squez-Giraldo?= Date: Sat, 19 Aug 2023 12:42:55 -0400 Subject: [PATCH 2/2] Update CHANGELOG.md --- Documentation/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/CHANGELOG.md b/Documentation/CHANGELOG.md index f44249bb4..e1c009e65 100644 --- a/Documentation/CHANGELOG.md +++ b/Documentation/CHANGELOG.md @@ -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