2 #include "../reagency_agent_header.h" 
    3 #include "../library_header.h" 
   31     double price, quantity;
 
   32     int fire_seller_attempts = 0;
 
   33     int regular_seller_attempts = 0;
 
   34     int firm_seller_attempts = 0;
 
   37     if (type == 0){firm_seller_attempts++;}
 
   38     else if (type == 2){regular_seller_attempts++;}
 
   39     else if (type == 1){fire_seller_attempts++;}
 
   42             printf(
"Warning @reagency_housing_process(): Unidentifed seller type is dtected! \n");
 
   49     add_hseller(&sellers_list, 
id, price, quantity, type);
 
   53     int bank, mortgage_choice;
 
   62     add_hbuyer(&buyers_list,
id,bank,cash,income,mortgage,mortgage_choice);
 
   71     add_hbank(&banks_list, 
id, cash, risk, 0);
 
   74     if (sellers_list.
size == 0 || buyers_list.
size == 0) {
 
   85         printf(
"\nReal Estate Agency Reports: Day= %d, Buyers = %d, Sellers = %d, Banks = %d \n", 
IT_NO, buyers_list.
size, sellers_list.
size, banks_list.
size);
 
  105     int transaction_quantity = 0;
 
  106     double transaction_volume = 0;
 
  108     int regular_sales = 0;
 
  111         if (sellers_list.
size == 0 ){
break;}
 
  112         if (buyers_list.
size == 0 ){
break;}
 
  119         if (nsold == quantity){
 
  122             transaction_quantity += nsold;
 
  123             transaction_volume += nsold * price;
 
  125             if (type == 0) { firm_sales++;}
 
  126             if (type == 2) { regular_sales++;}
 
  127             if (type == 1) { fire_sales++;}
 
  137                 printf(
"Real Estate Agency Reports: Buyer ID = %d, bought a housing unit for %f right away! \n", 
id, price);
 
  147         if (banks_list.
size == 0 ){
 
  149                 printf(
"Real Estate Agency Reports: No more more banks is available to offer mortgage! \n");
 
  161             if (banks_list.
array[i].
id == bank){
 
  166         } 
while (i < banks_list.
size);
 
  170                 printf(
"Bank of Household ID = %d is not available any more for crediting the mortgage.\n", 
id);
 
  186                 printf(
"Bank ID = %d, was not allowed to give mortgages any more.\n", banks_list.
array[i].
id);
 
  191         double mortgage_request = 0;
 
  193             mortgage_request = price - cash;
 
  195             mortgage_request = price;
 
  199         risk += mortgage_request;
 
  206                 printf(
"Bank ID = %d, was not allowed to give mortgages to Household ID = %d. \n", banks_list.
array[i].
id, 
id);
 
  217         double new_mortgage_cost = 0; 
 
  219         if (mortgage_choice == 1) {
 
  221             d2 = d1 * pow((1 + d1), 160);
 
  222             annuity = 1/d1 - 1/d2;
 
  223             new_mortgage_cost = mortgage_request / annuity;
 
  225         else if (mortgage_choice == 2){
 
  228         else if (mortgage_choice == 3){
 
  231             d2 = d1 * pow((1 + d1), 160);
 
  232             annuity = 1/d1 - 1/d2;
 
  233             new_mortgage_cost = mortgage_request / annuity;
 
  235         else if (mortgage_choice == 4){
 
  237             new_mortgage_cost = (mortgage_request / 160) + (mortgage_request*0.02/4);
 
  239         else if (mortgage_choice == 5){
 
  241             d2 = d1 * pow((1 + d1), 160);
 
  242             annuity = 1/d1 - 1/d2;
 
  243             new_mortgage_cost = mortgage_request / annuity;
 
  245         else if (mortgage_choice == 6){
 
  248         else if (mortgage_choice == 7){
 
  251             d2 = d1 * pow((1 + d1), 160);
 
  252             annuity = 1/d1 - 1/d2;
 
  253             new_mortgage_cost = mortgage_request / annuity;
 
  257                 printf(
"Warning @household_housing_debt_writeoff(): Unexpected mortgage choice = %d \n", mortgage_choice);
 
  263         mortgage += new_mortgage_cost;
 
  268                 printf(
"Household ID = %d mortgage request is denied by Bank ID = %d \n", 
id, banks_list.
array[i].
id);
 
  278             printf(
"Household ID = %d has gotten %f from Bank ID = %d along with her own %f amount of cash. \n", 
id, mortgage_request, banks_list.
array[i].
id, cash);
 
  286     if (nsold > 0 && sellers_list.
size > 0) {
 
  290         transaction_quantity += nsold;
 
  291         transaction_volume += nsold * price;
 
  292         if (type == 0) { firm_sales++;}
 
  293         if (type == 2) { regular_sales++;}
 
  294         if (type == 1) { fire_sales++;}
 
  298     for (
int i = 0; i < banks_list.
size; i++) {
 
  303     if (transaction_quantity > 0) {
 
  311         filename = malloc(100*
sizeof(
char));
 
  313         strcpy(filename, 
"./outputs/data/REAgency_sales.txt");
 
  315         file1 = fopen(filename,
"a");
 
  316         fprintf(file1,
"%d %d %d %d %d %d %d\n",
IT_NO, fire_seller_attempts, regular_seller_attempts, firm_seller_attempts, fire_sales, regular_sales, firm_sales);
 
  347         filename = malloc(40*
sizeof(
char));
 
  349         strcpy(filename, 
"./outputs/data/REAgency_snapshot.txt");
 
  351         file1 = fopen(filename,
"a");
 
  352         fprintf(file1,
"%d %d %f\n",
IT_NO, quantity, price);