ICEACE Model: Closed Economy
1.0.0
Design Documentation of ICEACE Model
Main Page
Related Pages
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Macros
Pages
IceaceModel1.0
Market_Credit
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
*/
8
int
bank_credit_check_interest_rate
()
9
{
10
11
START_INTEREST_RATE_MESSAGE_LOOP
12
INTEREST_RATE
=
interest_rate_message
->
rate
;
13
FINISH_INTEREST_RATE_MESSAGE_LOOP
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
*/
36
int
bank_credit_compute_income_statement
()
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;
43
INTERESTS_PAID
=
CENTRALBANK_DEBT
*
INTEREST_RATE
/ 4;
44
LIQUIDITY
-=
INTERESTS_PAID
;
45
add_bank_centralbank_interest_payment_message
(
ID
,
INTERESTS_PAID
);
46
47
REVENUES
=
INTERESTS_ACCRUED
;
48
TOTAL_COSTS
=
TOTAL_WRITEOFFS
+
INTERESTS_PAID
;
49
NET_EARNINGS
=
REVENUES
-
TOTAL_COSTS
;
50
51
if
(
DATA_COLLECTION_MODE
) {
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
64
INTERESTS_ACCRUED
= 0;
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
*/
75
int
bank_credit_compute_dividends
()
76
{
77
78
if
(
NET_EARNINGS
<= 0) {
79
TOTAL_DIVIDENDS
= 0;
80
RETAINED_EARNINGS
= 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;
89
threshold =
CAPITAL_ADEQUECY_RATIO
+
CAR_BUFFER_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
{
101
RETAINED_EARNINGS
=
NET_EARNINGS
;
102
TOTAL_DIVIDENDS
= 0;
103
}
104
}
105
else
{
106
RETAINED_EARNINGS
= 0;
107
TOTAL_DIVIDENDS
=
NET_EARNINGS
;
108
}
109
}
110
else
{
111
RETAINED_EARNINGS
= 0;
112
TOTAL_DIVIDENDS
=
NET_EARNINGS
;
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) {
119
LIQUIDITY
-=
TOTAL_DIVIDENDS
;
120
add_bank_net_profit_message
(
ID
,
TOTAL_DIVIDENDS
);
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
*/
135
int
bank_credit_do_balance_sheet
()
136
{
137
double
amount;
138
139
if
(
LIQUIDITY
< 0) {
140
amount = -1 *
LIQUIDITY
;
141
CENTRALBANK_DEBT
+= amount;
142
LIQUIDITY
= 0;
143
add_bank_centralbank_debt_request_message
(
ID
, amount);
144
}
145
146
if
(
LIQUIDITY
> 0) {
147
if
(
LIQUIDITY
>
CENTRALBANK_DEBT
){
148
amount =
CENTRALBANK_DEBT
;
149
LIQUIDITY
-= amount;
150
CENTRALBANK_DEBT
= 0;
151
add_bank_centralbank_debt_payment_message
(
ID
, amount);
152
}
153
else
{
154
amount =
LIQUIDITY
;
155
CENTRALBANK_DEBT
-= amount;
156
LIQUIDITY
= 0;
157
add_bank_centralbank_debt_payment_message
(
ID
, amount);
158
}
159
}
160
161
add_bank_centralbank_update_deposit_message
(
ID
,
LIQUIDITY
);
162
163
TOTAL_ASSETS
=
LIQUIDITY
+
LOANS
+
MORTGAGES
;
164
EQUITY
=
TOTAL_ASSETS
-
DEPOSITS
-
CENTRALBANK_DEBT
;
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
*/
194
int
bank_credit_process_loan_requests_1
()
195
{
196
double
risk_weighted_assets, amount;
197
int
firm;
198
199
risk_weighted_assets =
LOANS
+
MORTGAGES
;
200
201
START_FIRM_BANK_LOAN_REQUEST_1_MESSAGE_LOOP
202
amount =
firm_bank_loan_request_1_message
->
amount
;
203
firm =
firm_bank_loan_request_1_message
->
firm_id
;
204
205
if
(
EQUITY
>=
CAPITAL_ADEQUECY_RATIO
* risk_weighted_assets) {
206
LOANS
+= amount;
207
LIQUIDITY
-= amount;
208
add_bank_firm_loan_acknowledge_1_message
(
ID
, firm, 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
}
223
FINISH_FIRM_BANK_LOAN_REQUEST_1_MESSAGE_LOOP
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
*/
233
int
bank_credit_process_loan_requests_2
()
234
{
235
double
risk_weighted_assets, amount;
236
int
firm;
237
238
risk_weighted_assets =
LOANS
+
MORTGAGES
;
239
240
START_FIRM_BANK_LOAN_REQUEST_2_MESSAGE_LOOP
241
amount =
firm_bank_loan_request_2_message
->
amount
;
242
firm =
firm_bank_loan_request_2_message
->
firm_id
;
243
244
if
(
EQUITY
>=
CAPITAL_ADEQUECY_RATIO
* risk_weighted_assets) {
245
LOANS
+= amount;
246
LIQUIDITY
-= amount;
247
add_bank_firm_loan_acknowledge_2_message
(
ID
, firm, 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
}
264
FINISH_FIRM_BANK_LOAN_REQUEST_2_MESSAGE_LOOP
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
*/
274
int
bank_credit_recieve_loan_writeoffs
()
275
{
276
double
amount;
277
278
START_FIRM_BANK_INSOLVENT_ACCOUNT_MESSAGE_LOOP
279
amount =
firm_bank_insolvent_account_message
->
liquidity
;
280
LIQUIDITY
+= amount;
281
DEPOSITS
-= amount;
282
FINISH_FIRM_BANK_INSOLVENT_ACCOUNT_MESSAGE_LOOP
283
284
285
START_LOAN_WRITEOFF_MESSAGE_LOOP
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
}
304
FINISH_LOAN_WRITEOFF_MESSAGE_LOOP
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
*/
314
int
bank_credit_recieve_new_entrant_loan_requests
()
315
{
316
double
amount;
317
318
START_NEW_ENTRANT_LOAN_MESSAGE_LOOP
319
amount =
new_entrant_loan_message
->
amount
;
320
LOANS
+= amount;
321
LIQUIDITY
-= amount;
322
323
//printf("New entrant: Bank ID = %d, Amount = %f, Updated Loan = %f \n", ID, amount, LOANS);
324
FINISH_NEW_ENTRANT_LOAN_MESSAGE_LOOP
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
*/
333
int
bank_credit_collect_loan_interests
()
334
{
335
double
amount;
336
337
START_FIRM_BANK_INTEREST_ON_LOAN_MESSAGE_LOOP
338
amount =
firm_bank_interest_on_loan_message
->
amount
;
339
LIQUIDITY
+= amount;
340
INTERESTS_ACCRUED
+= amount;
341
FINISH_FIRM_BANK_INTEREST_ON_LOAN_MESSAGE_LOOP
342
343
return
0;
/* Returning zero means the agent is not removed */
344
}
345
346
347
348
Generated on Tue Apr 8 2014 13:25:19 for ICEACE Model: Closed Economy by
1.8.3.1