ICEACE Model: Closed Economy  1.0.0
Design Documentation of ICEACE Model
 All Data Structures Files Functions Variables Typedefs Macros Pages
bank_functions_top.c
Go to the documentation of this file.
1 #include "header.h"
2 #include "bank_agent_header.h"
3 
4 
5 /*
6  * \fn: int bank_init_loans()
7  * \brief:
8  */
10 {
11  LOANS = 0;
12 
16 
17  return 0; /* Returning zero means the agent is not removed */
18 }
19 
20 /*
21  * \fn: int bank_init_mortgages()
22  * \brief:
23  */
25 {
26  MORTGAGES = 0;
27 
31 
32  return 0; /* Returning zero means the agent is not removed */
33 }
34 
35 /*
36  * \fn: int bank_init_deposits()
37  * \brief:
38  */
40 {
41  double deposits_households = 0;
42  double deposits_firms = 0;
43 
45  deposits_households += household_bank_init_deposit_message->amount;
47 
49  deposits_firms += firm_bank_init_deposit_message->amount;
51 
52  DEPOSITS = deposits_households + deposits_firms;
53 
54  /* Initialization Check:
55  printf("Bank ID = %d, Deposits HH= %f, Firms = %f \n", ID, deposits_households, deposits_firms);
56  */
57 
58  return 0; /* Returning zero means the agent is not removed */
59 }
60 
61 /*
62  * \fn: int bank_init_balancesheet()
63  * \brief:
64  */
66 {
67 
68  LIQUIDITY = (LOANS + MORTGAGES) * 0.1;
70  EQUITY = TOTAL_ASSETS * 0.1;
72 
73  if (CENTRALBANK_DEBT < 0) {
74  LIQUIDITY += CENTRALBANK_DEBT;
75  CENTRALBANK_DEBT = 0;
76  }
77 
78  /* Simulation starts with credit markets and net earnings are computed after central bank debt but before interest collections.
79  Following initialization is done to prevent Banks with a negative earnings.
80  */
81  INTERESTS_ACCRUED = LOANS * ((INTEREST_RATE + 0.01) / 4);
82  INTERESTS_ACCRUED += MORTGAGES * ((INTEREST_RATE + 0.02) / 4);
83  LIQUIDITY += INTERESTS_ACCRUED;
85 
86 
87 
89 
90 
92 
93  /* Initialization Check*
94  printf("Bank ID = %d, Loans = %f, Mortgages = %f, Deposits = %f, Liquidity =%f, Equity =%f, Debt = %f \n", ID, LOANS, MORTGAGES, DEPOSITS, LIQUIDITY, EQUITY, CENTRALBANK_DEBT);
95  printf("Bank ID = %d, Equity Ratio = %f \n", ID, EQUITY/(LOANS + MORTGAGES));
96  */
97 
98  return 0; /* Returning zero means the agent is not removed */
99 }
100 
101 
102 /*
103  * \fn: int bank_iterate()
104  * \brief:
105  */
107 {
108 
109  if (DATA_COLLECTION_MODE) {
110  if (IT_NO == 0 || RESUME_MODE) {
111  char * filename;
112  FILE * file1;
113  filename = malloc(40*sizeof(char));
114 
115  /* @\fn: bank_credit_compute_income_statement() */
116  filename[0]=0;
117  strcpy(filename, "./outputs/data/Bank_IncomeStatement.txt");
118  file1 = fopen(filename,"w");
119  fprintf(file1,"%s %s %s %s %s %s %s %s %s %s\n","IT_NO", "ID", "REVENUES", "INTERESTS_ACCRUED", "TOTAL_COSTS", "TOTAL_WRITEOFFS", "INTERESTS_PAID", "NET_EARNINGS", "RETAINED_EARNINGS", "TOTAL_DIVIDENDS");
120  //fprintf(file1,"%d %d %f %f %f %f %f %f %f %f\n",IT_NO, ID, REVENUES, INTERESTS_ACCRUED, TOTAL_COSTS, TOTAL_WRITEOFFS, INTERESTS_PAID, NET_EARNINGS, RETAINED_EARNINGS, TOTAL_DIVIDENDS);
121  fclose(file1);
122 
123 
124  /* @\fn: bank_credit_do_balance_sheet() */
125  filename[0]=0;
126  strcpy(filename, "./outputs/data/Bank_BalanceSheet.txt");
127  file1 = fopen(filename,"w");
128  fprintf(file1,"%s %s %s %s %s %s %s %s %s\n","IT_NO", "ID", "TOTAL_ASSETS", "LIQUIDITY", "LOANS", "MORTGAGES", "DEPOSITS", "CENTRALBANK_DEBT", "EQUITY");
129  //fprintf(file1,"%d %d %f %f %f %f %f %f %f\n",IT_NO, ID, TOTAL_ASSETS, LIQUIDITY, LOANS, MORTGAGES, DEPOSITS, CENTRALBANK_DEBT, EQUITY);
130  fclose(file1);
131 
132 
133  /* @\fn: bank_credit_check_interest_rate() */
134  filename[0]=0;
135  strcpy(filename, "./outputs/data/ICEACE_identity_bank.txt");
136  file1 = fopen(filename,"w");
137  fprintf(file1,"%s %s %s %s %s %s %s\n","IT_NO", "ID", "LOANS", "MORTGAGES", "DEPOSITS", "EQUITY", "INTERESTS_PAID");
138  fclose(file1);
139 
140  free(filename);
141  }
142  }
143 
144  IT_NO++;
145 
146  return 0; /* Returning zero means the agent is not removed */
147 }
148 
149 /*
150  * \fn: int bank_update_deposits()
151  * \brief: puts money to deposit account of its prefered bak. */
153 {
154  double current_deposit, delta_deposit;
155  double deposits_households = 0;
156  double deposits_firms = 0;
157 
158  //printf("Bank ID = %d, pre-liquidity = %f, pre-deposits = %f \n", ID, LIQUIDITY, DEPOSITS);
159 
161  deposits_households += household_bank_update_deposit_message->amount;
163 
164  current_deposit = deposits_households;
165 
167  deposits_firms += firm_bank_update_deposit_message->amount;
169 
170  current_deposit += deposits_firms;
171  delta_deposit = current_deposit - DEPOSITS;
172 
173  DEPOSITS = current_deposit;
174  LIQUIDITY += delta_deposit;
175 
176  //printf("Bank ID = %d Deposits: From Firms = %f , from HH = %f, Total = %f, post-liquidity = %f \n", ID, deposits_firms, deposits_households, DEPOSITS, LIQUIDITY);
177 
178  if (PRINT_DEBUG_MODE) {
179  printf("Bank ID = %d Deposits: From Firms = %f , from HH = %f, Total = %f \n", ID, deposits_firms, deposits_households, DEPOSITS);
180  }
181 
182  return 0; /* Returning zero means the agent is not removed */
183 }
184 
185 /*
186  * \fn: int bank_update_centralbank_deposit()
187  * \brief:
188  */
190 {
191 
193 
194 
195  return 0; /* Returning zero means the agent is not removed */
196 }
197 
198