FirmsDecideCreditDemand#
- class bamengine.events.credit_market.FirmsDecideCreditDemand[source]#
Bases:
EventFirms calculate credit demand based on funding shortfall.
Firms need to pay their wage bill but may lack sufficient funds (net worth). Credit demand is the shortfall between wage obligations and available funds.
Algorithm
For each firm i:
\[B_i = \max(W_i - A_i, 0)\]where:
\(B_i\): credit demand (amount firm needs to borrow)
\(W_i\): wage bill (total wages owed to workers)
\(A_i\): total funds (firm’s current cash balance)
Firms with \(A_i \geq W_i\) have zero credit demand (self-financed).
Mathematical Notation
\[B_i = \max(0, W_i - A_i)\]Examples
Execute this event:
>>> import bamengine as be >>> sim = be.Simulation.init(n_firms=100, seed=42) >>> event = sim.get_event("firms_decide_credit_demand") >>> event.execute(sim)
Check total credit demand:
>>> sim.bor.credit_demand.sum() 1250.0
Find firms needing credit:
>>> import numpy as np >>> needs_credit = sim.bor.credit_demand > 0 >>> needs_credit.sum() 45
Verify credit demand formula:
>>> shortfall = np.maximum(sim.bor.wage_bill - sim.bor.total_funds, 0) >>> np.allclose(sim.bor.credit_demand, shortfall) True
Notes
This event must execute after FirmsCalcWageBill (need wage_bill) and before FirmsPrepareLoanApplications.
Firms with negative net worth may have very high credit demand (potentially exceeding available credit supply).
Credit demand is zero for self-financed firms (net_worth >= wage_bill).
See also
FirmsCalcWageBillCalculates wage_bill used in credit demand
FirmsCalcFinancialFragilityUses credit_demand to calculate leverage
FirmsPrepareLoanApplicationsFirms with credit_demand > 0 apply for loans
bamengine.events._internal.credit_market.firms_decide_credit_demandImplementation
- 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:
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_decide_credit_demand'#