ICEACE Model: Closed Economy  1.0.0
Design Documentation of ICEACE Model
 All Data Structures Files Functions Variables Typedefs Macros Pages
household_functions_top.c
Go to the documentation of this file.
1 #include "header.h"
3 
4 
5 /*
6  * \fn: int household_init_post_id()
7  * \brief:
8  */
10 {
11  /*** Balancesheet Verification */
12  char * filename;
13  FILE * file1;
14  filename = malloc(100*sizeof(char));
15  filename[0]=0;
16  strcpy(filename, "./outputs/data/Household_ID_Liquidity_Mortgages.txt");
17  file1 = fopen(filename,"w");
18  //fprintf(file1,"%d %f %f\n", ID, LIQUIDITY, MORTGAGES);
19  fclose(file1);
20  free(filename);
21 
23 
24  return 0; /* Returning zero means the agent is not removed */
25 }
26 
27 /*
28  * \fn: int household_init_employment()
29  * \brief:
30  */
32 {
37 
38  if (MY_EMPLOYER_ID > 0) {WAGE = 5.0;}
39  else {WAGE = 0.0;}
40 
41  for (int i = 0; i < 3; i++) {
42  if (PREVIOUS_WAGES[i] == 0) {
43  PREVIOUS_BENEFITS[i] = 4;
44  } else {
45  PREVIOUS_BENEFITS[i] = 1.5;
46  }
47  }
48 
49 
50  /*** Balancesheet Verification */
51  char * filename;
52  FILE * file1;
53  filename = malloc(100*sizeof(char));
54  filename[0]=0;
55  strcpy(filename, "./outputs/data/Household_ID_Liquidity_Mortgages.txt");
56  file1 = fopen(filename,"a");
57  fprintf(file1,"%d %f %f\n", ID, LIQUIDITY, MORTGAGES);
58  fclose(file1);
59  free(filename);
60 
61 
62  return 0; /* Returning zero means the agent is not removed */
63 }
64 
65 
66 /*
67  * \fn: int household_init_balancesheet()
68  * \brief:
69  */
71 {
72  /* The firms are initiliazed loans only with their preferred banks.
73  */
74  double d1, d2, annuity;
75  double total_income = LABOUR_INCOME + CAPITAL_INCOME;
76  double mortgage_cost_income_ratio = 0.2;
77 
78  if (MORTGAGE_CHOICE == 1) {
79  d1 = MORTGAGES_LIST.array[0].interestrate/4;
80  d2 = d1 * pow((1 + d1), 160);
81  annuity = 1/d1 - 1/d2;
82  MORTGAGES = total_income * mortgage_cost_income_ratio * annuity;
83  for (int i = 0; i < MORTGAGES_LIST.size ; i++) {
84  MORTGAGES_LIST.array[i].principal = MORTGAGES / MORTGAGES_LIST.size;
85  }
86  }
87  else if (MORTGAGE_CHOICE == 2){
88  MORTGAGES = (total_income * mortgage_cost_income_ratio) / (MORTGAGES_LIST.array[0].interestrate / 4 + 1/160);
89  for (int i = 0; i < MORTGAGES_LIST.size ; i++) {
90  MORTGAGES_LIST.array[i].principal = MORTGAGES / MORTGAGES_LIST.size;
91  }
92  }
93  else if (MORTGAGE_CHOICE == 3){
94  d1 = 0.02/4;
95  d2 = d1 * pow((1 + d1), 160);
96  annuity = 1/d1 - 1/d2;
97  MORTGAGES = total_income * mortgage_cost_income_ratio * annuity;
98  for (int i = 0; i < MORTGAGES_LIST.size ; i++) {
99  MORTGAGES_LIST.array[i].principal = MORTGAGES / MORTGAGES_LIST.size;
100  MORTGAGES_LIST.array[i].interestrate = 0.02;
101  }
102  }
103  else if (MORTGAGE_CHOICE == 4){
104  MORTGAGES = (total_income * mortgage_cost_income_ratio) / (0.02 / 4 + 1/160);
105  for (int i = 0; i < MORTGAGES_LIST.size ; i++) {
106  MORTGAGES_LIST.array[i].principal = MORTGAGES / MORTGAGES_LIST.size;
107  MORTGAGES_LIST.array[i].interestrate = 0.02;
108  }
109  }
110  else if (MORTGAGE_CHOICE == 5){
111  d1 = (MORTGAGES_LIST.array[0].interestrate + 0.01)/4;
112  d2 = d1 * pow((1 + d1), 160);
113  annuity = 1/d1 - 1/d2;
114  MORTGAGES = total_income * mortgage_cost_income_ratio * annuity;
115  for (int i = 0; i < MORTGAGES_LIST.size ; i++) {
116  MORTGAGES_LIST.array[i].principal = MORTGAGES / MORTGAGES_LIST.size;
117  MORTGAGES_LIST.array[i].interestrate += 0.01;
118  }
119  }
120  else if (MORTGAGE_CHOICE == 6){
121  MORTGAGES = (total_income * mortgage_cost_income_ratio) / ((MORTGAGES_LIST.array[0].interestrate + 0.01) / 4 + 1/160);
122  for (int i = 0; i < MORTGAGES_LIST.size ; i++) {
123  MORTGAGES_LIST.array[i].principal = MORTGAGES / MORTGAGES_LIST.size;
124  MORTGAGES_LIST.array[i].interestrate += 0.01;
125  }
126  }
127  else if (MORTGAGE_CHOICE == 7){
128  d1 = 0.02/4;
129  d2 = d1 * pow((1 + d1), 160);
130  annuity = 1/d1 - 1/d2;
131  MORTGAGES = total_income * mortgage_cost_income_ratio * annuity / (1 + (annuity * 0.02/4));
132  }
133  else {
134  if (WARNING_MODE) {
135  printf("Warning @household_housing_debt_writeoff(): Unexpected mortgage choice = %d \n", MORTGAGE_CHOICE);
136  }
137 
138  }
139 
140 
143 
146 
147  //if (MORTGAGE_CHOICE == 3 || MORTGAGE_CHOICE == 4 || MORTGAGE_CHOICE == 7){
148  // for (int i = 0; i < MORTGAGES_LIST.size ; i++) {
149  // MORTGAGES_LIST.array[i].interestrate = 0.02;
150  // }
151  //}
152  //else if (MORTGAGE_CHOICE == 5 || MORTGAGE_CHOICE == 6) {
153  // for (int i = 0; i < MORTGAGES_LIST.size; i++) {
154  // MORTGAGES_LIST.array[i].interestrate += 0.01;
155  // }
156  //}
157 
158  return 0; /* Returning zero means the agent is not removed */
159 }
160 
161 /*
162  * \fn: int household_iterate()
163  * \brief: Resumes its regular functions.
164  */
166 {
168  if (IT_NO == 0) {
169  char * filename;
170  FILE * file1;
171  filename = malloc(100*sizeof(char));
172 
173  /* Writing the column names. Make sure that an household with that ID does exist. */
174  if (ID == 542) {
175 
176  /* @\fn: int household_consumption_recieve_goods() */
177  filename[0]=0;
178  strcpy(filename, "./outputs/data/Household_Weekly.txt");
179  file1 = fopen(filename,"w");
180  fprintf(file1,"%s %s %s %s %s %s %s\n","IT_NO", "ID", "LIQUIDITY", "WEEKLY_CONSUMPTION_BUDGET", "money_to_spend", "money_spent", "quantity_bought");
181  //fprintf(file1,"%d %d %f %f %f %f %d\n",IT_NO, ID, LIQUIDITY, WEEKLY_CONSUMPTION_BUDGET, 0.0, 0.0, 0);
182  fclose(file1);
183 
184  /* @\fn: household_housing_debt_writeoff() */
185  filename[0]=0;
186  strcpy(filename, "./outputs/data/Household_Monthly_FirstDay.txt");
187  file1 = fopen(filename,"w");
188  fprintf(file1,"%s %s %s %s %s %s %s %s\n", "IT_NO", "ID", "MORTGAGES", "MORTGAGE_COST", "HOUSING_UNITS", "HOUSING_VALUE", "EQUITY_RATIO", "LIQUIDITY");
189  //fprintf(file1,"%d %d %f %f %d %f %f %f\n",IT_NO, ID, MORTGAGES, MORTGAGE_COSTS[0], HOUSING_UNITS, HOUSING_VALUE, EQUITY_RATIO, LIQUIDITY);
190  fclose(file1);
191 
192  /* @\fn: int household_credit_collect_benefits() */
193  filename[0]=0;
194  strcpy(filename, "./outputs/data/Household_Monthly_LastDay.txt");
195  file1 = fopen(filename,"w");
196  fprintf(file1,"%s %s %s %s %s %s\n","IT_NO", "ID", "MY_EMPLOYER_ID", "WAGE", "unemployment_benefit", "general_benefit");
197  //fprintf(file1,"%d %d %d %f %f %f\n",IT_NO, ID, MY_EMPLOYER_ID, WAGE, 0.0, 0.0);
198  fclose(file1);
199 
200  /* @\fn: int household_credit_do_balance_sheet() */
201  filename[0]=0;
202  strcpy(filename, "./outputs/data/Household_Quarterly.txt");
203  file1 = fopen(filename,"w");
204  fprintf(file1,"%s %s %s %s %s %s %s %s %s %s %s\n","IT_NO", "ID", "TOTAL_ASSETS", "LIQUIDITY", "HOUSING_VALUE", "LABOUR_INCOME", "BENEFITS", "CAPITAL_INCOME", "MORTGAGES", "HOUSING_PAYMENT", "EQUITY");
205  //fprintf(file1,"%d %d %f %f %f %f %f %f %f %f %f\n",IT_NO, ID, TOTAL_ASSETS, LIQUIDITY, HOUSING_VALUE, LABOUR_INCOME, GOVERNMENT_BENEFITS, CAPITAL_INCOME, MORTGAGES, HOUSING_PAYMENT, EQUITY);
206  fclose(file1);
207 
208  free(filename);
209  }
210  }
211  }
212 
213  IT_NO++;
214  return 0; /* Returning zero means the agent is not removed */
215 }
216 
217 /*
218  * \fn: int household_update_bank_account()
219  * \brief: puts money to deposit account of its prefered bak. */
221 {
222  if (LIQUIDITY > 0) {
224  }
225 
226  if (PRINT_DEBUG_MODE) {
227  if (ID > 40 && ID < 60) {
228  printf("Household ID = %d has a liquidity amount = %f deposited to bank.\n", ID, LIQUIDITY);
229  }
230 
231  }
232  return 0; /* Returning zero means the agent is not removed */
233 }