ICEACE Model: Closed Economy  1.0.0
Design Documentation of ICEACE Model
 All Data Structures Files Functions Variables Typedefs Macros Pages
household_functions_credit.c
Go to the documentation of this file.
1 #include "../header.h"
2 #include "../household_agent_header.h"
3 
4 /*
5  * \fn: int household_credit_check_interest_rate()
6  * \brief: Household hecks quarterly interest rate and
7  * sets the mortgage interest rates accordingly.
8  */
10 {
11 
13  /* 2 percent increase determined by the model. */
15 
17 
18  return 0; /* Returning zero means the agent is not removed */
19 }
20 
21 /*
22  * \fn: int household_credit_check_tax_rate()
23  * \brief:
24  */
26 {
30 
31  return 0; /* Returning zero means the agent is not removed */
32 }
33 
34 /*
35  * \fn: int household_credit_update_mortgage_rates()
36  * \brief:
37  */
39 {
40  int size, i, quarters_left;
41  //mortgage mort;
42  //init_mortgage(&mort);
43  double principal;
44 
45  size = MORTGAGES_LIST.size;
46  i = 0;
47 
48  while (i < size) {
49  //mort = MORTGAGES_LIST.array[i];
50  //principal = mort.principal;
51  principal = MORTGAGES_LIST.array[i].principal;
52  quarters_left = MORTGAGES_LIST.array[i].quarters_left;
53 
54  if (principal < 0.1) {
56  size--;
57  continue;
58  }
59 
60  if (quarters_left == 0){
61  if (principal >= 0.1) {
62  MORTGAGES_LIST.array[i].quarters_left = 1;
63  if (WARNING_MODE) {
64  printf("Warning @household_credit_update_mortgage_rates(): Mortgage life is over but the debt is not finished! Household = %d, The mortgage = %f\n", ID, principal);
65  }
66  }
67  else{
69  size--;
70  continue;
71  }
72  }
73  i++;
74  }
75 
76  size = MORTGAGES_LIST.size;;
77  if (size == 0) {
78  //free_mortgage(&mort);
79  return 0;
80  }
81 
82  double new_quarterly_interest;
83  double new_quarterly_principal, quarterly_principal;
84  double annuity;
85  double d1, d2;
86  double rate;
87 
88  new_quarterly_interest = 0;
89  new_quarterly_principal = 0;
91 
92  for (i = 0; i < size; i++) {
93  //mort = MORTGAGES_LIST.array[i];
94  //principal = mort.principal;
95  //quarters_left = mort.quarters_left - 1;
96  //rate = mort.interestrate;
97 
98  principal = MORTGAGES_LIST.array[i].principal;
99  quarters_left = MORTGAGES_LIST.array[i].quarters_left - 1;
100  rate = MORTGAGES_LIST.array[i].interestrate;
101  quarterly_principal = MORTGAGES_LIST.array[i].quarterly_principal;
102 
103 
104  if (MORTGAGE_CHOICE == 1) {
106  d2 = d1 * pow((1 + d1), quarters_left);
107  annuity = 1/d1 - 1/d2;
108  new_quarterly_interest = principal * d1;
109  new_quarterly_principal = (principal / annuity) - new_quarterly_interest;
110 
111  }
112  else if (MORTGAGE_CHOICE == 2){
113  new_quarterly_interest = principal * MORTGAGES_INTEREST_RATE / 4;
114  new_quarterly_principal = quarterly_principal;
115  }
116  else if (MORTGAGE_CHOICE == 3){
117  d1 = rate/4;
118  d2 = d1 * pow((1 + d1), quarters_left);
119  annuity = 1/d1 - 1/d2;
120  principal = principal * (1 + QUARTERLY_PRICE_CHANGE);
121 
122  new_quarterly_interest = principal * d1;
123  new_quarterly_principal = (principal / annuity) - new_quarterly_interest;
124  }
125  else if (MORTGAGE_CHOICE == 4){
126  principal = principal * (1 + QUARTERLY_PRICE_CHANGE);
127  new_quarterly_interest = principal * rate/4;
128  new_quarterly_principal = principal / quarters_left;
129  }
130  else if (MORTGAGE_CHOICE == 5){
131  d1 = rate/4;
132  d2 = d1 * pow((1 + d1), quarters_left);
133  annuity = 1/d1 - 1/d2;
134 
135  new_quarterly_interest = principal * d1;
136  new_quarterly_principal = principal / annuity - new_quarterly_interest;
137  }
138  else if (MORTGAGE_CHOICE == 6){
139  new_quarterly_interest = principal * rate/4;
140  new_quarterly_principal = quarterly_principal;
141  }
142  /* MORTGAGE_CHOICE 7 is a mortgage where indexation is paid right away */
143  else if (MORTGAGE_CHOICE == 7){
144  d1 = rate/4;
145  d2 = d1 * pow((1 + d1), quarters_left);
146  annuity = 1/d1 - 1/d2;
147  /* Interest payement includes index adjustment */
148  new_quarterly_interest = principal * rate/4 + principal * QUARTERLY_PRICE_CHANGE;
149  new_quarterly_principal = (principal / annuity) - (principal * rate/4);
150  }
151  else {
152  if (WARNING_MODE) {
153  printf("Warning @household_housing_buy(): Unexpected mortgage choice = %d \n", MORTGAGE_CHOICE);
154  }
155  }
156 
157  MORTGAGES_LIST.array[i].quarters_left = quarters_left;
158  MORTGAGES_LIST.array[i].quarterly_interest = new_quarterly_interest;
159  MORTGAGES_LIST.array[i].quarterly_principal = new_quarterly_principal;
160  MORTGAGES_LIST.array[i].principal = principal;
161 
162  EXPECTED_HOUSING_PAYMENT += new_quarterly_interest + new_quarterly_principal;
163  }
164 
165  //free_mortgage(&mort);
166  return 0; /* Returning zero means the agent is not removed */
167 }
168 
169 /*
170  * \fn: int household_credit_collect_shares()
171  * \brief: Collecting shares from the firms via Equity Fund.
172  */
174 {
175 
176  CAPITAL_INCOME = 0;
177 
181 
182  return 0; /* Returning zero means the agent is not removed */
183 }
184 
185 
186 /*
187  * \fn: int household_credit_do_balance_sheet()
188  * \brief:
189  */
191 {
192  /* Updating value of housing assets.
193  It is up to date. Update is done monthly.
194  */
195  // HOUSING_VALUE = HOUSING_UNITS * HOUSING_PRICE;
196 
197  /* Liquidity contains labour incomes. */
200 
202  char * filename;
203  FILE * file1;
204  filename = malloc(100*sizeof(char));
205  filename[0]=0;
206  strcpy(filename, "./outputs/data/Household_Quarterly.txt");
207 
208  file1 = fopen(filename,"a");
209  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);
210  fclose(file1);
211  free(filename);
212  }
213 
214  /* Shares are liquidified. */
216 
217  return 0; /* Returning zero means the agent is not removed */
218 }
219 
220 /*
221  * \fn: int household_credit_collect_benefits()
222  * \brief: Collect general transfer benefits and/or unemployment benefits from the government.
223  */
225 {
226  double general_benefit = 0;
227 
229  general_benefit = general_benefit_message->amount;
230  LIQUIDITY += general_benefit;
231  GOVERNMENT_BENEFITS = general_benefit;
233 
234  double unemployment_benefit = 0;
235 
236  if (MY_EMPLOYER_ID == 0) {
238  unemployment_benefit = unemployment_benefit_message->amount;
239  LIQUIDITY += unemployment_benefit;
240  GOVERNMENT_BENEFITS += unemployment_benefit;
242  }
243 
244  /* Updating history of benefits */
248 
250  char * filename;
251  FILE * file1;
252  filename = malloc(100*sizeof(char));
253  filename[0]=0;
254  strcpy(filename, "./outputs/data/Household_Monthly_LastDay.txt");
255  file1 = fopen(filename,"a");
256  fprintf(file1,"%d %d %d %f %f %f\n",IT_NO, ID, MY_EMPLOYER_ID, WAGE, unemployment_benefit, general_benefit);
257  fclose(file1);
258  free(filename);
259  }
260 
261  return 0; /* Returning zero means the agent is not removed */
262 }
263 
264