amort_prt.c

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         fprintf(ofile,"Interest due to Delayed Intial Payment: %.*f\n",(int)prec,amortsched->delayed_int);
00084     } /* endif */
00085 
00086     free(times_E);
00087     free(times_I);
00088 
00089     if ( amortsched->option < 3 ) {
00090         summary = (summary == 'y') ? 'x' : 'o';
00091     } /* endif */
00092 
00093     switch ( summary ) {
00094         case 'a':
00095                 /* variable prepayment schedule
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                                 } /* endif */
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                 } /* endif */
00125                 } /* endfor */
00126                         break;
00127                 case 'f':
00128                         /* fixed prepayment schedule
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                                 } /* endif */
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                 } /* endif */
00158                 } /* endfor */
00159                         break;
00160                 case 'o':
00161                         /* constant payment to principal
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                                 } /* endif */
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                 } /* endif */
00189                 } /* endfor */                  
00190                         break;
00191                 case 'p':
00192                         /* normal payment schedule
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                                 } /* endif */
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                                 } /* endif */
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                 } /* endif */
00227                 } /* endfor */
00228                 
00229                 if ( !jj ) {
00230                         fprintf(ofile,amortsched->fv_case ? "Pmt *       Interest        Balance\n" : "Pmt *       Interest      Principal        Balance\n");
00231                                 pmtsched = amortyr->payments;
00232                         } /* endif */
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             } /* endif */
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                         /* constant payment to principal - annual summary
00257                          */
00258                 case 'y':
00259                         /* normal payment - annual summary
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                         } /* endfor */
00271                         break;
00272         } /* endswitch */
00273         
00274     fprintf(ofile,"\nTotal Interest: %.*f\n",(int)prec,amortsched->total_interest);
00275 
00276 } /* prt_amortization_schedule */

Generated on Sun Oct 12 05:06:58 2008 for GnuCash by  doxygen 1.5.2