GnuCash 2.4.99
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 {
00076     VST_NUMERIC = 0,
00077     VST_STRING
00078 } VarStoreType;
00079 
00080 typedef struct var_store
00081 {
00082     char *variable_name;          /* variable name if variable, NULL otherwise       */
00083     char use_flag;        /* flag if variable has been assigned to           */
00084     char assign_flag;     /* flag if variable is used                        */
00085     VarStoreType type;
00086     void *value;                  /* pointer to implementation defined numeric value */
00087     var_store_ptr next_var; /* pointer to next variable in linked list         */
00088 }
00089 var_store;
00090 
00091 
00092 /* The following structure is used for the numeric operations
00093  * involving double float and integer arithmetic */
00094 
00095 /* structure used for storing numeric values - used by routines which
00096  * evaluate arithmetic operators '+', '-', '/', '*' */
00097 typedef struct numeric *numeric_ptr;
00098 typedef struct numeric
00099 {
00100     char type;                  /* designates type of value */
00101     union
00102     {
00103         long int int_value;             /* long integer value   */
00104         double dbl_value;               /* double value         */
00105     }
00106     value;
00107 }
00108 numeric;
00109 
00110 /* The following structures are used by the amortization functions for
00111  * storing amortization schedule information */
00112 
00113 /* structure used by amortization routines for storing annual summary
00114  information */
00115 typedef struct yearly_summary *yearly_summary_ptr;
00116 typedef struct yearly_summary
00117 {
00118     unsigned year;
00119     double interest;
00120     double end_balance;
00121 }
00122 yearly_summary;
00123 
00124 /* structure used by amortization routines for storing information on
00125  a single payment */
00126 typedef struct sched_pmt *sched_pmt_ptr;
00127 typedef struct sched_pmt
00128 {
00129     unsigned period_num;
00130     double interest;
00131     double principal;
00132     double advanced_pmt;
00133     double total_pmt;
00134     double balance;
00135 }
00136 sched_pmt;
00137 
00138 /* structure used by amortization routines for storing information on
00139  * payments for a single year */
00140 typedef struct amort_sched_yr *amort_sched_yr_ptr;
00141 typedef struct amort_sched_yr
00142 {
00143     unsigned year;
00144     unsigned num_periods;
00145     sched_pmt_ptr payments;
00146     double interest_pd;
00147     double principal_pd;
00148     double yr_end_balance;
00149     double total_interest_pd;
00150     double final_pmt;
00151     amort_sched_yr_ptr next_yr;
00152 }
00153 amort_sched_yr;
00154 
00155 /* structure used by amortization routines for passing and storing
00156  * infomation on a particular amortization transaction */
00157 typedef struct amort_sched *amort_sched_ptr;
00158 typedef struct amort_sched
00159 {
00160     /* following information set by function calling amortization
00161        functions */
00162     unsigned n;                 /* number of periods                        */
00163     double nint;                        /* nominal interest rate                    */
00164     double pv;                  /* present value                            */
00165     double pmt;                 /* periodic payment                         */
00166     double fv;                  /* future value                             */
00167     unsigned CF;                        /* compounding frequency                    */
00168     unsigned PF;                        /* payment frequency                        */
00169     unsigned disc;              /* discrete/continuous compounding flag     */
00170     unsigned bep;                       /* beginning/end of period payment flag     */
00171     unsigned prec;              /* roundoff precision                       */
00172     unsigned year_E;            /* Effective date - year                    */
00173     unsigned month_E;           /* Effective date - month                   */
00174     unsigned day_E;             /* Effective date - day of month            */
00175     unsigned year_I;            /* Initial payment date - year              */
00176     unsigned month_I;           /* Initial payment date - month             */
00177     unsigned day_I;             /* Initial payment date - day of month      */
00178 
00179     /* following information set by calling function to indicate which
00180      * schedule to compute and which type of schedule */
00181     unsigned option;            /* option flag from 1 to 6 inclusive        */
00182     char summary;                       /* summary flag == 'y', 'p', 'a' or 'f'     */
00183 
00184     /* following information set by amortization functions */
00185     double eint;                        /* effective interest rate                  */
00186     double bp;                  /* float value of bep                       */
00187     double total_interest;      /* total interest paid                  */
00188     unsigned total_periods;     /* total numer of periods in schedule   */
00189     unsigned long yr_pmt;               /* number of payments in first year         */
00190     double final_pmt_opt_1;     /* final payment option 1 */
00191     double final_pmt_opt_2;     /* final payment option 2 */
00192     double final_pmt_opt_3;     /* final payment option 3 */
00193     double final_pmt_opt_4;     /* final payment option 4 */
00194     double final_pmt_opt_5;     /* final payment option 5 */
00195     double final_pmt_opt_6;     /* final payment option 6 */
00196     double final_pmt;           /* final payment          */
00197     double pve;                 /* pv adjusted for delayed initial payment  */
00198     double new_pmt;             /* pmt adjusted for delayed initial payment */
00199     double cpmt;                        /* constant payment to principal            */
00200     double cpmt1;                       /* constant payment to principal, 1st case  */
00201     double cpmt2;                       /* constant payment to principal, 2cd case  */
00202     double delayed_int;         /* interest due to delayed initial payment  */
00203     double fixed_pmt;           /* fixed prepayment amount for amortization */
00204     unsigned new_n;             /* new number of periods to amortize due to
00205                                    delayed intial payment */
00206     unsigned fv_case;           /* fv case flag */
00207     unsigned long Eff_Date_jdn;
00208     unsigned yday_E;
00209     unsigned long Init_Date_jdn;
00210     unsigned yday_I;
00211     union
00212     {
00213         amort_sched_yr_ptr first_yr;
00214         yearly_summary_ptr summary;
00215     }
00216     schedule;
00217 }
00218 amort_sched;
00219 
00220 /* The following structure is used to hold all of the financial
00221  * variables used by the financial calculator */
00222 
00223 /* structure used by financial computation routines to store financial
00224    variables */
00225 typedef struct financial_info *fi_ptr;
00226 typedef struct financial_info
00227 {
00228     double ir;                  /* interest rate            */
00229     double pv;                  /* present value            */
00230     double pmt;                 /* periodic payment         */
00231     double fv;                  /* future value             */
00232 
00233     unsigned npp;                       /* number of payment periods            */
00234     unsigned CF;                        /* Compounding frequency                */
00235     unsigned PF;                        /* payment frequency                    */
00236     unsigned bep;                       /* beginning/end of period payment flag */
00237     /* TRUE  == beginning of period         */
00238     /* FALSE == end of period               */
00239     unsigned disc;              /* discrete/continuous compounding flag */
00240     /* TRUE  == discrete compounding        */
00241     /* FALSE == continuous compounding      */
00242 
00243     /* precision of roundoff for pv, pmt and fv.
00244      * i, Interest not rounded
00245      * n, number of periods rounded to integer value, implicit value of zero, 0
00246      *
00247      * 2 for US Dollars
00248      */
00249     unsigned prec;
00250 }
00251 financial_info;
00252 
00253 typedef struct parser_env *parser_env_ptr;
00254 
00255 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines