2 #include "../household_agent_header.h"
3 #include "../library_header.h"
12 double quarterly_income;
53 if (fabs(wealth) <= 0.01){
105 double mortgage_used, liquidity_spent, annuity;
116 if (mortgage_used + liquidity_spent > 0){
119 printf(
"Household ID = %d has bought a new housing unit for %f. \n",
ID, mortgage_used + liquidity_spent);
123 if (liquidity_spent > 0){
127 if (mortgage_used > 0){
128 double quarterly_interest;
129 double quarterly_principal;
131 double used_interest_rate;
136 quarterly_interest = 0;
137 quarterly_principal = 0;
141 quarterly_principal = (mortgage_used / annuity) - quarterly_interest;
147 quarterly_principal = (mortgage_used / 160);
152 quarterly_interest = mortgage_used * 0.02/4;
154 d2 = d1 * pow((1 + d1), 160);
155 annuity = 1/d1 - 1/d2;
156 quarterly_principal = (mortgage_used / annuity) - quarterly_interest;
161 quarterly_interest = mortgage_used * 0.02/4;
162 quarterly_principal = (mortgage_used / 160);
168 quarterly_interest = mortgage_used * used_interest_rate/4;
170 d2 = d1 * pow((1 + d1), 160);
171 annuity = 1/d1 - 1/d2;
172 quarterly_principal = (mortgage_used / annuity) - quarterly_interest;
178 quarterly_interest = mortgage_used * used_interest_rate / 4;
179 quarterly_principal = (mortgage_used / 160);
185 d2 = d1 * pow((1 + d1), 160);
186 annuity = 1/d1 - 1/d2;
189 quarterly_principal = (mortgage_used / annuity) - (mortgage_used * 0.02/4);
194 printf(
"Warning @household_housing_buy(): Unexpected mortgage choice = %d \n",
MORTGAGE_CHOICE);
203 printf(
"Household ID = %d a new mortgage debt of %f. \n",
ID, mortgage_used);
221 double price_difference, price;
242 double price_difference, price;
277 printf(
"Household ID = %d (%d) has gotten a house unit sold for %f \n",
ID,
HMARKET_ROLE, sale_price);
300 double principal, new_principle;
301 double quarterly_interest, new_quarterly_interest;
302 double quarterly_principal, new_quarterly_principal;
346 while (sale_price > 0) {
357 quarterly_principal =
MORTGAGES_LIST.array[0].quarterly_principal;
361 if (principal <= sale_price){
364 sale_price -= principal;
366 printf(
"Fire Seller = %d has removed the mortgage debt = %f \n",
ID, principal);
377 new_principle = principal - sale_price;
380 printf(
"Fire Seller = %d decreases a mortgage debt from = %f to %f \n",
ID, principal, new_principle);
383 new_quarterly_interest = 0;
384 new_quarterly_principal = 0;
387 d2 = d1 * pow((1 + d1), quarters_left);
388 annuity = 1/d1 - 1/d2;
389 new_quarterly_interest = new_principle * d1;
390 new_quarterly_principal = (new_principle / annuity) - new_quarterly_interest;
395 new_quarterly_principal = new_principle / quarters_left;
399 d2 = d1 * pow((1 + d1), quarters_left);
400 annuity = 1/d1 - 1/d2;
402 new_quarterly_interest = new_principle * d1;
403 new_quarterly_principal = (new_principle / annuity) - new_quarterly_interest;
406 new_quarterly_interest = new_principle * rate/4;
407 new_quarterly_principal = new_principle / quarters_left;
411 d2 = d1 * pow((1 + d1), quarters_left);
412 annuity = 1/d1 - 1/d2;
414 new_quarterly_interest = new_principle * d1;
415 new_quarterly_principal = (new_principle / annuity) - new_quarterly_interest;
418 new_quarterly_interest = new_principle * rate/4;
419 new_quarterly_principal = new_principle / quarters_left;
423 d2 = d1 * pow((1 + d1), quarters_left);
424 annuity = 1/d1 - 1/d2;
427 new_quarterly_principal = (new_principle / annuity) - (new_principle * rate/4);
431 printf(
"Warning @household_housing_buy(): Unexpected mortgage choice = %d \n",
MORTGAGE_CHOICE);
436 MORTGAGES_LIST.array[0].quarterly_interest = new_quarterly_interest;
437 MORTGAGES_LIST.array[0].quarterly_principal = new_quarterly_principal;
443 if (sale_price > 0) {
479 if (size == 0){
return 0;}
485 double total_interest_paid = 0;
486 double total_principal_paid = 0;
487 double interest_paid;
488 double principal_paid, principal_left;
490 for (i = 0; i < size; i++) {
496 principal_left =
MORTGAGES_LIST.array[i].principal - principal_paid;
499 total_interest_paid += interest_paid;
500 total_principal_paid += principal_paid;
512 for (i = 0; i < 3; i++) {
547 double pre_mortgages, writeoff;
548 double quarterly_principal, quarterly_interest;
555 filename = malloc(100*
sizeof(
char));
557 strcpy(filename,
"./outputs/data/Household_Monthly_FirstDay.txt");
558 file1 = fopen(filename,
"a");
576 double annuity, d1, d2;
577 double used_interest_rate;
579 for (ind = 0; ind < size; ind++) {
583 quarterly_interest = 0;
584 quarterly_principal = 0;
587 d2 = d1 * pow((1 + d1), 160);
588 annuity = 1/d1 - 1/d2;
591 quarterly_principal = (
MORTGAGES / annuity) - quarterly_interest;
604 d2 = d1 * pow((1 + d1), 160);
605 annuity = 1/d1 - 1/d2;
608 quarterly_principal = (
MORTGAGES / annuity) - quarterly_interest;
621 d2 = d1 * pow((1 + d1), 160);
622 annuity = 1/d1 - 1/d2;
625 quarterly_interest =
MORTGAGES * used_interest_rate / 4;
626 quarterly_principal = (
MORTGAGES / annuity) - quarterly_interest;
640 d2 = d1 * pow((1 + d1), 160);
641 annuity = 1/d1 - 1/d2;
650 printf(
"Warning @household_housing_debt_writeoff(): Unexpected mortgage choice = %d \n",
MORTGAGE_CHOICE);
660 if (writeoff < 0 || MORTGAGES < 0) {
661 printf(
"Warning @household_housing_debt_writeoff(): Unexpected negative values detected, Household = %d, Total income = %f, Mortgage Costs= %f, Writeoff = %f, Pre Mortgage = %f New Mortgage = %f, interest = %f. 50 percent of the mortgage cost will be written off. \n",
ID, total_income,
HOUSING_PAYMENT, writeoff, pre_mortgages, MORTGAGES,
MORTGAGES_INTEREST_RATE);
665 MORTGAGES = pre_mortgages * 0.5;
666 writeoff = pre_mortgages * 0.5;
677 filename = malloc(100*
sizeof(
char));
679 strcpy(filename,
"./outputs/data/BankruptcyInspection.txt");
680 file1 = fopen(filename,
"a");
681 fprintf(file1,
"%d %d %s %s %d %f\n",
IT_NO,
ID,
"Household",
"Mortgage",
BANK_ID, writeoff);
687 printf(
"Household ID = %d, Debts writeoff: %d mortgages affected. Loss on Bank ID = %d amounts to %f \n",
ID, size,
BANK_ID, writeoff);
703 filename = malloc(100*
sizeof(
char));
705 strcpy(filename,
"./outputs/data/Household_Monthly_FirstDay.txt");
706 file1 = fopen(filename,
"a");