GnuCash 2.4.99
fin-main.c
00001 /***************************************************************************
00002                           fin-main.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 call financial equations and output results
00020  *  6-15-2000
00021  *
00022  */
00023 
00024 #include <stdio.h>
00025 
00026 #include "finvar.h"
00027 #include "finproto.h"
00028 
00029 static void  prt_status(
00030     fi_ptr       fi,
00031     FILE        *ofile);
00032 
00033 int             main(int argc, char **argv, char **env)
00034 {
00035     financial_info  fininfo;
00036     amort_sched     amortsched;
00037 
00038     set_default(&fininfo);
00039     fininfo.prec = 2;
00040 
00041     fininfo.npp = 360;
00042     fininfo.ir = 8.25;
00043     fininfo.pv = 345725.0;
00044 
00045     (void)fi_calc_payment(&fininfo);
00046     printf("With npp == %u\n     ir == %.*f\n     pv == %.*f\n", fininfo.npp, fininfo.prec, fininfo.ir, fininfo.prec, fininfo.pv);
00047     printf("------------>Compute pmt: -2597.32\n");
00048     prt_status(&fininfo,
00049                stdout);
00050 
00051     fi_calc_interest(&fininfo);
00052     printf("\n------------>Compute ir\n");
00053     prt_status(&fininfo,
00054                stdout);
00055 
00056     fi_calc_num_payments(&fininfo);
00057     printf("\n------------>Compute npp\n");
00058     prt_status(&fininfo,
00059                stdout);
00060 
00061     fi_calc_future_value(&fininfo);
00062     printf("\n------------>Compute fv\n");
00063     prt_status(&fininfo,
00064                stdout);
00065 
00066     set_default(&fininfo);
00067 
00068     fininfo.npp = 360;
00069     fininfo.ir = 8.25;
00070     fininfo.pv = 345725.0;
00071     fi_calc_payment(&fininfo);
00072 
00073     printf("\n\n Reset financial variables and compute amortization schedules.\n");
00074     printf("First Schedule - ignore delay in first payment and\noutput annual summary\n");
00075 
00076     amortsched.n = fininfo.npp;
00077     amortsched.nint = fininfo.ir;
00078     amortsched.pv = fininfo.pv;
00079     amortsched.pmt = fininfo.pmt;
00080     amortsched.fv = fininfo.fv;
00081     amortsched.CF = fininfo.CF;
00082     amortsched.PF = fininfo.PF;
00083     amortsched.disc = fininfo.disc;
00084     amortsched.bep = fininfo.bep;
00085     amortsched.prec = fininfo.prec;
00086     amortsched.year_E = 1999;
00087     amortsched.month_E = 6;
00088     amortsched.day_E = 15;
00089     amortsched.year_I = 1999;
00090     amortsched.month_I = 8;
00091     amortsched.day_I = 1;
00092     amortsched.fixed_pmt = -400;
00093 
00094     (void)Amortization_init(&amortsched);
00095 
00096     amortsched.option = 3;
00097     amortsched.summary = 'y';
00098     (void)Amortization_Schedule(&amortsched);
00099     prt_amortization_schedule(&amortsched, stdout);
00100 
00101     printf("\n\nSecond Schedule - ignore delay in first payment and\noutput schedule for each payment\n");
00102     amortsched.summary = 'p';
00103     (void)Amortization_Schedule(&amortsched);
00104     prt_amortization_schedule(&amortsched, stdout);
00105 
00106 
00107     printf("\n\nThird Schedule - ignore delay in first payment and\noutput variable advanced prepayment schedule\n");
00108     amortsched.summary = 'a';
00109     (void)Amortization_Schedule(&amortsched);
00110     prt_amortization_schedule(&amortsched, stdout);
00111 
00112     printf("\n\nFourth Schedule - ignore delay in first payment and\noutput fixed prepayment schedule\n");
00113     amortsched.summary = 'f';
00114     (void)Amortization_Schedule(&amortsched);
00115     prt_amortization_schedule(&amortsched, stdout);
00116 
00117     printf("\n\nFifth Schedule - use new payments due to delay and\noutput annual summary\n");
00118     amortsched.option = 5;
00119     amortsched.summary = 'y';
00120     (void)Amortization_Schedule(&amortsched);
00121     prt_amortization_schedule(&amortsched, stdout);
00122 
00123     printf("\n\nSixth Schedule - use new payments due to delay and\noutput periodic payment schedule\n");
00124     amortsched.option = 5;
00125     amortsched.summary = 'p';
00126     (void)Amortization_Schedule(&amortsched);
00127     prt_amortization_schedule(&amortsched, stdout);
00128 
00129     printf("\n\nSeventh Schedule - use new payments due to delay and\noutput variable prepayment schedule\n");
00130     amortsched.option = 5;
00131     amortsched.summary = 'a';
00132     (void)Amortization_Schedule(&amortsched);
00133     prt_amortization_schedule(&amortsched, stdout);
00134 
00135     printf("\n\nEighth Schedule - use new payments due to delay and\noutput fixed prepayment schedule\n");
00136     amortsched.option = 5;
00137     amortsched.summary = 'f';
00138     (void)Amortization_Schedule(&amortsched);
00139     prt_amortization_schedule(&amortsched, stdout);
00140     Amortization_free(&amortsched);
00141 } /* main */
00142 
00143 static void  prt_status(
00144     fi_ptr       fi,
00145     FILE        *ofile)
00146 {
00147     fprintf(ofile, "<================================>\nCurrent Financial Calculator Status:\n");
00148     fprintf(ofile, "Compounding Frequency: (CF) %u\n", fi->CF);
00149     fprintf(ofile, "Payment     Frequency: (PF) %u\n", fi->PF);
00150     fprintf(ofile, "Compounding: %s\n", fi->disc ? "Discrete (disc = TRUE)" : "Continuous (disc = FALSE)");
00151     fprintf(ofile, "Payments: %s\n", fi->bep ? "Beginning of Period (bep = TRUE)" : "End of Period (bep = FALSE)");
00152     if ( fi->npp > 12 ) fprintf(ofile, "Number of Payment Periods (n): %u\t\t(Years: %u)\n", fi->npp, fi->npp / fi->PF);
00153     else fprintf(ofile, "Number of Payment Periods (n): %u\n", fi->npp);
00154     if ((fi->CF == 1) && (fi->PF == 1) ) fprintf(ofile, "Nominal Interest per Payment Period (i): %f\t(Annualized: %.*f\n", fi->ir, fi->prec, fi->ir * 12);
00155     else fprintf(ofile, "Nominal Annual Interest Rate (i): %.*f\n", fi->prec, fi->ir);
00156     /*    fprintf(ofile, "  Effective Interest Rate Per Payment Period: %f\n",eff_int(nint/100.0,CF,PF));   */
00157     fprintf(ofile, "Present Value (pv): %.*f\n", fi->prec, fi->pv);
00158     fprintf(ofile, "Periodic Payment (pmt): %.*f\n", fi->prec, fi->pmt);
00159     fprintf(ofile, "Future Value (fv): %.*f\n", fi->prec, fi->fv);
00160 }   /* prt_status */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines