|
GnuCash 2.4.99
|
00001 /*************************************************************************** 00002 amort_prt.c - description 00003 ------------------- 00004 begin : Thursday June 15 2000 00005 email : tboldt@attglobal.net 00006 Author : Terry D. Boldt 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 /* 00019 * Functions to print amortization schedules 00020 * 6-15-2000 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, /* amortization schedule to print */ 00037 FILE *ofile) /* output file */ 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 { 00084 fprintf(ofile, "Interest due to Delayed Intial Payment: %.*f\n", (int)prec, amortsched->delayed_int); 00085 } /* endif */ 00086 00087 free(times_E); 00088 free(times_I); 00089 00090 if ( amortsched->option < 3 ) 00091 { 00092 summary = (summary == 'y') ? 'x' : 'o'; 00093 } /* endif */ 00094 00095 switch ( summary ) 00096 { 00097 case 'a': 00098 /* variable prepayment schedule 00099 */ 00100 fprintf(ofile, "Advanced Prepayment Amortization - Variable Prepayment\n"); 00101 amortyr = amortsched->schedule.first_yr; 00102 for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- ) 00103 { 00104 if ( !jj ) 00105 { 00106 fprintf(ofile, "Pmt * Interest Principal Prepay Total Pmt Balance\n"); 00107 pmtsched = amortyr->payments; 00108 jj = amortyr->num_periods; 00109 } /* endif */ 00110 00111 fprintf(ofile, "%4u %12.*f %12.*f %12.*f %12.*f %12.*f\n", 00112 pmtsched->period_num, 00113 (int)prec, pmtsched->interest, 00114 (int)prec, pmtsched->principal, 00115 (int)prec, pmtsched->advanced_pmt, 00116 (int)prec, pmtsched->total_pmt, 00117 (int)prec, pmtsched->balance); 00118 00119 if ( !--jj ) 00120 { 00121 fprintf(ofile, "Summary for: %u:\n", amortyr->year); 00122 fprintf(ofile, " Interest Paid: %.*f\n", (int)prec, amortyr->interest_pd); 00123 fprintf(ofile, " Principal Paid: %.*f\n", (int)prec, amortyr->principal_pd); 00124 fprintf(ofile, " Year Ending Balance: %.*f\n", (int)prec, amortyr->yr_end_balance); 00125 fprintf(ofile, " Sum of Interest Paid: %.*f\n", (int)prec, amortyr->total_interest_pd); 00126 prst_yr = amortyr; 00127 amortyr = amortyr->next_yr; 00128 } 00129 else 00130 { 00131 pmtsched++; 00132 } /* endif */ 00133 } /* endfor */ 00134 break; 00135 case 'f': 00136 /* fixed prepayment schedule 00137 */ 00138 fprintf(ofile, "Advanced Prepayment Amortization - Fixed Prepayment: %.*f\n", (int)prec, amortsched->fixed_pmt); 00139 amortyr = amortsched->schedule.first_yr; 00140 for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- ) 00141 { 00142 if ( !jj ) 00143 { 00144 fprintf(ofile, "Pmt * Interest Principal Prepay Total Pmt Balance\n"); 00145 pmtsched = amortyr->payments; 00146 jj = amortyr->num_periods; 00147 } /* endif */ 00148 00149 fprintf(ofile, "%4u %12.*f %12.*f %12.*f %12.*f %12.*f\n", 00150 pmtsched->period_num, 00151 (int)prec, pmtsched->interest, 00152 (int)prec, pmtsched->principal, 00153 (int)prec, pmtsched->advanced_pmt, 00154 (int)prec, pmtsched->total_pmt, 00155 (int)prec, pmtsched->balance); 00156 00157 if ( !--jj ) 00158 { 00159 fprintf(ofile, "Summary for: %u:\n", amortyr->year); 00160 fprintf(ofile, " Interest Paid: %.*f\n", (int)prec, amortyr->interest_pd); 00161 fprintf(ofile, " Principal Paid: %.*f\n", (int)prec, amortyr->principal_pd); 00162 fprintf(ofile, " Year Ending Balance: %.*f\n", (int)prec, amortyr->yr_end_balance); 00163 fprintf(ofile, " Sum of Interest Paid: %.*f\n", (int)prec, amortyr->total_interest_pd); 00164 prst_yr = amortyr; 00165 amortyr = amortyr->next_yr; 00166 } 00167 else 00168 { 00169 pmtsched++; 00170 } /* endif */ 00171 } /* endfor */ 00172 break; 00173 case 'o': 00174 /* constant payment to principal 00175 */ 00176 fprintf(ofile, "Constant Payment to Principal: %.*f\n", (int)prec, amortsched->cpmt); 00177 amortyr = amortsched->schedule.first_yr; 00178 for ( j = amortsched->total_periods , jj = 0 ; j && amortyr ; j-- ) 00179 { 00180 if ( !jj ) 00181 { 00182 fprintf(ofile, "Pmt# Interest Total Payment Balance\n"); 00183 pmtsched = amortyr->payments; 00184 jj = amortyr->num_periods; 00185 } /* endif */ 00186 00187 fprintf(ofile, "%4u %12.*f %12.*f %12.*f\n", 00188 pmtsched->period_num, 00189 (int)prec, pmtsched->interest, 00190 (int)prec, pmtsched->total_pmt, 00191 (int)prec, pmtsched->balance); 00192 00193 if ( !--jj ) 00194 { 00195 fprintf(ofile, "Summary for: %u:\n", amortyr->year); 00196 fprintf(ofile, " Interest Paid: %.*f\n", (int)prec, amortyr->interest_pd); 00197 fprintf(ofile, " Principal Paid: %.*f\n", (int)prec, amortyr->principal_pd); 00198 fprintf(ofile, " Year Ending Balance: %.*f\n", (int)prec, amortyr->yr_end_balance); 00199 fprintf(ofile, " Sum of Interest Paid: %.*f\n", (int)prec, amortyr->total_interest_pd); 00200 prst_yr = amortyr; 00201 amortyr = amortyr->next_yr; 00202 } 00203 else 00204 { 00205 pmtsched++; 00206 } /* endif */ 00207 } /* endfor */ 00208 break; 00209 case 'p': 00210 /* normal payment schedule 00211 */ 00212 fprintf(ofile, "Normal Amortization Schedule\n"); 00213 amortyr = amortsched->schedule.first_yr; 00214 for ( j = amortsched->total_periods - 1 , jj = 0 ; j && amortyr ; j-- ) 00215 { 00216 if ( !jj ) 00217 { 00218 fprintf(ofile, amortsched->fv_case ? "Pmt * Interest Balance\n" : "Pmt * Interest Principal Balance\n"); 00219 pmtsched = amortyr->payments; 00220 jj = amortyr->num_periods; 00221 } /* endif */ 00222 00223 if ( fv_case ) 00224 { 00225 fprintf(ofile, "%4u %12.*f %12.*f\n", 00226 pmtsched->period_num, 00227 (int)prec, pmtsched->interest, 00228 (int)prec, pmtsched->balance); 00229 } 00230 else 00231 { 00232 fprintf(ofile, "%4u %12.*f %12.*f %12.*f\n", 00233 pmtsched->period_num, 00234 (int)prec, pmtsched->interest, 00235 (int)prec, pmtsched->principal, 00236 (int)prec, pmtsched->balance); 00237 } /* endif */ 00238 00239 if ( !--jj ) 00240 { 00241 fprintf(ofile, "Summary for: %u:\n", amortyr->year); 00242 fprintf(ofile, " Interest Paid: %.*f\n", (int)prec, amortyr->interest_pd); 00243 if ( !fv_case ) fprintf(ofile, " Principal Paid: %.*f\n", (int)prec, amortyr->principal_pd); 00244 fprintf(ofile, " Year Ending Balance: %.*f\n", (int)prec, amortyr->yr_end_balance); 00245 fprintf(ofile, " Sum of Interest Paid: %.*f\n", (int)prec, amortyr->total_interest_pd); 00246 prst_yr = amortyr; 00247 amortyr = amortyr->next_yr; 00248 } 00249 else 00250 { 00251 pmtsched++; 00252 } /* endif */ 00253 } /* endfor */ 00254 00255 if ( !jj ) 00256 { 00257 fprintf(ofile, amortsched->fv_case ? "Pmt * Interest Balance\n" : "Pmt * Interest Principal Balance\n"); 00258 pmtsched = amortyr->payments; 00259 } /* endif */ 00260 00261 fprintf(ofile, "Final Payment: %.*f\n", (int)prec, amortyr->final_pmt); 00262 00263 if ( fv_case ) 00264 { 00265 fprintf(ofile, "%4u %12.*f %12.*f\n", 00266 pmtsched->period_num, 00267 (int)prec, pmtsched->interest, 00268 (int)prec, pmtsched->balance); 00269 } 00270 else 00271 { 00272 fprintf(ofile, "%4u %12.*f %12.*f %12.*f\n", 00273 pmtsched->period_num, 00274 (int)prec, pmtsched->interest, 00275 (int)prec, pmtsched->principal, 00276 (int)prec, pmtsched->balance); 00277 } /* endif */ 00278 00279 fprintf(ofile, "Summary for: %u:\n", amortyr->year); 00280 fprintf(ofile, " Interest Paid: %.*f\n", (int)prec, amortyr->interest_pd); 00281 if ( !fv_case ) fprintf(ofile, " Principal Paid: %.*f\n", (int)prec, amortyr->principal_pd); 00282 fprintf(ofile, " Year Ending Balance: %.*f\n", (int)prec, amortyr->yr_end_balance); 00283 fprintf(ofile, " Sum of Interest Paid: %.*f\n", (int)prec, amortyr->total_interest_pd); 00284 break; 00285 case 'x': 00286 /* constant payment to principal - annual summary 00287 */ 00288 case 'y': 00289 /* normal payment - annual summary 00290 */ 00291 if ( summary == 'x' ) fprintf(ofile, "Annual Summary - Constant Payment to Principal: %.*f\n", (int)prec, amortsched->cpmt); 00292 else fprintf(ofile, "Annual Summary - Normal Amortization\n"); 00293 fprintf(ofile, "Year Interest Ending Balance\n"); 00294 annual_summary = amortsched->schedule.summary; 00295 for ( j = amortsched->total_periods , jj = 0 ; j ; j-- , jj++ ) 00296 { 00297 fprintf(ofile, "%4u %12.*f %12.*f\n", 00298 annual_summary[jj].year, 00299 (int)prec, annual_summary[jj].interest, 00300 (int)prec, annual_summary[jj].end_balance); 00301 } /* endfor */ 00302 break; 00303 } /* endswitch */ 00304 00305 fprintf(ofile, "\nTotal Interest: %.*f\n", (int)prec, amortsched->total_interest); 00306 00307 } /* prt_amortization_schedule */
1.7.4