00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027 #include <time.h>
00028
00029 #include "finvar.h"
00030 #include "finproto.h"
00031 #include "fin_spl_protos.h"
00032
00033 amort_sched_ptr amort_opt(
00034 amort_sched_ptr amortsched,
00035 void *parse_env)
00036 {
00037 char buffer[200], *errp;
00038 unsigned long ii;
00039 unsigned prec = amortsched->prec;
00040 var_store value;
00041 numeric_ptr nval;
00042 struct tm *times_E,
00043 *times_I;
00044
00045
00046 times_E = (struct tm *)calloc(1, sizeof(struct tm));
00047 ii = amortsched->Eff_Date_jdn;
00048 times_E->tm_mday = amortsched->day_E;
00049 times_E->tm_mon = amortsched->month_E - 1;
00050 times_E->tm_year = amortsched->year_E - 1900;
00051 times_E->tm_wday = (ii + 1) % 7;
00052 times_E->tm_yday = amortsched->yday_E;
00053
00054 times_I = (struct tm *)calloc(1, sizeof(struct tm));
00055 ii = amortsched->Init_Date_jdn;
00056 times_I->tm_mday = amortsched->day_I;
00057 times_I->tm_mon = amortsched->month_I - 1;
00058 times_I->tm_year = amortsched->year_I - 1900;
00059 times_I->tm_wday = (ii + 1) % 7;
00060 times_I->tm_yday = amortsched->yday_I;
00061
00062 printf("\n******************************");
00063 qof_strftime(buffer, (size_t)50, "%c", times_E);
00064 printf("\nEffective Date: %s\n", buffer);
00065 qof_strftime(buffer, (size_t)50, "%c", times_I);
00066 printf("Initial Payment Date: %s\n", buffer);
00067 free(times_E);
00068 free(times_I);
00069 printf("The Original Present Value (pv) is: %.*f\n", (int)prec, amortsched->pv);
00070 printf("The Original Periodic Payment (pmt) is: %.*f\n", (int)prec, amortsched->pmt);
00071 printf("The Original Future Value (fv) is: %.*f\n", (int)prec, amortsched->fv);
00072
00073 printf("The Delayed Present Value (pve) is: %.*f\n", (int)prec, amortsched->pve);
00074 printf("The New Periodic Payment (pmt) for pve is: %.*f\n\n", (int)prec, amortsched->new_pmt);
00075
00076 printf("The amortization options are:\n");
00077 printf("1 -- Amortize with Original Amount and Constant Payment to Principal: %.*f\n", (int) prec, amortsched->cpmt1);
00078 printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_1);
00079 printf("2 -- Amortize with Delayed Amount and Constant Payment to Principal: %.*f\n", (int)prec, amortsched->cpmt2);
00080 printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_2);
00081 printf("3 -- Amortize with Original Transaction Values\n");
00082 printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_3);
00083 printf("4 -- Amortize with Delayed Amount, Original Periodic Payment\n");
00084 printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_4);
00085 printf("5 -- Amortize with Delayed Amount, New Periodic Payment\n");
00086 printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_5);
00087 if ( amortsched->new_n )
00088 {
00089 printf("6 -- Amortize with Original Amount, Original Periodic Payment,\n");
00090 printf(" new number of total payments (n): %u\n", amortsched->new_n);
00091 printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_6);
00092 }
00093 printf("Enter choice 1, 2, 3, 4, 5 or 6: ");
00094 fgets(buffer, 190, stdin);
00095 amortsched->option = buffer[0] - '0';
00096
00097 printf("Amortization Schedule:\n");
00098 printf("y -- Yearly Summary\n");
00099 printf("p -- Periodic Payment\n");
00100 if ( amortsched->option < 3 )
00101 {
00102 printf("Enter Choice y or p: ");
00103 }
00104 else
00105 {
00106 printf("f -- Fixed Advanced Payment\n");
00107 printf("a -- Variable Advanced Payment\n");
00108 printf("Enter Choice y, p, f or a: ");
00109 }
00110 fgets(buffer, 190, stdin);
00111 amortsched->summary = buffer[0];
00112
00113 if ( amortsched->summary == 'f' )
00114 {
00115 if ( amortsched->fixed_pmt != 0.0 )
00116 {
00117 printf("Current Fixed Prepayment: %.*f\nChange Fixed Prepayment? (y/n): ", (int)prec, amortsched->fixed_pmt);
00118 fgets(buffer, 190, stdin);
00119 }
00120 else
00121 {
00122 buffer[0] = 'y';
00123 }
00124
00125 if ( buffer[0] == 'y' )
00126 {
00127 printf("Enter Fixed Prepayment Amount: ");
00128 fgets(buffer, 190, stdin);
00129 if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
00130 {
00131 nval = (numeric_ptr)(value.value);
00132 switch ( nval->type )
00133 {
00134 case INT_TYPE:
00135 amortsched->fixed_pmt = (double)(nval->value.int_value);
00136 break;
00137 case DBL_TYPE:
00138 amortsched->fixed_pmt = nval->value.dbl_value;
00139 break;
00140 }
00141 if ( !value.variable_name ) free_numeric(value.value);
00142 }
00143 else
00144 {
00145 parse_error(get_parse_error(parse_env), buffer, errp);
00146 }
00147 }
00148 }
00149
00150 return amortsched;
00151 }