home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 4.4 KB | 156 lines | [TEXT/CWIE] |
- // Copyright 1995 © David A. Wilson. All rights reserved.
-
- //====================================================================
- #ifndef _FINANCE_
- #include "Finance.h"
- #endif
-
- #ifndef __FP__
- #include <fp.h> // PowerPC math functions
- #endif
-
- //====================================================================
- // Savings functions
- double
- FutureValue(double presentValue,
- double annualInterestPercent,
- short compoundsPerYear,
- double years)
- {
- // H-P 35 Math Pac, p 96.
- short n = compoundsPerYear * years;
- double i = (annualInterestPercent/100.0) / compoundsPerYear;
- double factor = pow(1.0 + i, n);
- return presentValue * factor;
- }
-
- //-------------------------------------------------------------------
- double
- FutureValueWithPayments(double payment,
- short paymentsPerYear,
- short compoundsPerYear,
- double annualInterestPercent,
- double years)
- {
- // H-P 67/97 Business Decisions Pac, p. B-03
- double Q;
- double n;
- double Z;
- double cOverP = (double)compoundsPerYear/(double)paymentsPerYear;
- double pOverC = (double)paymentsPerYear/(double)compoundsPerYear;
- double i = (annualInterestPercent/100.0) / compoundsPerYear;
- if (pOverC <= 1.0) {
- Q = pow(1.0 + i, cOverP) - 1.0;
- n = paymentsPerYear * years;
- Z = (1.0 + Q);
- }
- else {
- Q = i;
- n = paymentsPerYear * years * cOverP;
- Z = (pOverC + 1.0) * (Q / 2.0) + pOverC;
- }
- double factor = Q / (pow(1.0 + Q, n) - 1);
- return (payment * Z / factor);
- }
-
- //-------------------------------------------------------------------
- double
- AnnuityPresentValue(double payment,
- double annualInterestPercent,
- short paymentsPerYear,
- double years)
- {
- // H-P 67 Standard Pac, p. 05-02
- short n = paymentsPerYear * years;
- double i = (annualInterestPercent/100.0) / paymentsPerYear;
- double factor = 1.0 - pow(1.0 + i, -n);
- return payment * factor / i;
- }
-
- //-------------------------------------------------------------------
- double
- AnnuityMonths(double annuity,
- double monthlyWithdrawal,
- double annualInterestPercent)
- {
- // H-P 67 Standard Pac, p 05-02.
- // annuity = Present Value
- const double kMonthsPerYear = 12.0;
- double i = (annualInterestPercent/100.0) / kMonthsPerYear;
- double factor1 = log( 1.0 - (i * annuity/ monthlyWithdrawal) );
- double factor2 = log( 1.0 + i );
- return - factor1 / factor2;
- }
-
- //-------------------------------------------------------------------
- double
- Payment(double amountBorrowed,
- double annualInterestPercent,
- double years)
- {
- // H-P 67 Standard Pac, p 05-02.
- // amountBorrowed = Present Value
- const double kMonthsPerYear = 12.0;
- short n = kMonthsPerYear * years;
- double i = (annualInterestPercent/100.0) / kMonthsPerYear;
- double factor = 1 - pow(1.0 + i, -n);
- return (i * amountBorrowed) / factor;
- }
-
- //======================================================================
- // Loan functions
- double
- LoanAmount(double monthlyPayment,
- double annualInterestPercent,
- double years)
- {
- // H-P 67 Standard Pac, p 05-02.
- // amountBorrowed = Present Value
- const double kMonthsPerYear = 12.0;
- short n = kMonthsPerYear * years;
- double i = (annualInterestPercent/100.0) / kMonthsPerYear;
- double factor = 1 - pow(1.0 + i, -n);
- return (monthlyPayment / i) * factor;
- }
-
- //-------------------------------------------------------------------
- double
- LoanMonths(double amountBorrowed,
- double monthlyPayment,
- double annualInterestPercent)
- {
- // H-P 67 Standard Pac, p 05-02.
- // amountBorrowed = Present Value
- const double kMonthsPerYear = 12.0;
- double i = (annualInterestPercent/100.0) / kMonthsPerYear;
- double factor1 = log( 1.0 - (i * amountBorrowed/ monthlyPayment) );
- double factor2 = log( 1.0 + i );
- return - factor1 / factor2;
- }
-
- //-------------------------------------------------------------------
- double
- InterestRate(double amountBorrowed,
- double monthlyPayment,
- double years)
- {
- // H-P 67 Standard Pac, p 05-02.
- return 0;
- }
-
- //-------------------------------------------------------------------
- double
- BalloonPayment(double amountBorrowed,
- double monthlyPayment,
- double annualInterestPercent,
- double years)
- {
- // H-P 67 Standard Pac, p 05-06.
- const double kMonthsPerYear = 12.0;
- double i = (annualInterestPercent/100.0) / kMonthsPerYear;
- short n = kMonthsPerYear * years;
- double factor1 = pow(1.0 + i, -n);
- double factor2 = (monthlyPayment / i) * ( 1.0 - factor1);
- return (amountBorrowed - factor2) / factor1;
- }
-