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
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
*/
9
int
bank_init_loans
()
10
{
11
LOANS
= 0;
12
13
START_FIRM_BANK_INIT_LOANS_MESSAGE_LOOP
14
LOANS
+=
firm_bank_init_loans_message
->
amount
;
15
FINISH_FIRM_BANK_INIT_LOANS_MESSAGE_LOOP
16
17
return
0;
/* Returning zero means the agent is not removed */
18
}
19
20
/*
21
* \fn: int bank_init_mortgages()
22
* \brief:
23
*/
24
int
bank_init_mortgages
()
25
{
26
MORTGAGES
= 0;
27
28
START_HOUSEHOLD_BANK_INIT_MORTGAGES_MESSAGE_LOOP
29
MORTGAGES
+=
household_bank_init_mortgages_message
->
amount
;
30
FINISH_HOUSEHOLD_BANK_INIT_MORTGAGES_MESSAGE_LOOP
31
32
return
0;
/* Returning zero means the agent is not removed */
33
}
34
35
/*
36
* \fn: int bank_init_deposits()
37
* \brief:
38
*/
39
int
bank_init_deposits
()
40
{
41
double
deposits_households = 0;
42
double
deposits_firms = 0;
43
44
START_HOUSEHOLD_BANK_INIT_DEPOSIT_MESSAGE_LOOP
45
deposits_households +=
household_bank_init_deposit_message
->
amount
;
46
FINISH_HOUSEHOLD_BANK_INIT_DEPOSIT_MESSAGE_LOOP
47
48
START_FIRM_BANK_INIT_DEPOSIT_MESSAGE_LOOP
49
deposits_firms +=
firm_bank_init_deposit_message
->
amount
;
50
FINISH_FIRM_BANK_INIT_DEPOSIT_MESSAGE_LOOP
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
*/
65
int
bank_init_balancesheet
()
66
{
67
68
LIQUIDITY
= (
LOANS
+
MORTGAGES
) * 0.1;
69
TOTAL_ASSETS
=
LOANS
+
MORTGAGES
+
LIQUIDITY
;
70
EQUITY
=
TOTAL_ASSETS
* 0.1;
71
CENTRALBANK_DEBT
=
TOTAL_ASSETS
-
DEPOSITS
-
EQUITY
;
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
;
84
INTERESTS_PAID
=
CENTRALBANK_DEBT
*
INTEREST_RATE
/ 4;
85
86
87
88
add_bank_centralbank_init_debt_message
(
ID
,
CENTRALBANK_DEBT
);
89
90
91
add_bank_centralbank_init_deposit_message
(
ID
,LIQUIDITY);
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
*/
106
int
bank_iterate
()
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. */
152
int
bank_update_deposits
()
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
160
START_HOUSEHOLD_BANK_UPDATE_DEPOSIT_MESSAGE_LOOP
161
deposits_households +=
household_bank_update_deposit_message
->
amount
;
162
FINISH_HOUSEHOLD_BANK_UPDATE_DEPOSIT_MESSAGE_LOOP
163
164
current_deposit = deposits_households;
165
166
START_FIRM_BANK_UPDATE_DEPOSIT_MESSAGE_LOOP
167
deposits_firms +=
firm_bank_update_deposit_message
->
amount
;
168
FINISH_FIRM_BANK_UPDATE_DEPOSIT_MESSAGE_LOOP
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
*/
189
int
bank_update_centralbank_deposit
()
190
{
191
192
add_bank_centralbank_update_deposit_message
(
ID
,
LIQUIDITY
);
193
194
195
return
0;
/* Returning zero means the agent is not removed */
196
}
197
198
Generated on Tue Apr 8 2014 13:25:17 for ICEACE Model: Closed Economy by
1.8.3.1