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 #include <mcheck.h>
00029
00030 #include "finvar.h"
00031 #include "finproto.h"
00032 #include "fin_spl_protos.h"
00033
00034
00035 void prt_amortization_schedule(
00036 amort_sched_ptr amortsched,
00037 FILE *ofile)
00038 {
00039 unsigned j,
00040 jj,
00041 prec = amortsched->prec,
00042 option = amortsched->option,
00043 fv_case = amortsched->fv_case;
00044 unsigned char datel[100],
00045 summary = amortsched->summary;
00046 struct tm *times_E,
00047 *times_I;
00048 amort_sched_yr_ptr amortyr,
00049 prst_yr;
00050 sched_pmt_ptr pmtsched = NULL;
00051 yearly_summary_ptr annual_summary;
00052
00053 times_E = (struct tm *)calloc(1,sizeof(struct tm));
00054 times_E->tm_mday = amortsched->day_E;
00055 times_E->tm_mon = amortsched->month_E - 1;
00056 times_E->tm_year = amortsched->year_E - 1900;
00057 times_E->tm_wday = (amortsched->Eff_Date_jdn + 1) % 7;
00058 times_E->tm_yday = amortsched->yday_E;
00059
00060 times_I = (struct tm *)calloc(1,sizeof(struct tm));
00061 times_I->tm_mday = amortsched->day_I;
00062 times_I->tm_mon = amortsched->month_I - 1;
00063 times_I->tm_year = amortsched->year_I - 1900;
00064 times_I->tm_wday = (amortsched->Init_Date_jdn + 1) % 7;
00065 times_I->tm_yday = amortsched->yday_I;
00066
00067 fprintf(ofile,"Amortization Table\n");
00068 qof_strftime(datel,(size_t)100,"%c",times_E);
00069 fprintf(ofile,"Effective Date: %s\n",datel);
00070 qof_strftime(datel,(size_t)100,"%c",times_I);
00071 fprintf(ofile,"Initial Payment Date: %s\n",datel);
00072 fprintf(ofile,"Compounding Frequency per year: %u\n",amortsched->CF);
00073 fprintf(ofile,"Payment Frequency per year: %u\n",amortsched->PF);
00074 fprintf(ofile,"Compounding: %s\n",(amortsched->disc ? "Discrete" : "Continuous"));
00075 fprintf(ofile,"Payments: %s\n",(amortsched->bep ? "Beginning of Period" : "End of Period"));
00076 fprintf(ofile,"Payments (%u): %.*f\n",amortsched->n - 1,(int)prec,(option < 3) ? amortsched->cpmt : (option == 5) ? amortsched->new_pmt : amortsched->pmt);
00077 fprintf(ofile,"Final payment (%u): %.*f\n",amortsched->n,(int)prec,amortsched->final_pmt);
00078 if ( (amortsched->CF == 1) && (amortsched->PF == 1) ) fprintf(ofile,"Nominal Interest per Payment Period: %g\t(Annualized: %g)\n",amortsched->nint,amortsched->nint * 12);
00079 else fprintf(ofile,"Nominal Annual Interest Rate: %g\n",amortsched->nint);
00080 fprintf(ofile," Effective Interest Rate Per Payment Period: %g\n",amortsched->eint);
00081 fprintf(ofile,"Present Value: %.*f\n",(int)prec,amortsched->pv);
00082 if ( (amortsched->option == 2) || (amortsched->option > 3) ) {
00083 fprintf(ofile,"Interest due to Delayed Intial Payment: %.*f\n",(int)prec,amortsched->delayed_int);
00084 }
00085
00086 free(times_E);
00087 free(times_I);
00088
00089 if ( amortsched->option < 3 ) {
00090 summary = (summary == 'y') ? 'x' : 'o';
00091 }
00092
00093 switch ( summary ) {
00094 case 'a':
00095
00096
00097 fprintf(ofile,"Advanced Prepayment Amortization - Variable Prepayment\n");
00098 amortyr = amortsched->schedule.first_yr;
00099 for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- ) {
00100 if ( !jj ) {
00101 fprintf(ofile,"Pmt * Interest Principal Prepay Total Pmt Balance\n");
00102 pmtsched = amortyr->payments;
00103 jj = amortyr->num_periods;
00104 }
00105
00106 fprintf(ofile,"%4u %12.*f %12.*f %12.*f %12.*f %12.*f\n",
00107 pmtsched->period_num,
00108 (int)prec,pmtsched->interest,
00109 (int)prec,pmtsched->principal,
00110 (int)prec,pmtsched->advanced_pmt,
00111 (int)prec,pmtsched->total_pmt,
00112 (int)prec,pmtsched->balance);
00113
00114 if ( !--jj ) {
00115 fprintf(ofile,"Summary for: %u:\n",amortyr->year);
00116 fprintf(ofile," Interest Paid: %.*f\n",(int)prec,amortyr->interest_pd);
00117 fprintf(ofile," Principal Paid: %.*f\n",(int)prec,amortyr->principal_pd);
00118 fprintf(ofile," Year Ending Balance: %.*f\n",(int)prec,amortyr->yr_end_balance);
00119 fprintf(ofile," Sum of Interest Paid: %.*f\n",(int)prec,amortyr->total_interest_pd);
00120 prst_yr = amortyr;
00121 amortyr = amortyr->next_yr;
00122 } else {
00123 pmtsched++;
00124 }
00125 }
00126 break;
00127 case 'f':
00128
00129
00130 fprintf(ofile,"Advanced Prepayment Amortization - Fixed Prepayment: %.*f\n",(int)prec,amortsched->fixed_pmt);
00131 amortyr = amortsched->schedule.first_yr;
00132 for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- ) {
00133 if ( !jj ) {
00134 fprintf(ofile,"Pmt * Interest Principal Prepay Total Pmt Balance\n");
00135 pmtsched = amortyr->payments;
00136 jj = amortyr->num_periods;
00137 }
00138
00139 fprintf(ofile,"%4u %12.*f %12.*f %12.*f %12.*f %12.*f\n",
00140 pmtsched->period_num,
00141 (int)prec,pmtsched->interest,
00142 (int)prec,pmtsched->principal,
00143 (int)prec,pmtsched->advanced_pmt,
00144 (int)prec,pmtsched->total_pmt,
00145 (int)prec,pmtsched->balance);
00146
00147 if ( !--jj ) {
00148 fprintf(ofile,"Summary for: %u:\n",amortyr->year);
00149 fprintf(ofile," Interest Paid: %.*f\n",(int)prec,amortyr->interest_pd);
00150 fprintf(ofile," Principal Paid: %.*f\n",(int)prec,amortyr->principal_pd);
00151 fprintf(ofile," Year Ending Balance: %.*f\n",(int)prec,amortyr->yr_end_balance);
00152 fprintf(ofile," Sum of Interest Paid: %.*f\n",(int)prec,amortyr->total_interest_pd);
00153 prst_yr = amortyr;
00154 amortyr = amortyr->next_yr;
00155 } else {
00156 pmtsched++;
00157 }
00158 }
00159 break;
00160 case 'o':
00161
00162
00163 fprintf(ofile,"Constant Payment to Principal: %.*f\n",(int)prec,amortsched->cpmt);
00164 amortyr = amortsched->schedule.first_yr;
00165 for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- ) {
00166 if ( !jj ) {
00167 fprintf(ofile,"Pmt# Interest Total Payment Balance\n");
00168 pmtsched = amortyr->payments;
00169 jj = amortyr->num_periods;
00170 }
00171
00172 fprintf(ofile,"%4u %12.*f %12.*f %12.*f\n",
00173 pmtsched->period_num,
00174 (int)prec,pmtsched->interest,
00175 (int)prec,pmtsched->total_pmt,
00176 (int)prec,pmtsched->balance);
00177
00178 if ( !--jj ) {
00179 fprintf(ofile,"Summary for: %u:\n",amortyr->year);
00180 fprintf(ofile," Interest Paid: %.*f\n",(int)prec,amortyr->interest_pd);
00181 fprintf(ofile," Principal Paid: %.*f\n",(int)prec,amortyr->principal_pd);
00182 fprintf(ofile," Year Ending Balance: %.*f\n",(int)prec,amortyr->yr_end_balance);
00183 fprintf(ofile," Sum of Interest Paid: %.*f\n",(int)prec,amortyr->total_interest_pd);
00184 prst_yr = amortyr;
00185 amortyr = amortyr->next_yr;
00186 } else {
00187 pmtsched++;
00188 }
00189 }
00190 break;
00191 case 'p':
00192
00193
00194 fprintf(ofile,"Normal Amortization Schedule\n");
00195 amortyr = amortsched->schedule.first_yr;
00196 for ( j = amortsched->total_periods - 1 , jj = 0 ; j && amortyr ; j-- ) {
00197 if ( !jj ) {
00198 fprintf(ofile,amortsched->fv_case ? "Pmt * Interest Balance\n" : "Pmt * Interest Principal Balance\n");
00199 pmtsched = amortyr->payments;
00200 jj = amortyr->num_periods;
00201 }
00202
00203 if ( fv_case ) {
00204 fprintf(ofile,"%4u %12.*f %12.*f\n",
00205 pmtsched->period_num,
00206 (int)prec,pmtsched->interest,
00207 (int)prec,pmtsched->balance);
00208 } else {
00209 fprintf(ofile,"%4u %12.*f %12.*f %12.*f\n",
00210 pmtsched->period_num,
00211 (int)prec,pmtsched->interest,
00212 (int)prec,pmtsched->principal,
00213 (int)prec,pmtsched->balance);
00214 }
00215
00216 if ( !--jj ) {
00217 fprintf(ofile,"Summary for: %u:\n",amortyr->year);
00218 fprintf(ofile," Interest Paid: %.*f\n",(int)prec,amortyr->interest_pd);
00219 if ( !fv_case ) fprintf(ofile," Principal Paid: %.*f\n",(int)prec,amortyr->principal_pd);
00220 fprintf(ofile," Year Ending Balance: %.*f\n",(int)prec,amortyr->yr_end_balance);
00221 fprintf(ofile," Sum of Interest Paid: %.*f\n",(int)prec,amortyr->total_interest_pd);
00222 prst_yr = amortyr;
00223 amortyr = amortyr->next_yr;
00224 } else {
00225 pmtsched++;
00226 }
00227 }
00228
00229 if ( !jj ) {
00230 fprintf(ofile,amortsched->fv_case ? "Pmt * Interest Balance\n" : "Pmt * Interest Principal Balance\n");
00231 pmtsched = amortyr->payments;
00232 }
00233
00234 fprintf(ofile,"Final Payment: %.*f\n",(int)prec,amortyr->final_pmt);
00235
00236 if ( fv_case ) {
00237 fprintf(ofile,"%4u %12.*f %12.*f\n",
00238 pmtsched->period_num,
00239 (int)prec,pmtsched->interest,
00240 (int)prec,pmtsched->balance);
00241 } else {
00242 fprintf(ofile,"%4u %12.*f %12.*f %12.*f\n",
00243 pmtsched->period_num,
00244 (int)prec,pmtsched->interest,
00245 (int)prec,pmtsched->principal,
00246 (int)prec,pmtsched->balance);
00247 }
00248
00249 fprintf(ofile,"Summary for: %u:\n",amortyr->year);
00250 fprintf(ofile," Interest Paid: %.*f\n",(int)prec,amortyr->interest_pd);
00251 if ( !fv_case ) fprintf(ofile," Principal Paid: %.*f\n",(int)prec,amortyr->principal_pd);
00252 fprintf(ofile," Year Ending Balance: %.*f\n",(int)prec,amortyr->yr_end_balance);
00253 fprintf(ofile," Sum of Interest Paid: %.*f\n",(int)prec,amortyr->total_interest_pd);
00254 break;
00255 case 'x':
00256
00257
00258 case 'y':
00259
00260
00261 if ( summary == 'x' ) fprintf(ofile,"Annual Summary - Constant Payment to Principal: %.*f\n",(int)prec,amortsched->cpmt);
00262 else fprintf(ofile,"Annual Summary - Normal Amortization\n");
00263 fprintf(ofile,"Year Interest Ending Balance\n");
00264 annual_summary = amortsched->schedule.summary;
00265 for ( j = amortsched->total_periods , jj = 0 ; j ; j-- , jj++ ) {
00266 fprintf(ofile,"%4u %12.*f %12.*f\n",
00267 annual_summary[jj].year,
00268 (int)prec,annual_summary[jj].interest,
00269 (int)prec,annual_summary[jj].end_balance);
00270 }
00271 break;
00272 }
00273
00274 fprintf(ofile,"\nTotal Interest: %.*f\n",(int)prec,amortsched->total_interest);
00275
00276 }