Agent-Based Model Module¶
This module implements agent-based modeling techniques for simulating bank behaviors during stress scenarios.
BankAgent¶
Bank agent implementation for financial network simulations.
This module provides the BankAgent class which represents a bank in the agent-based model and implements its decision-making behaviors.
- class scr_financial.abm.bank_agent.BankAgent(bank_id, initial_state, decision_model=None, stochastic=True)[source]¶
Bases:
objectRepresents a bank in the agent-based model.
- Parameters:
bank_id (str) – Unique identifier for the bank.
initial_state (dict) – Dictionary containing initial bank attributes.
decision_model (object, optional) – Decision model to use for agent behavior, by default DefaultDecisionModel().
stochastic (bool) – Enable Ornstein-Uhlenbeck noise on regulatory ratios each step.
- __init__(bank_id, initial_state, decision_model=None, stochastic=True)[source]¶
Initialize a bank agent with an ID and initial state.
- evolve_ratios(rng, dt=1.0)[source]¶
Apply one discrete Ornstein-Uhlenbeck step to CET1, LCR, NSFR.
dx = theta*(mu - x)*dt + sigma*sqrt(dt)*N(0,1)
- apply_counterparty_loss(loss_amount)[source]¶
Apply a credit loss from a defaulted counterparty.
Reduces interbank_assets, CET1 proportionally, and cash.
- Parameters:
loss_amount (float)
- Return type:
None
- update_state(new_state)[source]¶
Update the bank’s state with new information.
- Parameters:
new_state (dict) – Dictionary containing updated attributes
- Return type:
None
- assess_solvency()[source]¶
Determine if the bank is solvent based on capital ratios.
- Returns:
True if the bank is solvent, False otherwise
- Return type:
- assess_liquidity()[source]¶
Determine if the bank has adequate liquidity.
- Returns:
True if the bank has adequate liquidity, False otherwise
- Return type:
- calculate_lending_capacity()[source]¶
Calculate how much the bank can lend to other banks.
- Returns:
Lending capacity in currency units
- Return type:
- decide_lending_action(potential_borrowers, market_sentiment)[source]¶
Decide lending actions based on current state and market conditions.
- decide_borrowing_action(potential_lenders, market_sentiment)[source]¶
Decide borrowing actions based on current state and market conditions.
BankingSystemSimulation¶
Banking system simulation for financial network analysis.
This module provides the BankingSystemSimulation class for simulating interbank lending and contagion dynamics.
- class scr_financial.abm.simulation.BankingSystemSimulation(bank_data, network_data, system_indicators, stochastic=True, seed=None)[source]¶
Bases:
objectImplements the agent-based simulation engine.
- Parameters:
- __init__(bank_data, network_data, system_indicators, stochastic=True, seed=None)[source]¶
Initialize the simulation with bank data, network data, and system indicators.
- calculate_market_sentiment()[source]¶
Calculate overall market sentiment based on system indicators.
- Returns:
Market sentiment (0-1 scale, 1 being positive)
- Return type:
- apply_external_shock(shock_params)[source]¶
Apply an external shock to the system.
- Parameters:
shock_params (dict) – Dictionary containing shock parameters
- Return type:
None
- simulate_interbank_lending()[source]¶
Simulate one round of interbank lending decisions.
- Return type:
None
- reset()[source]¶
Reset the simulation to its initial state.
Clears
history, resetstimeto 0, and re-initialises every bank’s state from thebank_datapassed at construction. Network connections are also restored from the originalnetwork_data.- Return type:
None
- get_adjacency_matrix()[source]¶
Get the adjacency matrix of the current network.
- Returns:
Adjacency matrix
- Return type:
Decision Models¶
Decision models for bank agents in financial network simulations.
This module provides various decision-making models that determine how bank agents behave in different scenarios.
- class scr_financial.abm.decision_models.DefaultDecisionModel[source]¶
Bases:
objectDefault decision model for bank agents.
Implements simple rule-based decision making for lending, borrowing, and responding to shocks.
- decide_lending_action(bank, potential_borrowers, market_sentiment)[source]¶
Decide lending actions based on current state and market conditions.
- class scr_financial.abm.decision_models.StressDecisionModel[source]¶
Bases:
DefaultDecisionModelDecision model for bank agents during stress scenarios.
This model extends the default model with more conservative behavior during market stress.
- class scr_financial.abm.decision_models.LearningDecisionModel(learning_rate=0.1)[source]¶
Bases:
DefaultDecisionModelDecision model that learns from past interactions.
This model extends the default model with learning capabilities based on past interactions with other banks.
- Parameters:
learning_rate (float)
- __init__(learning_rate=0.1)[source]¶
Initialise the learning decision model.
- Parameters:
learning_rate (float) – Weight given to each new outcome when updating interaction scores. Must be in (0, 1]. Defaults to 0.1.
- Return type:
None
- decide_lending_action(bank, potential_borrowers, market_sentiment)[source]¶
Lending decisions influenced by past interactions.