CalcInflationRate#

class bamengine.events.labor_market.CalcInflationRate[source]#

Bases: Event

Calculate and store the inflation rate for the current period.

The inflation rate measures the change in the average market price level. This is used by AdjustMinimumWage to index the minimum wage to inflation. Uses year-over-year comparison (4-period lookback).

Algorithm

  1. Check if price history has at least 5 periods (\(t \geq 4\))

  2. If insufficient history, set \(\pi_t = 0\) and skip

  3. Otherwise, calculate: \(\pi_t = (\bar{P}_t - \bar{P}_{t-4}) / \bar{P}_{t-4}\)

  4. Append \(\pi_t\) to inflation history

Mathematical Notation

\[\pi_t = \frac{\bar{P}_t - \bar{P}_{t-4}}{\bar{P}_{t-4}}\]

where:

  • \(\pi_t\): inflation rate at period t

  • \(\bar{P}_t\): average market price at period t

Examples

Execute this event:

>>> import bamengine as be
>>> sim = be.Simulation.init(n_firms=100, seed=42)
>>> event = sim.get_event("calc_inflation_rate")
>>> event.execute(sim)

Check inflation history:

>>> # Need at least 5 periods for non-zero YoY inflation
>>> for _ in range(5):
...     sim.step()
>>> sim.ec.inflation_history[-1]
0.023

Inflation requires 5 periods of history:

>>> sim = be.Simulation.init(n_firms=10, seed=42)
>>> event = sim.get_event("calc_inflation_rate")
>>> event.execute(sim)
>>> sim.ec.inflation_history[-1]
0.0

Notes

This event must execute before AdjustMinimumWage in each period.

During the first 4 periods (t < 4), inflation is set to 0.0 since there is insufficient history.

The inflation rate is stored in Economy.inflation_history for later use by minimum wage adjustment.

See also

AdjustMinimumWage

Uses inflation to update minimum wage

Economy

Global economy state with price/inflation history

bamengine.events._internal.labor_market.calc_inflation_rate

Implementation

execute(sim)[source]#

Execute the event’s logic.

Mutates simulation state in-place. This method must be implemented by all Event subclasses.

Parameters:

sim (Simulation) – The simulation instance containing all state and configuration.

Returns:

All mutations are in-place.

Return type:

None

Examples

Implement execute in a custom event:

>>> from bamengine import event, ops
>>>
>>> @event
... class CustomPricingEvent:
...     def execute(self, sim):
...         prod = sim.get_role("Producer")
...         # Apply 10% markup to all prices
...         new_prices = ops.multiply(prod.price, 1.1)
...         ops.assign(prod.price, new_prices)

Access configuration and RNG:

>>> @event
... class StochasticEvent:
...     def execute(self, sim):
...         shock = sim.config.h_rho
...         random_values = sim.rng.uniform(0, shock, size=sim.n_firms)
...         # Use random_values in calculations

Notes

The execute method receives full Simulation access, including: - All roles: sim.get_role(“RoleName”) or sim.prod, sim.wrk, etc. - Configuration: sim.config - RNG: sim.rng - Economy state: sim.ec

__init__()#
name = 'calc_inflation_rate'#