ICEACE Model: Closed Economy  1.0.0
Design Documentation of ICEACE Model
 All Data Structures Files Functions Variables Typedefs Macros Pages
bank_functions_credit.c
Go to the documentation of this file.
1 #include "../header.h"
2 #include "../bank_agent_header.h"
3 
4 /*
5  * \fn: int bank_credit_check_interest_rate()
6  * \brief: Checks quarterly interest rate determined by central bank.
7  */
9 {
10 
14 
15  char * filename;
16  FILE * file1;
17  filename = malloc(40*sizeof(char));
18 
19  filename[0]=0;
20  strcpy(filename, "./outputs/data/ICEACE_identity_bank.txt");
21  file1 = fopen(filename,"a");
22  double current_equity = 0;
23  current_equity = LIQUIDITY + LOANS + MORTGAGES - DEPOSITS - CENTRALBANK_DEBT;
24  fprintf(file1,"%d %d %f %f %f %f %f\n",IT_NO, ID, LOANS, MORTGAGES, DEPOSITS, current_equity, INTERESTS_PAID);
25 
26  fclose(file1);
27  free(filename);
28 
29  return 0; /* Returning zero means the agent is not removed */
30 }
31 
32 /*
33  * \fn: int bank_credit_compute_income_statement()
34  * \brief:
35  */
37 {
38  /* No payment on principal amount of debt is considered here!
39  The principal payment is done within balance sheet accounting.
40  */
41 
42  INTERESTS_PAID = 0;
46 
50 
52  char * filename;
53  FILE * file1;
54  filename = malloc(100*sizeof(char));
55  filename[0]=0;
56  strcpy(filename, "./outputs/data/Bank_IncomeStatement.txt");
57 
58  file1 = fopen(filename,"a");
59  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);
60  fclose(file1);
61  free(filename);
62  }
63 
65  TOTAL_WRITEOFFS = 0;
66 
67  return 0; /* Returning zero means the agent is not removed */
68 }
69 
70 
71 /*
72  * \fn: int bank_credit_compute_dividends()
73  * \brief:
74  */
76 {
77 
78  if (NET_EARNINGS <= 0) {
79  TOTAL_DIVIDENDS = 0;
81  return 0;
82  }
83  /* determine if dividends retained.*/
84 
85  double risky_assets;
86  risky_assets = LOANS + MORTGAGES;
87  if (risky_assets > 0) {
88  double threshold;
90  if (EQUITY / risky_assets < threshold){
91  /* instead of keeping whole earnings a portion of earnings
92  that is large enough to satisfy equity ratio is to be used.
93  */
94  double needed;
95  needed = threshold * risky_assets - EQUITY;
96  if (needed < NET_EARNINGS) {
97  RETAINED_EARNINGS = needed;
98  TOTAL_DIVIDENDS = NET_EARNINGS - needed;
99  }
100  else {
102  TOTAL_DIVIDENDS = 0;
103  }
104  }
105  else {
106  RETAINED_EARNINGS = 0;
108  }
109  }
110  else {
111  RETAINED_EARNINGS = 0;
113  if (PRINT_DEBUG_MODE){
114  printf("Total Asset of Bank = %d is Negative or Zero!!!\n", ID);
115  }
116  }
117 
118  if (TOTAL_DIVIDENDS > 0) {
121  if (PRINT_DEBUG_MODE){
122  printf("Bank ID= %d has earnings to send to the Fund. \n", ID);
123  }
124  }
125 
126  return 0; /* Returning zero means the agent is not removed */
127 }
128 
129 /*
130  * \fn: int bank_credit_do_balance_sheet()
131  * \brief: Bank does the balance sheet accounting.
132  * If the bank is out of liquidity it compensates it from the central bank.
133  * If the bank has positive liquidity and debt to central bank, it pays its debt.
134  */
136 {
137  double amount;
138 
139  if (LIQUIDITY < 0) {
140  amount = -1 * LIQUIDITY;
141  CENTRALBANK_DEBT += amount;
142  LIQUIDITY = 0;
144  }
145 
146  if (LIQUIDITY > 0) {
148  amount = CENTRALBANK_DEBT;
149  LIQUIDITY -= amount;
150  CENTRALBANK_DEBT = 0;
152  }
153  else{
154  amount = LIQUIDITY;
155  CENTRALBANK_DEBT -= amount;
156  LIQUIDITY = 0;
158  }
159  }
160 
162 
165 
166  //printf("Bank ID = %d at Balance Sheet, post-liquidity = %f, CB Debt = %f \n", ID, LIQUIDITY, CENTRALBANK_DEBT);
167 
168 
169  /* Added to give households as equal chance as firms at getting bank credits.
170  */
171  LOANS_START = LOANS;
172 
173  if (DATA_COLLECTION_MODE) {
174  char * filename;
175  FILE * file1;
176  filename = malloc(100*sizeof(char));
177  filename[0]=0;
178  strcpy(filename, "./outputs/data/Bank_BalanceSheet.txt");
179 
180  file1 = fopen(filename,"a");
181  fprintf(file1,"%d %d %f %f %f %f %f %f %f\n",IT_NO, ID, TOTAL_ASSETS, LIQUIDITY, LOANS, MORTGAGES, DEPOSITS, CENTRALBANK_DEBT, EQUITY);
182  fclose(file1);
183  free(filename);
184  }
185 
186  return 0; /* Returning zero means the agent is not removed */
187 }
188 
189 
190 /*
191  * \fn: int bank_credit_process_loan_requests_1()
192  * \brief:
193  */
195 {
196  double risk_weighted_assets, amount;
197  int firm;
198 
199  risk_weighted_assets = LOANS + MORTGAGES;
200 
204 
205  if (EQUITY >= CAPITAL_ADEQUECY_RATIO * risk_weighted_assets) {
206  LOANS += amount;
207  LIQUIDITY -= amount;
209 
210  //printf("Bank ID = %d Loan Stage 1: %f --> Firm ID = %d, Current Loans = %f \n", ID, amount, firm, LOANS);
211 
212  if (PRINT_DEBUG_MODE){
213  printf("Bank ID = %d Loan Stage 1: %f --> Firm ID = %d!\n", ID, amount, firm);
214  }
215  }
216  else {
217  //printf("Bank ID = %d at Loan Stage 1: Denies %f for Firm ID = %d, Current Loans = %f \n", ID, amount, firm, LOANS);
218 
219  if (PRINT_DEBUG_MODE){
220  printf("Bank ID = %d at Loan Stage 1: denies a %f amount loan request from Firm ID = %d \n", ID, amount, firm);
221  }
222  }
224 
225 
226  return 0; /* Returning zero means the agent is not removed */
227 }
228 
229 /*
230  * \fn: int bank_credit_process_loan_requests_2()
231  * \brief: Processes requests from a rationed firms.
232  */
234 {
235  double risk_weighted_assets, amount;
236  int firm;
237 
238  risk_weighted_assets = LOANS + MORTGAGES;
239 
243 
244  if (EQUITY >= CAPITAL_ADEQUECY_RATIO * risk_weighted_assets) {
245  LOANS += amount;
246  LIQUIDITY -= amount;
248 
249  //printf("Bank ID = %d Loan Stage 2: %f --> Firm ID = %d, Current Loans = %f \n", ID, amount, firm, LOANS);
250 
251  if (PRINT_DEBUG_MODE){
252  printf("Bank ID = %d Loan Stage 2: %f --> Firm ID = %d!\n", ID, amount, firm);
253  }
254  }
255  else {
256 
257 
258  //printf("Bank ID = %d at Loan Stage 2: Denies %f for Firm ID = %d, Current Loans = %f \n", ID, amount, firm, LOANS);
259 
260  if (PRINT_DEBUG_MODE){
261  printf("Bank ID = %d at Loan Stage 2: denies a %f amount loan request from Firm ID = %d \n", ID, amount, firm);
262  }
263  }
265 
266 
267  return 0; /* Returning zero means the agent is not removed */
268 }
269 
270 /*
271  * \fn: int bank_credit_recieve_loan_writeoffs()
272  * \brief:
273  */
275 {
276  double amount;
277 
280  LIQUIDITY += amount;
281  DEPOSITS -= amount;
283 
284 
286  amount = loan_writeoff_message->amount;
287  LOANS -= amount;
288  TOTAL_WRITEOFFS += amount;
289 
290 
291  //printf("Write off: Bank ID = %d, Amount = %f, Updated Loan = %f \n", ID, amount, LOANS);
292 
293  if (DATA_COLLECTION_MODE) {
294  char * filename;
295  FILE * file1;
296  filename = malloc(100*sizeof(char));
297  filename[0]=0;
298  strcpy(filename, "./outputs/data/BankruptcyInspection.txt");
299  file1 = fopen(filename,"a");
300  fprintf(file1,"%d %d %s %s %d %f\n",IT_NO, ID, "Bank", "Loans", ID, amount);
301  fclose(file1);
302  free(filename);
303  }
305 
306  return 0; /* Returning zero means the agent is not removed */
307 }
308 
309 
310 /*
311  * \fn: int bank_credit_recieve_new_entrant_loan_requests()
312  * \brief:
313  */
315 {
316  double amount;
317 
320  LOANS += amount;
321  LIQUIDITY -= amount;
322 
323  //printf("New entrant: Bank ID = %d, Amount = %f, Updated Loan = %f \n", ID, amount, LOANS);
325 
326  return 0; /* Returning zero means the agent is not removed */
327 }
328 
329 /*
330  * \fn: int bank_credit_collect_loan_interests()
331  * \brief:
332  */
334 {
335  double amount;
336 
339  LIQUIDITY += amount;
340  INTERESTS_ACCRUED += amount;
342 
343  return 0; /* Returning zero means the agent is not removed */
344 }
345 
346 
347 
348