Skip to content

Commit

Permalink
adding YAML config for portfolio block and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenthall committed Jul 3, 2024
1 parent 2db6527 commit 2a09a27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
37 changes: 10 additions & 27 deletions HARK/models/consumer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,13 @@ blocks:

reward:
u: c ** (1 - CRRA) / (1 - CRRA)


#portfolio_block = DBlock(
# **{
# "name": "portfolio",
# "shocks": {
# "risky_return": (Lognormal, {"mean": "Rfree + EqP", "std": "RiskyStd"})
# },
# "dynamics": {
# "stigma": Control(["a"]),
# "R": lambda stigma, Rfree, risky_return: Rfree
# + (risky_return - Rfree) * stigma,
# },
# }
#)

#tick_block = DBlock(
# **{
# "name": "tick",
# "dynamics": {
# "k": lambda a: a,
# },
# }
#)

#cons_problem = RBlock(blocks=[consumption_block, tick_block])
#cons_portfolio_problem = RBlock(blocks=[consumption_block, portfolio_block, tick_block])
- &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
15 changes: 10 additions & 5 deletions HARK/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ def test_parse(self):

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')
self.assertEqual(config["calibration"]["DiscFac"], 0.96)
self.assertEqual(config["blocks"][0]["name"], "consumption normalized")

## construct and test the block
cons_norm_block = model.DBlock(**config['blocks'][0])
cons_norm_block.construct_shocks(config['calibration'])
## 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}})

0 comments on commit 2a09a27

Please sign in to comment.