-
Notifications
You must be signed in to change notification settings - Fork 1
/
centralbank_functions_top.c
145 lines (112 loc) · 4.61 KB
/
centralbank_functions_top.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "header.h"
#include "centralbank_agent_header.h"
/*
* \fn: int centralbank_init_balancesheet()
* \brief:
*/
int centralbank_init_balancesheet()
{
double amount;
LOANS_BANKS = 0;
START_BANK_CENTRALBANK_INIT_DEBT_MESSAGE_LOOP
LOANS_BANKS += bank_centralbank_init_debt_message->amount;
FINISH_BANK_CENTRALBANK_INIT_DEBT_MESSAGE_LOOP
LIQUIDITY_BANKS = 0;
START_BANK_CENTRALBANK_INIT_DEPOSIT_MESSAGE_LOOP
amount = bank_centralbank_init_deposit_message->amount;
LIQUIDITY_BANKS += amount;
FINISH_BANK_CENTRALBANK_INIT_DEPOSIT_MESSAGE_LOOP
START_GOV_CENTRALBANK_INIT_DEPOSIT_MESSAGE_LOOP
amount = gov_centralbank_init_deposit_message->amount;
LIQUIDITY_GOVERNMENT = amount;
FINISH_GOV_CENTRALBANK_INIT_DEPOSIT_MESSAGE_LOOP
START_FUND_CENTRALBANK_INIT_DEPOSIT_MESSAGE_LOOP
amount = fund_centralbank_init_deposit_message->amount;
LIQUIDITY_EQUITYFUND = amount;
FINISH_FUND_CENTRALBANK_INIT_DEPOSIT_MESSAGE_LOOP
/* Equity Fund liquidity is disregarded. */
LIQUIDITY_EQUITYFUND = 0;
LIQUIDITY = 0;
EQUITY = 0;
LOANS_GOVERNMENT = 0;
TOTAL_WRITEOFFS = 0;
double loans, deposits, liabilities;
loans = LOANS_BANKS + LOANS_GOVERNMENT;
deposits = LIQUIDITY_BANKS + LIQUIDITY_GOVERNMENT + LIQUIDITY_EQUITYFUND;
/* Fiat money in this case equal to firms total loans minus private sector deposits. */
FIAT_MONEY = loans - deposits;
if (FIAT_MONEY < 0) {
LIQUIDITY = -1 * FIAT_MONEY;
FIAT_MONEY = 0;
}
liabilities = FIAT_MONEY + deposits;
TOTAL_ASSETS = loans + LIQUIDITY;
EQUITY = TOTAL_ASSETS - liabilities;
return 0; /* Returning zero means the agent is not removed */
}
/*
* \fn: int centralbank_iterate()
* \brief:
*/
int centralbank_iterate()
{
if (DATA_COLLECTION_MODE) {
if (IT_NO == 0) {
char * filename;
FILE * file1;
/* @/fn: centralbank_do_balance_sheet() */
filename = malloc(100*sizeof(char));
filename[0]=0;
strcpy(filename, "./outputs/data/CentralBank_snapshot.txt");
file1 = fopen(filename,"w");
fprintf(file1,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n","IT_NO", "INTEREST_RATE", "INFLATION_RATE", "REVENUES", "TOTAL_COSTS", "NET_EARNINGS", "TOTAL_ASSETS", "LIQUIDITY", "LOANS_BANKS", "LOANS_GOVERNMENT", "EQUITY","FIAT_MONEY", "LIQUIDITY_BANKS", "LIQUIDITY_GOVERNMENT", "LIQUIDITY_EQUITYFUND");
//fprintf(file1,"%d %f %f %f %f %f %f %f %f %f %f %f %f %f\n",IT_NO, INTEREST_RATE, INFLATION_RATE, REVENUES, TOTAL_COSTS, NET_EARNINGS, TOTAL_ASSETS, LIQUIDITY, LOANS_BANKS, LOANS_GOVERNMENT, EQUITY,FIAT_MONEY, LIQUIDITY_BANKS, LIQUIDITY_GOVERNMENT, LIQUIDITY_EQUITYFUND);
fclose(file1);
free(filename);
}
if (IT_NO == 0) {
char * filename;
FILE * file1;
/* @/fn: () */
filename = malloc(40*sizeof(char));
filename[0]=0;
strcpy(filename, "./outputs/data/BankruptcyInspection.txt");
file1 = fopen(filename,"w");
fprintf(file1,"%s %s %s %s %s %s\n","IT", "ID", "Agent", "Writeoff_Type", "Bank", "Amount");
fclose(file1);
free(filename);
}
}
IT_NO++;
return 0; /* Returning zero means the agent is not removed */
}
/*
* \fn: int centralbank_update_deposits()
* \brief:
*/
int centralbank_update_deposits()
{
double pre, post, delta_deposits;
pre = LIQUIDITY_BANKS + LIQUIDITY_EQUITYFUND + LIQUIDITY_GOVERNMENT;
LIQUIDITY_BANKS = 0;
START_BANK_CENTRALBANK_UPDATE_DEPOSIT_MESSAGE_LOOP
LIQUIDITY_BANKS += bank_centralbank_update_deposit_message->amount;
FINISH_BANK_CENTRALBANK_UPDATE_DEPOSIT_MESSAGE_LOOP
LIQUIDITY_GOVERNMENT = 0;
START_GOV_CENTRALBANK_UPDATE_DEPOSIT_MESSAGE_LOOP
LIQUIDITY_GOVERNMENT = gov_centralbank_update_deposit_message->amount;
FINISH_GOV_CENTRALBANK_UPDATE_DEPOSIT_MESSAGE_LOOP
LIQUIDITY_EQUITYFUND = 0;
START_FUND_CENTRALBANK_UPDATE_DEPOSIT_MESSAGE_LOOP
LIQUIDITY_EQUITYFUND = fund_centralbank_update_deposit_message->amount;
FINISH_FUND_CENTRALBANK_UPDATE_DEPOSIT_MESSAGE_LOOP
post = LIQUIDITY_BANKS + LIQUIDITY_EQUITYFUND + LIQUIDITY_GOVERNMENT;
delta_deposits = post - pre;
LIQUIDITY += delta_deposits;
/* This is where Central Bank prints banknotes. */
if (LIQUIDITY < 0) {
FIAT_MONEY -= LIQUIDITY;
LIQUIDITY = 0;
}
return 0; /* Returning zero means the agent is not removed */
}