econ-ark / HARK

Heterogenous Agents Resources & toolKit
Apache License 2.0
328 stars 198 forks source link

Monte Carlo Simulator that accepts aggregate blocks #1471

Open sbenthall opened 2 months ago

sbenthall commented 2 months ago

We now have a Monte Carlo simulator for an AgentType which is generic to model equations. These equations are passed in as 'blocks'. This functionality is limited to 'micro' economic problems, because the simulator does not handle cases where agents interact.

A natural next step would be to extend the Monte Carlo simulation functionality to allow for the definition of Aggregate, 'Market' or 'Economy' blocks, which would be very similar in spirit to the HARK 0.x Market class.

I believe this would be possible to do in 10 hours of work or less.

What would be most useful, before starting this work, is having on hand an example, in mathematical equations of the simplest possible compelling Market or Economy example. I believe that this might be something like a Cobb Douglas function.

Could somebody please advise me on where to look for the details of such a canonical market model?

I know Krusell Smith would be great to do eventually, but of course it would be best to start with something simpler. Extending the more basic functionality to the more complex model might be a good grad student task.

Mv77 commented 1 month ago

The simplest model with micro-heterogeneity is possibly the "Aiyagari Model"

Lots of old integrals math in there but it amounts to including the equilibrium restriction that $$\texttt{Rfree} = F(\int a_{i,t} di)$$ where $F(\cdot)$ can be something simple like $F(x) = 1 + x^{0.33 - 1}$, adequately scaled so that the Rfree ultimately makes sense and is not like... 5.

There are no aggregate shocks and, since with enough agents the integral should be constant, this is a model in which the conditions of every individual agent change (idiosyncratic risk) but the macro aggregates are constant. That is why it is simpler than, e.g., Krusell-Smith

Mv77 commented 1 month ago

Intuition is that R is the price of renting capital (the funds that agents save). If there is a lot of saved funds available, renting them should be cheaper.

Think of $F(\cdot)$ as the price that some external entity (in this case a firm) is willing to pay to agents for renting their savings for one period. Impose that and you have an equilibirum model.

mnwhite commented 1 month ago

To be clear, this can be done with a trivial subclass of IndShockConsumerType (that gives it reset() and market_action() methods) and a custom Market subclass. The AiyagariMarket would have act_T=1, reap_vars = ['aLvl'], sow_vars = [], and dyn_vars = ['Rfree']. The agent subclass would simulate() as its market_action() (rather than the usual sim_one_period). The mill_rule can just sum/integrate aLvl and store it as aLvlAgg, and update_dynamics would take in aLvlAgg, take the average of the last X periods, and then plug that into the pricing function (damping might be needed).

NB: Writing that out reminded me how much of a mistake it was to call it dyn_vars rather than eqbm_vars.

It can also be "solved" with an AggShockConsumerType by shutting down aggregate shocks and writing a custom Afunc that has agents believe E[At] = A{t-1}, where A_{t-1} can be recovered from the M_t state because shocks have been shut off (appropriate to the pricing function, which is usually Cobb-Douglas-based in ConsAggShock). Solve that type and simulate it for a large number of periods, and it will settle down into the eqbm interest rate and level of capital.

On Tue, Jul 16, 2024 at 9:24 PM Mateo Velásquez-Giraldo < @.***> wrote:

Intuition is that R is the price of renting capital (the funds that agents save). If there is a lot of saved funds available, renting them should be cheaper.

Think of $F(\cdot)$ as the price that some external entity (in this case a firm) is willing to pay to agents for renting their savings for one period. Impose that and you have an equilibirum model.

— Reply to this email directly, view it on GitHub https://github.com/econ-ark/HARK/issues/1471#issuecomment-2232124556, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADKRAFLFWT7JE4HTOZHDQJ3ZMXBTPAVCNFSM6AAAAABKVCVGR2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZSGEZDINJVGY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

sbenthall commented 1 month ago

Thanks @Mv77 that's perfect.

I'm linking here to the dolark version of this model just for reference, since it's a succinct representation of the problem:

https://github.com/EconForge/dolark.py/blob/master/examples/ayiagari.yaml

sbenthall commented 1 month ago

It's a little hard to unpack the forward transition equations from the original paper, but I believe it, for the individual agent:

$$z = lw + (1+r)a$$

$$c < z + b$$

$$a' = z - c$$

And at the aggregate level:

$$K = \sum_N a$$

$$r = \alpha (K/N) ^ { \alpha - 1}$$

$$w = (1-\alpha)*(K/N)^\alpha$$

EDIT: The equation for $r$ has been edited as per @mnwhite suggestion below.

CRRA utility as before.

I believe this is sufficient for the Monte Carlo simulation for arbitrary decision rules (which may be out of equilibrium). I wonder if you agree.

mnwhite commented 1 month ago

Those look correct to me, but I'd rephrase the r equation because N/K looks so jarring to me.

On Wed, Jul 17, 2024 at 11:49 AM Sebastian Benthall < @.***> wrote:

It's a little hard to unpack the forward transition equations from the original paper, but I believe it, for the individual agent:

$$z = lw + (1+r)a$$

$$c < z + b$$

$$a' = z - c$$

And at the aggregate level:

$$K = \sum_N a$$

$$r = \alpha (N/K) ^ {1 - \alpha}$$

$$w = (1-\alpha)*(K/N)^\alpha$$

CRRA utility as before.

I believe this is sufficient for the Monte Carlo simulation for arbitrary decision rules (which may be out of equilibrium). I wonder if you agree.

— Reply to this email directly, view it on GitHub https://github.com/econ-ark/HARK/issues/1471#issuecomment-2233643798, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADKRAFOZUOS5W6SB452SY7LZM2HCNAVCNFSM6AAAAABKVCVGR2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZTGY2DGNZZHA . You are receiving this because you commented.Message ID: @.***>

sbenthall commented 1 month ago

How would you like it expressed, @mnwhite ?

mnwhite commented 1 month ago

As K/N, and then flip the sign of the exponent. I just meant that K/N means something interpretable, whereas N/K is not.

On Wed, Jul 17, 2024 at 12:13 PM Sebastian Benthall < @.***> wrote:

How would you like it expressed, @mnwhite https://github.com/mnwhite ?

— Reply to this email directly, view it on GitHub https://github.com/econ-ark/HARK/issues/1471#issuecomment-2233692515, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADKRAFLRMEXIMFZPYUHN76TZM2JZJAVCNFSM6AAAAABKVCVGR2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZTGY4TENJRGU . You are receiving this because you were mentioned.Message ID: @.***>

sbenthall commented 1 month ago

I agree. Good point, @mnwhite

Mv77 commented 1 month ago

I'd suggest setting $N$ to 1 and forgetting about wages. Receiving wages as an input that affects the income of agents might require defining a new agent type. I'd just take income to be whatever the baseline income process of ConsIndShock is.

That way the only real equilibrium restriction to be satisfied would be $F\left ( \int a_{i,t}(\texttt{Rfree}) di \right) = \texttt{Rfree}$. Call it a "simplified Aiyagari" just to start testing the framework with a single simple equation.

mnwhite commented 1 month ago

I think N here is just the number of simulated agents; it's in the summation statement for aggregate K from individual a_i that Seb had.

On Wed, Jul 17, 2024 at 12:58 PM Mateo Velásquez-Giraldo < @.***> wrote:

I'd suggest setting $N$ to 1 and forgetting about wages. Receiving wages as an input that affects the income of agents might require defining a new agent type. I'd just take income to be whatever the baseline income process of ConsIndShock is.

That way the only real equilibrium restriction to be satisfied would be $F\left ( \int a_{i,t}(\texttt{Rfree}) di \right) = \texttt{Rfree}$. Call it a "simplified Aiyagari" just to start testing the framework with a single simple equation.

— Reply to this email directly, view it on GitHub https://github.com/econ-ark/HARK/issues/1471#issuecomment-2233771669, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADKRAFN6VZMJT7RNKGEDGQLZM2PEFAVCNFSM6AAAAABKVCVGR2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZTG43TCNRWHE . You are receiving this because you were mentioned.Message ID: @.***>

sbenthall commented 1 month ago

@Mv77 The point of this issue is to develop (a) a python configuration object which contains model equations for aggregation and (b) changes to the (general) Monte Carlo simulator to enable forward simulation with such a configuration object. There are no AgentType objects involved here at all.

So it's the aggregation, not the equilibrium condition, which I'm getting at here.

Out of scope for this issue is to write a solver that can take these equations and derive a solution. That's perhaps far ahead. It would follow on #1438