FirmsCollectRevenue#

class bamengine.events.revenue.FirmsCollectRevenue[source]#

Bases: Event

Firms collect revenue from sales and calculate gross profit.

Revenue is calculated from goods sold (production minus remaining inventory). Gross profit is revenue minus wage costs. Funds increase by revenue amount.

Algorithm

For each firm i:

  1. Calculate units sold: \(Q_i = Y_i - S_i\)

  2. Calculate revenue: \(R_i = P_i \times Q_i\)

  3. Calculate gross profit: \(GP_i = R_i - W_i\)

  4. Add revenue to funds: \(A_i \leftarrow A_i + R_i\)

Mathematical Notation

\[ \begin{align}\begin{aligned}Q_i = Y_i - S_i\\R_i = P_i \times Q_i\\GP_i = R_i - W_i\\A_i \leftarrow A_i + R_i\end{aligned}\end{align} \]

where \(Y_i\) = production, \(S_i\) = inventory, \(P_i\) = price, \(W_i\) = wage_bill, \(A_i\) = total_funds.

Examples

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

Check total revenue:

>>> total_revenue = sim.bor.gross_profit.sum() + sim.bor.wage_bill.sum()
>>> total_revenue
5200.0

Firms with positive sales have positive revenue:

>>> import numpy as np
>>> units_sold = sim.prod.production - sim.prod.inventory
>>> firms_with_sales = units_sold > 0
>>> revenue = sim.prod.price * units_sold
>>> (revenue[firms_with_sales] > 0).all()
True

Notes

This event must execute after all goods market events (need final inventory).

Gross profit can be negative if wage bill exceeds revenue (operating loss).

Net profit (calculated later) further subtracts interest payments.

See also

FirmsPayDividends

Uses net_profit for dividend calculation

bamengine.events._internal.firms_collect_revenue

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 = 'firms_collect_revenue'#