finvar.h

00001 /***************************************************************************
00002  *              -------------------
00003  *    create   : Sat Jun 17 20:14:13 2000
00004  *    copyright: (C) 2000 by Terry D. Boldt
00005  *    email    : tboldt@attglobal.net
00006  *              -------------------
00007  ***************************************************************************/
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 /***************************************************************************
00017  *  Global Financial Variables
00018  *  Sat Jun 17 20:14:13 2000
00019  *
00020  ***************************************************************************/
00021 
00022 #ifndef FINVAR_H
00023 #define FINVAR_H
00024 
00025 #if !defined( EOS )
00026 #define EOS '\x000'
00027 #endif
00028 
00029 #if !defined( TRUE )
00030 #define TRUE (1)
00031 #endif
00032 
00033 #if !defined( FALSE )
00034 #define FALSE (0)
00035 #endif
00036 
00037 #define INT_TYPE    '\x001'
00038 #define DBL_TYPE    '\x002'
00039 
00040 typedef enum
00041 {
00042   PARSER_NO_ERROR = 0,
00043   UNBALANCED_PARENS,
00044   STACK_OVERFLOW,
00045   STACK_UNDERFLOW,
00046   UNDEFINED_CHARACTER,
00047   NOT_A_VARIABLE,
00048   NOT_A_FUNC,
00049   PARSER_OUT_OF_MEMORY,
00050   NUMERIC_ERROR,
00051   EXPRESSION_ERROR,
00052   PARSER_NUM_ERRORS
00053 }
00054 ParseError;
00055 
00056 #define UNUSED_VAR  '\x000'
00057 #define USED_VAR    '\x001'
00058 #define ASSIGNED_TO '\x002'
00059 
00060 #define ADD_OP  '+'
00061 #define SUB_OP  '-'
00062 #define DIV_OP  '/'
00063 #define MUL_OP  '*'
00064 #define ASN_OP  '='
00065 
00066 /* The following structure is used by the expression parser to store
00067  * named and temporary variables.  */
00068 
00069 /* structure used for storing variables - used by expression parser/evaluator
00070  */
00071 typedef struct var_store *var_store_ptr;
00072 
00073 /* the type of entity contained in the var_store */
00074 typedef enum {
00075   VST_NUMERIC = 0,
00076   VST_STRING
00077 } VarStoreType;
00078 
00079 typedef struct var_store
00080 {
00081   char *variable_name;    /* variable name if variable, NULL otherwise       */
00082   char use_flag;          /* flag if variable has been assigned to           */
00083   char assign_flag;       /* flag if variable is used                        */
00084   VarStoreType type;
00085   void *value;            /* pointer to implementation defined numeric value */
00086   var_store_ptr next_var; /* pointer to next variable in linked list         */
00087 }
00088 var_store;
00089 
00090 
00091 /* The following structure is used for the numeric operations
00092  * involving double float and integer arithmetic */
00093 
00094 /* structure used for storing numeric values - used by routines which
00095  * evaluate arithmetic operators '+', '-', '/', '*' */
00096 typedef struct numeric *numeric_ptr;
00097 typedef struct numeric
00098 {
00099   char type;                    /* designates type of value */
00100   union
00101   {
00102     long int int_value;         /* long integer value   */
00103     double dbl_value;           /* double value         */
00104   }
00105   value;
00106 }
00107 numeric;
00108 
00109 /* The following structures are used by the amortization functions for
00110  * storing amortization schedule information */
00111 
00112 /* structure used by amortization routines for storing annual summary
00113  information */
00114 typedef struct yearly_summary *yearly_summary_ptr;
00115 typedef struct yearly_summary
00116 {
00117   unsigned year;
00118   double interest;
00119   double end_balance;
00120 }
00121 yearly_summary;
00122 
00123 /* structure used by amortization routines for storing information on
00124  a single payment */
00125 typedef struct sched_pmt *sched_pmt_ptr;
00126 typedef struct sched_pmt
00127 {
00128   unsigned period_num;
00129   double interest;
00130   double principal;
00131   double advanced_pmt;
00132   double total_pmt;
00133   double balance;
00134 }
00135 sched_pmt;
00136 
00137 /* structure used by amortization routines for storing information on
00138  * payments for a single year */
00139 typedef struct amort_sched_yr *amort_sched_yr_ptr;
00140 typedef struct amort_sched_yr
00141 {
00142   unsigned year;
00143   unsigned num_periods;
00144   sched_pmt_ptr payments;
00145   double interest_pd;
00146   double principal_pd;
00147   double yr_end_balance;
00148   double total_interest_pd;
00149   double final_pmt;
00150   amort_sched_yr_ptr next_yr;
00151 }
00152 amort_sched_yr;
00153 
00154 /* structure used by amortization routines for passing and storing
00155  * infomation on a particular amortization transaction */
00156 typedef struct amort_sched *amort_sched_ptr;
00157 typedef struct amort_sched
00158 {
00159   /* following information set by function calling amortization
00160      functions */
00161   unsigned n;                   /* number of periods                        */
00162   double nint;                  /* nominal interest rate                    */
00163   double pv;                    /* present value                            */
00164   double pmt;                   /* periodic payment                         */
00165   double fv;                    /* future value                             */
00166   unsigned CF;                  /* compounding frequency                    */
00167   unsigned PF;                  /* payment frequency                        */
00168   unsigned disc;                /* discrete/continuous compounding flag     */
00169   unsigned bep;                 /* beginning/end of period payment flag     */
00170   unsigned prec;                /* roundoff precision                       */
00171   unsigned year_E;              /* Effective date - year                    */
00172   unsigned month_E;             /* Effective date - month                   */
00173   unsigned day_E;               /* Effective date - day of month            */
00174   unsigned year_I;              /* Initial payment date - year              */
00175   unsigned month_I;             /* Initial payment date - month             */
00176   unsigned day_I;               /* Initial payment date - day of month      */
00177 
00178 /* following information set by calling function to indicate which
00179  * schedule to compute and which type of schedule */
00180   unsigned option;              /* option flag from 1 to 6 inclusive        */
00181   char summary;                 /* summary flag == 'y', 'p', 'a' or 'f'     */
00182 
00183 /* following information set by amortization functions */
00184   double eint;                  /* effective interest rate                  */
00185   double bp;                    /* float value of bep                       */
00186   double total_interest;        /* total interest paid                  */
00187   unsigned total_periods;       /* total numer of periods in schedule   */
00188   unsigned long yr_pmt;         /* number of payments in first year         */
00189   double final_pmt_opt_1;       /* final payment option 1 */
00190   double final_pmt_opt_2;       /* final payment option 2 */
00191   double final_pmt_opt_3;       /* final payment option 3 */
00192   double final_pmt_opt_4;       /* final payment option 4 */
00193   double final_pmt_opt_5;       /* final payment option 5 */
00194   double final_pmt_opt_6;       /* final payment option 6 */
00195   double final_pmt;             /* final payment          */
00196   double pve;                   /* pv adjusted for delayed initial payment  */
00197   double new_pmt;               /* pmt adjusted for delayed initial payment */
00198   double cpmt;                  /* constant payment to principal            */
00199   double cpmt1;                 /* constant payment to principal, 1st case  */
00200   double cpmt2;                 /* constant payment to principal, 2cd case  */
00201   double delayed_int;           /* interest due to delayed initial payment  */
00202   double fixed_pmt;             /* fixed prepayment amount for amortization */
00203   unsigned new_n;               /* new number of periods to amortize due to
00204                                    delayed intial payment */
00205   unsigned fv_case;             /* fv case flag */
00206   unsigned long Eff_Date_jdn;
00207   unsigned yday_E;
00208   unsigned long Init_Date_jdn;
00209   unsigned yday_I;
00210   union
00211   {
00212     amort_sched_yr_ptr first_yr;
00213     yearly_summary_ptr summary;
00214   }
00215   schedule;
00216 }
00217 amort_sched;
00218 
00219 /* The following structure is used to hold all of the financial
00220  * variables used by the financial calculator */
00221 
00222 /* structure used by financial computation routines to store financial
00223    variables */
00224 typedef struct financial_info *fi_ptr;
00225 typedef struct financial_info
00226 {
00227   double ir;                    /* interest rate            */
00228   double pv;                    /* present value            */
00229   double pmt;                   /* periodic payment         */
00230   double fv;                    /* future value             */
00231 
00232   unsigned npp;                 /* number of payment periods            */
00233   unsigned CF;                  /* Compounding frequency                */
00234   unsigned PF;                  /* payment frequency                    */
00235   unsigned bep;                 /* beginning/end of period payment flag */
00236   /* TRUE  == beginning of period         */
00237   /* FALSE == end of period               */
00238   unsigned disc;                /* discrete/continuous compounding flag */
00239   /* TRUE  == discrete compounding        */
00240   /* FALSE == continuous compounding      */
00241 
00242   /* precision of roundoff for pv, pmt and fv.
00243    * i, Interest not rounded
00244    * n, number of periods rounded to integer value, implicit value of zero, 0
00245    *
00246    * 2 for US Dollars
00247    */
00248   unsigned prec;
00249 }
00250 financial_info;
00251 
00252 typedef struct parser_env *parser_env_ptr;
00253 
00254 #endif

Generated on Mon Sep 8 05:03:55 2008 for GnuCash by  doxygen 1.5.2