FirmsCalcFinancialFragility#
- class bamengine.events.credit_market.FirmsCalcFinancialFragility[source]#
Bases:
EventFirms calculate projected financial fragility metric for credit evaluation.
The fragility metric is the leverage ratio (debt-to-equity). Higher fragility indicates greater default risk. Banks may use this metric (implicitly via net worth ranking) to assess creditworthiness.
Algorithm
For each firm i:
Pre-fill fragility with
max_leverage(worst-case for firms with \(A_i \leq 0\))For firms with \(A_i > 0\): \(f_i = B_i / A_i\) (uncapped)
Mathematical Notation
\[f_i = \frac{B_i}{A_i}\]where:
\(f_i\): projected financial fragility (leverage)
\(B_i\): credit demand
\(A_i\): net worth
Examples
Execute this event:
>>> import bamengine as be >>> sim = be.Simulation.init(n_firms=100, seed=42) >>> # First calculate credit demand >>> sim.get_event("firms_decide_credit_demand")().execute(sim) >>> # Then calculate metrics >>> event = sim.get_event("firms_calc_financial_fragility") >>> event.execute(sim)
Check fragility distribution:
>>> sim.bor.projected_fragility.mean() 0.15
Find high-fragility firms:
>>> import numpy as np >>> high_risk = sim.bor.projected_fragility > 0.5 >>> high_risk.sum() 8
Verify fragility calculation:
>>> # For firms with positive net worth: fragility = credit_demand / net_worth >>> pos_net_worth = sim.bor.net_worth > 0 >>> expected_fragility = ( ... sim.bor.credit_demand[pos_net_worth] / sim.bor.net_worth[pos_net_worth] ... ) >>> actual_fragility = sim.bor.projected_fragility[pos_net_worth] >>> np.allclose(actual_fragility, expected_fragility) True
Notes
This event must execute after FirmsDecideCreditDemand and before FirmsPrepareLoanApplications.
Fragility is calculated but not directly used by banks in the current implementation. Banks rank applicants by net worth instead. Future extensions could incorporate fragility into credit decisions.
Firms with zero or negative net worth have undefined leverage. The implementation assigns
max_leveragefor these firms, giving them the worst credit priority and highest interest rate premium.See also
FirmsDecideCreditDemandCalculates credit_demand used in leverage
CreditMarketRoundBanks evaluate creditworthiness (by net worth)
BorrowerFinancial state with credit_demand, net_worth
bamengine.events._internal.credit_market.firms_calc_financial_fragilityImplementation
- 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_calc_financial_fragility'#