-
Notifications
You must be signed in to change notification settings - Fork 16
Bank Overview
Si Li edited this page Mar 7, 2025
·
1 revision
Here's a breakdown (generated by Gemini):
The Bank class in this code is designed to simulate the core operations of a banking institution within the economic simulation. Its functions can be grouped into these categories:
- Initialization and Configuration:
- BankInit(float initDeposits, string curr):
- Purpose: Sets up the initial state of the bank.
- Actions:
- Sets the currency used by the bank.
- Initializes the bank's total deposits (TotalDeposits).
- Sets the initial values for liability and wealth.
- Initializes the Deposits dictionary to track individual agent deposits.
- BankRegulations(float ratio, int termsInRounds, float interest, int _maxMissedPayments, float _maxPrinciple, int _maxNumDefaults):
- Purpose: Configures the bank's regulatory parameters.
- Actions:
- Sets the fractionalReserveRatio (how much money the bank must hold in reserve).
- Sets the loan termInRounds (how long a loan lasts).
- Sets the interestRate on loans.
- Sets maximum missed payments, principle and defaults for loans.
- Init(SimulationConfig cfg, AuctionStats at, string b, float _initStock, float maxstock, float cash=-1f)
- Purpose: initializes the bank.
- Actions:
- sets up the starting conditions for the bank.
- add initial inventories.
- Deposit Operations:
- Deposit(EconAgent agent, float amount, string curr):
- Purpose: Handles an agent making a deposit into the bank.
- Actions:
- Increases the bank's TotalDeposits.
- Updates the specific agent's deposit balance in the Deposits dictionary.
- Logs the deposit transaction.
- CheckAccountBalance(EconAgent agent):
- Purpose: Retrieves the current deposit balance for a specific agent.
- Actions:
- Returns the agent's current deposit amount from the Deposits dictionary.
- Withdraw(EconAgent agent, float amount, string curr):
- Purpose: Handles an agent making a withdrawal from the bank.
- Actions:
- Reduces the bank's TotalDeposits.
- Reduces the specific agent's deposit balance in the Deposits dictionary.
- Ensures that the withdrawal amount doesn't exceed the agent's available balance.
- Logs the withdrawal transaction.
- Loan Operations:
- Borrow(EconAgent agent, float amount, string curr):
- Purpose: Handles an agent taking out a loan from the bank.
- Actions:
- Checks if the agent is eligible to borrow (using CheckIfCanBorrow).
- Checks if the bank has sufficient reserves to loan.
- Creates a new Loan object.
- Adds the loan to the agent's loan history in loanBook.
- Increases the bank's liability (money owed to the bank).
- Transfers the loan amount to the agent's cash balance.
- Logs the loan transaction.
- CheckIfCanBorrow(EconAgent agent, float amount)
- Purpose: Checks if an agent can get a loan.
- Actions:
- Checks if the principle and num defaults is within range.
- QueryLoans(EconAgent agent):
- Purpose: Gets the total outstanding loan amount (principle) for a specific agent.
- Actions:
- Returns the agent's current outstanding loan principle from loanBook.
- CollectPayments():
- Purpose: Handles the collection of loan payments from all agents.
- Actions:
- Iterates through all agents who have loans.
- Calls CollectPaymentsFromAgent to process each agent's payment.
- Logs how much debt and interest was collected.
- CollectPaymentsFromAgent(EconAgent agent, ref float tempLiability, Loans loans)
- Purpose: Collects payments from a specific agent
- Actions:
- Calls PayOffLoans to process payments.
- Calls MarkOffPaidLoans to remove paid loans.
- if there was a shortfall, call AgentBorrowsShortfall to take out a loan to pay it.
- AgentPays actually makes the payment.
- AgentBorrowsShortfall(EconAgent agent, ref float tempLiability, float paymentByAgent, float agentMonies)
- Purpose: Has an agent take out more money if they can't pay.
- Actions:
- Figures out how much the agent needs to borrow.
- calls Borrow to actually take out the loan.
- AgentPays(EconAgent agent, float paymentByAgent, float deposit, float interestPaidByAgent)
- Purpose: Has an agent pay the bank.
- Actions:
- If they have enough deposits, use that to pay.
- otherwise, pay using cash.
- MarkOffPaidLoans(EconAgent agent, ref float tempLiability, Loans loans)
- Purpose: remove paid off loans from the books.
- Actions:
- Checks if each loan was paid off, and removes it if it was.
- PayOffLoans(EconAgent agent, ref float tempLiability, Loans loans, float deposit,out float interestPaidByAgent, out float paymentByAgent)
- Purpose: Processes loan payments.
- Actions:
- Iterates through each loan.
- Figures out how much interest and payment is due.
- If not enough to pay, may borrow more.
- If they miss too many payments, default on their loan.
- sets output parameters for how much interest and principle was paid.
- Financial Status and Reporting:
- Monies():
- Purpose: Returns the bank's total financial resources.
- Actions:
- Calculates and returns TotalDeposits + Wealth.
- TotalDeposits, liability, Wealth
- Purpose: variables to track how much the bank has, owes, and owns.
- DebugLiability(float tempLiability)
- Purpose: used to make sure liability is correct.
- LiquidateInventory(Inventory agentInventory)
- Purpose: Takes the inventory from an agent
- Actions:
- Takes items from the provided inventory, and places them into the bank.
- Overrides from EconAgent
- CreateBids(AuctionBook book)
- Purpose: override for creating bids, but it does nothing.
- CreateAsks()
- Purpose: override to make offers, selling inventories for 90% of market price.
- Decide()
- Purpose: overide for decide actions, but it does nothing.
- Helper functions
- BorrowAmount(float paymentByAgent, float agentMonies)
- Purpose: calculates how much a agent should borrow.
- Misc
- Enable
- Purpose: if loans are currently enabled. High-Level Summary The Bank class manages:
- Deposits: Agents can deposit and withdraw funds.
- Loans: Agents can borrow money, and the bank tracks their loan amounts, interest, and repayment status.
- Reserves: The bank maintains a fractional reserve, ensuring it has some cash on hand to handle withdrawals.
- Regulations: The bank is subject to various regulatory limits (e.g., reserve ratio, loan terms).
- Loan Payments: The bank collects loan payments from agents each round, and can attempt to help them borrow more to cover shortfalls.
- Liquidation: can take over the inventory from an agent.
- Tracking: has variables to track the financial status of the bank. This class is a key component for adding financial complexity to the economic simulation. By having a bank, agents can borrow money to expand their operations, and the bank can earn interest while (hopefully) managing its risk appropriately.