wkranec/finance — pull request #14 by wiseleyb (2012-09-10 00:18:22+00:00)
Title: Add Execl's RATE function.  Adding annual_fee to payment calculations (dupe function though - didn't touch yours)

Also made a few tweaks so this works out of the box in Rails/Rails-Console. I couldn't get your examples like 250000.amortize(rate) working (ruby 1.9.3, Rails 3.2.8).

Added tests. All tests pass.

Be happy to do whatever tweaks you want.

== Effective Interest Rate

Implementation of Execl's RATE function

RATE RATE(NPER, PMT, PV, FV, type, guess)
Returns the constant interest rate per period of an annuity.
=> NPER is the total number of periods, during which payments are made (payment period).
=> PMT is the constant payment (annuity) paid during each period.
=> PV is the cash value in the sequence of payments.
=> FV (optional) is the future value, which is reached at the end of the periodic payments.
=> Type (optional) defines whether the payment is due at the beginning (1) or the end (0) of a period.
=> Guess (optional) determines the estimated value of the interest with iterative calculation.
see test/test_effective_interest_rate.rb for examples
adapted from Java code found here: http://www.pcpros.com/software/programming/java/java.shtml
Example:
Finance::EffectiveInterestRate.calc_effective_interest_rate(360, -1433.39, 200000)

== Financial Payments with annual fees

This will return identical results that Finance::Amortization will given annual_fee = 0
Simply adds ability to use annual_fee

Finance::EffectiveInterestRate.calc_payment(principal, rate, periods, annual_fee = 0)