00001 /*************************************************************************** 00002 mymoneyfinancialcalculator.h - description 00003 ------------------- 00004 begin : Tue Oct 21 2003 00005 copyright : (C) 2000-2003 by Michael Edwardes 00006 email : mte@users.sourceforge.net 00007 Javier Campos Morales <javi_c@users.sourceforge.net> 00008 Felix Rodriguez <frodriguez@users.sourceforge.net> 00009 John C <thetacoturtle@users.sourceforge.net> 00010 Thomas Baumgart <ipwizard@users.sourceforge.net> 00011 Kevin Tambascio <ktambascio@users.sourceforge.net> 00012 ***************************************************************************/ 00013 00014 /*************************************************************************** 00015 * * 00016 * This program is free software; you can redistribute it and/or modify * 00017 * it under the terms of the GNU General Public License as published by * 00018 * the Free Software Foundation; either version 2 of the License, or * 00019 * (at your option) any later version. * 00020 * * 00021 ***************************************************************************/ 00022 00023 #ifndef MYMONEYFINANCIALCALCULATOR_H 00024 #define MYMONEYFINANCIALCALCULATOR_H 00025 00026 #ifdef HAVE_CONFIG_H 00027 #include <config.h> 00028 #endif 00029 00030 #include <cmath> 00031 // ---------------------------------------------------------------------------- 00032 // QT Includes 00033 00034 // ---------------------------------------------------------------------------- 00035 // KDE Includes 00036 00037 // ---------------------------------------------------------------------------- 00038 // Project Includes 00039 00040 #include <kmymoney/export.h> 00041 00042 #ifdef _GLIBCPP_HAVE_MODFL 00043 #define HAVE_LONG_DOUBLE 1 00044 #endif 00045 00046 #ifndef HAVE_LONG_DOUBLE 00047 #define HAVE_LONG_DOUBLE 0 00048 #endif 00049 00050 #if HAVE_LONG_DOUBLE 00051 #define FCALC_DOUBLE long double 00052 #else 00053 #define FCALC_DOUBLE double 00054 #define modfl(a,b) modf(a,b) 00055 #define roundl(a) round(a) 00056 #define powl(a,b) pow(a,b) 00057 #define expl(a) exp(a) 00058 #define logl(a) log(a) 00059 #define floorl(a) floor(a) 00060 #define fabsl(a) fabs(a) 00061 #endif 00062 00072 class KMYMONEY_EXPORT MyMoneyFinancialCalculator 00073 { 00074 public: 00075 MyMoneyFinancialCalculator(); 00076 ~MyMoneyFinancialCalculator(); 00077 00088 FCALC_DOUBLE numPayments(); 00089 00100 FCALC_DOUBLE payment(); 00101 00112 FCALC_DOUBLE presentValue(); 00113 00124 FCALC_DOUBLE futureValue(); 00125 00136 FCALC_DOUBLE interestRate(); 00137 00162 FCALC_DOUBLE interestDue(void) const; 00163 00171 void setPrec(const unsigned short prec = 2); 00172 00180 void setNpp(const FCALC_DOUBLE npp); 00181 00182 FCALC_DOUBLE npp(void) const { return m_npp; }; 00183 00202 void setPF(const unsigned short PF = 12); 00203 00222 void setCF(const unsigned short CF = 12); 00223 00231 void setBep(const bool bep = false); 00232 00240 void setDisc(const bool disc = true); 00241 00248 void setIr(const FCALC_DOUBLE ir); 00249 00250 FCALC_DOUBLE ir(void) const { return m_ir; }; 00251 00258 void setPv(const FCALC_DOUBLE pv); 00259 00260 FCALC_DOUBLE pv(void) const { return m_pv; }; 00261 00268 void setPmt(const FCALC_DOUBLE pmt); 00269 00270 FCALC_DOUBLE pmt(void) const { return m_pmt; }; 00271 00278 void setFv(const FCALC_DOUBLE fv); 00279 00280 FCALC_DOUBLE fv(void) const { return m_fv; }; 00281 00282 private: 00283 FCALC_DOUBLE eff_int(void) const; 00284 FCALC_DOUBLE nom_int(const FCALC_DOUBLE eint) const; 00285 FCALC_DOUBLE rnd(const FCALC_DOUBLE x) const; 00286 00287 FCALC_DOUBLE _Ax(const FCALC_DOUBLE eint) const; 00288 FCALC_DOUBLE _Bx(const FCALC_DOUBLE eint) const; 00289 FCALC_DOUBLE _Cx(const FCALC_DOUBLE eint) const; 00290 FCALC_DOUBLE _fi(const FCALC_DOUBLE eint) const; 00291 FCALC_DOUBLE _fip(const FCALC_DOUBLE eint) const; 00292 00293 private: 00294 FCALC_DOUBLE m_ir; // nominal interest rate 00295 FCALC_DOUBLE m_pv; // present value 00296 FCALC_DOUBLE m_pmt; // periodic payment 00297 FCALC_DOUBLE m_fv; // future value 00298 FCALC_DOUBLE m_npp; // number of payment periods 00299 00300 unsigned short m_CF; // compounding frequency 00301 unsigned short m_PF; // payment frequency 00302 00303 unsigned short m_prec; // precision for roundoff for pv, pmt and fv 00304 // i is not rounded, n is integer 00305 00306 bool m_bep; // beginning/end of period payment flag 00307 bool m_disc; // discrete/continous compounding flag 00308 00309 unsigned short m_mask; // available value mask 00310 #define PV_SET 0x0001 00311 #define IR_SET 0x0002 00312 #define PMT_SET 0x0004 00313 #define NPP_SET 0x0008 00314 #define FV_SET 0x0010 00315 }; 00316 00317 #endif