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 printf("6 -- Amortize with Original Amount, Original Periodic Payment,\n");
00089 printf(" new number of total payments (n): %u\n",amortsched->new_n);
00090 printf(" and final payment: %.*f\n",(int)prec,amortsched->final_pmt_opt_6);
00091 }
00092 printf("Enter choice 1, 2, 3, 4, 5 or 6: ");
00093 fgets(buffer,190,stdin);
00094 amortsched->option = buffer[0] - '0';
00095
00096 printf("Amortization Schedule:\n");
00097 printf("y -- Yearly Summary\n");
00098 printf("p -- Periodic Payment\n");
00099 if ( amortsched->option < 3 ) {
00100 printf("Enter Choice y or p: ");
00101 } else {
00102 printf("f -- Fixed Advanced Payment\n");
00103 printf("a -- Variable Advanced Payment\n");
00104 printf("Enter Choice y, p, f or a: ");
00105 }
00106 fgets(buffer,190,stdin);
00107 amortsched->summary = buffer[0];
00108
00109 if ( amortsched->summary == 'f' ) {
00110 if ( amortsched->fixed_pmt != 0.0 ) {
00111 printf("Current Fixed Prepayment: %.*f\nChange Fixed Prepayment? (y/n): ",(int)prec,amortsched->fixed_pmt);
00112 fgets(buffer,190,stdin);
00113 } else { buffer[0] = 'y';
00114 }
00115
00116 if ( buffer[0] == 'y' ) {
00117 printf("Enter Fixed Prepayment Amount: ");
00118 fgets(buffer,190,stdin);
00119 if ( (errp = parse_string(&value,buffer,parse_env)) == NULL ) {
00120 nval = (numeric_ptr)(value.value);
00121 switch ( nval->type ) {
00122 case INT_TYPE:
00123 amortsched->fixed_pmt = (double)(nval->value.int_value);
00124 break;
00125 case DBL_TYPE:
00126 amortsched->fixed_pmt = nval->value.dbl_value;
00127 break;
00128 }
00129 if ( !value.variable_name ) free_numeric(value.value);
00130 } else {
00131 parse_error(get_parse_error(parse_env),buffer,errp);
00132 }
00133 }
00134 }
00135
00136 return amortsched;
00137 }