ICEACE Model: Closed Economy  1.0.0
Design Documentation of ICEACE Model
 All Data Structures Files Functions Variables Typedefs Macros Pages
firm_functions_top.c
Go to the documentation of this file.
1 #include "header.h"
2 #include "firm_agent_header.h"
3 #include <math.h>
4 
5 /*
6  * \fn: int firm_init_post_id()
7  * \brief:
8  */
10 {
12 
13  /*** Balancesheet Verification. */
15  char * filename;
16  FILE * file1;
17  filename = malloc(100*sizeof(char));
18  filename[0]=0;
19  strcpy(filename, "./outputs/data/Firm_ID_Liquidity_Loan.txt");
20  file1 = fopen(filename,"w");
21  //fprintf(file1,"%d %f %f\n",ID, LIQUIDITY, DEBT);
22  fclose(file1);
23  free(filename);
24  }
25 
26 
27  return 0; /* Returning zero means the agent is not removed */
28 }
29 
30 /*
31  * \fn: int firm_init_employment()
32  * \brief:
33  */
35 {
36  int new_employee, position;
37 
41  if (position > 0) {
42  MANAGER = new_employee;
43  }
44  add_int(&EMPLOYEES, new_employee);
46 
47 
49 
50 
51  NO_EMPLOYEES = EMPLOYEES.size;
54  DEBT = (NO_EMPLOYEES * WAGE_OFFER * 0.2) / LOANS_INTEREST_RATE;
59  LOAN_LIST[0].amount = DEBT;
60 
61  /* The value is used to set a large (inf) number for regular firms.*/
62  CAPITAL_PRODUCTIVITY = (double) 999999;
63 
64  if (ISCONSTRUCTOR) {
65 
68  SALES = 2;
70  CAPITAL_GOODS = ceil((TOTAL_ASSETS - UNIT_HOUSE_PRICE * INVENTORY - LIQUIDITY)/CAPITAL_GOODS_PRICE);
72 
73  } else {
74 
76  INVENTORY = (int) (PRODUCTION_CURRENT / 10);
79  CAPITAL_GOODS = ceil((TOTAL_ASSETS - UNIT_GOODS_PRICE * INVENTORY - LIQUIDITY)/CAPITAL_GOODS_PRICE);
80  }
81 
85 
86  if (PRINT_DEBUG_MODE) {
87  printf("Firm %d --> Size = %d \n", ID, NO_EMPLOYEES);
88  }
89 
90  return 0; /* Returning zero means the agent is not removed */
91 }
92 
93 /*
94  * \fn: int firm_init_balancesheet()
95  * \brief:
96  */
98 {
99  /*The firms are initiliazed loans only with their preferred banks.
100  */
102 
104 
105  /*** Balancesheet Verification. */
106  if (DATA_COLLECTION_MODE) {
107  char * filename;
108  FILE * file1;
109  filename = malloc(100*sizeof(char));
110  filename[0]=0;
111  strcpy(filename, "./outputs/data/Firm_ID_Liquidity_Loan.txt");
112  file1 = fopen(filename,"a");
113  fprintf(file1,"%d %f %f\n",ID, LIQUIDITY, DEBT);
114  fclose(file1);
115  free(filename);
116 
117  }
118 
119 
120  return 0; /* Returning zero means the agent is not removed */
121 }
122 
123 /*
124  * \fn: int firm_iterate()
125  * \brief:
126  */
128 {
130 
131  if (IT_NO == 0)
132  {
133 
134  char * filename;
135  FILE * file1;
136  filename = malloc(140*sizeof(char));
137 
138  if (ISCONSTRUCTOR) {
139  /* @\fn: firm_production_construction_plan() */
140  filename[0]=0;
141  strcpy(filename, "./outputs/data/Constructor_Firm_Monthly.txt");
142  file1 = fopen(filename,"w");
143  fprintf(file1,"%s %s %s %s %s %s %s %s %s %s\n","IT_NO", "ID", "WAGE_OFFER", "NO_EMPLOYEES", "EMPLOYEES_NEEDED", "SALES", "INVENTORY", "PRODUCTION_CURRENT", "PRODUCTION_PLAN", "UNIT_HOUSE_PRICE");
144  fclose(file1);
145 
146 
147  /* @\fn: firm_credit_compute_income_statement() */
148  filename[0]=0;
149  strcpy(filename, "./outputs/data/Constructor_Firm_Quarterly_IncomeStatement.txt");
150  file1 = fopen(filename,"w");
151  fprintf(file1,"%s %s %s %s %s %s %s %s\n","IT_NO", "ID", "REVENUES", "OPERATING_COSTS", "LABOUR_COSTS", "TOTAL_INTEREST_PAYMENTS", "EBIT", "NET_EARNINGS");
152  fclose(file1);
153 
154 
155  /* @\fn: firm_credit_pay_dividends() */
156  filename[0]=0;
157  strcpy(filename, "./outputs/data/Constructor_Firm_Quarterly_Dividends.txt");
158  file1 = fopen(filename,"w");
159  fprintf(file1,"%s %s %s %s\n","IT_NO", "ID", "DIVIDENDS_PAID", "DIVIDENDS_TO_BE_PAID");
160  fclose(file1);
161 
162  /* @\fn: firm_credit_do_balance_sheet() */
163  filename[0]=0;
164  strcpy(filename, "./outputs/data/Constructor_Firm_Quarterly_BalanceSheet.txt");
165  file1 = fopen(filename,"w");
166  fprintf(file1,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n","IT_NO", "ID", "ISLIQUIDSHORT", "HASLOAN", "HASINVESTMENT", "LIQUIDITY_NEED", "ISINSOLVENT", "ISILLIQUID", "TOTAL_ASSETS", "LIQUIDITY", "INVENTORY", "UNIT_HOUSE_PRICE", "CAPITAL_GOODS_PRICE", "CAPITAL_GOODS", "DEBT", "EQUITY");
167  fclose(file1);
168  }
169  else
170  {
171  /* @\fn: firm_production_plan() */
172  filename[0]=0;
173  strcpy(filename, "./outputs/data/Firm_Monthly.txt");
174  file1 = fopen(filename,"w");
175  fprintf(file1,"%s %s %s %s %s %s %s %s %s %s\n","IT_NO", "ID", "WAGE_OFFER", "NO_EMPLOYEES", "EMPLOYEES_NEEDED", "SALES", "INVENTORY", "PRODUCTION_CURRENT", "PRODUCTION_PLAN", "UNIT_GOODS_PRICE");
176  fclose(file1);
177 
178 
179  /* @\fn: firm_credit_compute_income_statement() */
180  filename[0]=0;
181  strcpy(filename, "./outputs/data/Firm_Quarterly_IncomeStatement.txt");
182  file1 = fopen(filename,"w");
183  fprintf(file1,"%s %s %s %s %s %s %s %s\n","IT_NO", "ID", "REVENUES", "OPERATING_COSTS", "LABOUR_COSTS", "TOTAL_INTEREST_PAYMENTS", "EBIT", "NET_EARNINGS");
184  fclose(file1);
185 
186 
187  /* @\fn: firm_credit_pay_dividends() */
188  filename[0]=0;
189  strcpy(filename, "./outputs/data/Firm_Quarterly_Dividends.txt");
190  file1 = fopen(filename,"w");
191  fprintf(file1,"%s %s %s %s\n","IT_NO", "ID", "DIVIDENDS_PAID", "DIVIDENDS_TO_BE_PAID");
192  fclose(file1);
193 
194  /* @\fn: firm_credit_do_balance_sheet() */
195  filename[0]=0;
196  strcpy(filename, "./outputs/data/Firm_Quarterly_BalanceSheet.txt");
197  file1 = fopen(filename,"w");
198  fprintf(file1,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n","IT_NO", "ID", "ISLIQUIDSHORT", "HASLOAN", "HASINVESTMENT", "LIQUIDITY_NEED","ISINSOLVENT", "ISILLIQUID", "TOTAL_ASSETS", "LIQUIDITY", "INVENTORY", "UNIT_GOODS_PRICE", "CAPITAL_GOODS_PRICE", "CAPITAL_GOODS", "DEBT", "EQUITY");
199  fclose(file1);
200  }
201  free(filename);
202  }
203  }
204 
205 
206  IT_NO++;
207  return 0; /* Returning zero means the agent is not removed */
208 }
209 
210 /*
211  * \fn: int firm_update_bank_account()
212  * \brief: puts money to deposit account of its prefered bak. */
214 {
215  if (LIQUIDITY > 0) {
217  }
218 
219  if (PRINT_DEBUG_MODE) {
220  printf("Firm ID = %d a liquidity amount = %f has deposited to bank.\n", ID, LIQUIDITY);
221  }
222 
223  return 0; /* Returning zero means the agent is not removed */
224 }