-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1465 from sbenthall/i1373
YAML configuration for consumer portfolio problem, with parser and working tests.
- Loading branch information
Showing
6 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# | ||
# A YAML configuration file for the consumption portfolio problem blocks. | ||
# | ||
|
||
calibration: | ||
DiscFac: 0.96 | ||
CRRA: 2.0 | ||
R: 1.03 # can be overriden by portfolio dynamics | ||
Rfree: 1.03 | ||
EqP: 0.02 | ||
LivPrb: 0.98 | ||
PermGroFac: 1.01 | ||
BoroCnstArt: None | ||
TranShkStd: 0.1 | ||
RiskyStd: 0.1 | ||
|
||
blocks: | ||
- &cons_normalized | ||
name: consumption normalized | ||
shocks: | ||
live: !Bernoulli | ||
p: LivPrb | ||
theta: !MeanOneLogNormal | ||
sigma: TranShkStd | ||
dynamics: | ||
b: k * R / PermGroFac | ||
m: b + theta | ||
c: !Control | ||
info: m | ||
a: m - c | ||
|
||
reward: | ||
u: c ** (1 - CRRA) / (1 - CRRA) | ||
- &portfolio_choice | ||
name: portfolio choice | ||
shocks: | ||
risky_return: !Lognormal | ||
mean: Rfree + EqP | ||
std: RiskyStd | ||
dynamics: | ||
stigma: !Control | ||
info: a | ||
R: Rfree + (risky_return - Rfree) * stigma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import unittest | ||
|
||
import HARK.model as model | ||
import HARK.parser as parser | ||
import yaml | ||
|
||
|
||
class test_consumption_parsing(unittest.TestCase): | ||
def setUp(self): | ||
this_file_path = os.path.dirname(__file__) | ||
consumer_yaml_path = os.path.join(this_file_path, "../models/consumer.yaml") | ||
|
||
self.consumer_yaml_file = open(consumer_yaml_path, "r") | ||
|
||
def test_parse(self): | ||
self.consumer_yaml_file | ||
|
||
config = yaml.load(self.consumer_yaml_file, Loader=parser.harklang_loader()) | ||
|
||
self.assertEqual(config["calibration"]["DiscFac"], 0.96) | ||
self.assertEqual(config["blocks"][0]["name"], "consumption normalized") | ||
|
||
## construct and test the consumption block | ||
cons_norm_block = model.DBlock(**config["blocks"][0]) | ||
cons_norm_block.construct_shocks(config["calibration"]) | ||
cons_norm_block.discretize({"theta": {"N": 5}}) | ||
self.assertEqual(cons_norm_block.calc_reward({"c": 1, "CRRA": 2})["u"], -1.0) | ||
|
||
## construct and test the portfolio block | ||
portfolio_block = model.DBlock(**config["blocks"][1]) | ||
portfolio_block.construct_shocks(config["calibration"]) | ||
portfolio_block.discretize({"risky_return": {"N": 5}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ networkx>=3 | |
numba<0.60.0 | ||
numpy>=1.23 | ||
pandas>=1.5 | ||
pyyaml>=6.0 | ||
quantecon | ||
scipy>=1.10 | ||
seaborn>=0.12 | ||
|