Functions
The NPFinancial package contains functions for calculating present value / future value, payment amount, and different types of interest rates.
Present/Future Value
NPFinancial.pv
— Functionpv(rate::Real, nper::Integer, pmt::Real, fv = 0.0, when = :end)
Compute the present value given the future value fv
, an interest rate rate
and a fixed periodic payment pmt
over a number of periods nper
. The payment is expected to be paid at the beginning of each period (:begin
) or :end
of the period, as specified in the when
argument.
NPFinancial.fv
— Functionfv(rate::Real, nper::Integer, pmt::Real, pv::Real, when = :end)
Compute the future value given the present value pv
, an interest rate rate
that is compounded once per period, over nper
number of periods. A fixed payment pmt
may be specified in the when
argument, which is paid either at the beginning of each period (:begin
) or :end
of the period.
Examples
julia> fv(0.05, 1, 0, -100)
105.0
julia> fv(0.05, 2, 0, -100)
110.25
NPFinancial.npv
— Functionnpv(rate::Real, values::AbstractVector{<:Real})
Compute the Net Present Value (NPV) of a cash flow series values
given an internal rate of return rate
.
The (fixed) time interval between cash flow "events" must be the same as that for which rate
is given (i.e., if rate
is per year, then precisely a year is understood to elapse between each cash flow event). By convention, investments or "deposits" are negative, income or "withdrawals" are positive; values
must begin with the initial investment, thus values[1]
will typically be negative.
Examples
julia> npv(0.281,[-100, 39, 59, 55, 20])
-0.00847859163845488
Reference
- L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed., Addison-Wesley, 2003, pg. 346.
Payments
NPFinancial.ipmt
— Functionipmt(rate::Real, per::Integer, nper::Integer, pv::Real, fv = 0.0, when = :end)
Compute the interest component of the periodic payment. This useful for any loan that has a repayment schedule.
Examples
Let's say I have need to repay a mortage loan with amount 300000 (present value) with monthly interst rate of 4.25% over the next 30 years. What would be the interest component of my monthly payment? Initially, the interest component is a large part of the payment but towards the end, it would be a smaller portion as illustrated below for periods 1, 2, 3, 358, 359, and 360:
julia> pmt(0.0425/12, 30*12, 300000)
-1475.8196732384283
julia> ipmt.(0.0425/12, [1,2,3,358,359,360], 30*12, 300000)
6-element Array{Float64,1}:
-1062.5
-1061.04
-1059.57
-15.5702
-10.3984
-5.20841
NPFinancial.ppmt
— Functionppmt(rate, per, nper, pv, fv = 0.0, when = :end)
Compute the principal component of the periodic payment. This useful for any loan that has a repayment schedule.
Examples
julia> pmt(0.0425/12, 30*12, 300000)
-1475.8196732384283
julia> ppmt.(0.0425/12, [1,2,3,358,359,360], 30*12, 300000)
6-element Array{Float64,1}:
-413.32
-414.784
-416.253
-1460.25
-1465.42
-1470.61
NPFinancial.pmt
— Functionpmt(rate::Real, nper::Integer, pv::Real, fv = 0.0, when = :end)
Compute the payment given the present value pv
, an interest rate rate
that is compounded once per period, over nper
number of periods, such that at the end of the last period the value becomes fv
. The payment is expected to be paid at the beginning of each period (:begin
) or :end
of the period, as specified in the when
argument.
Examples
Let's say I have need to repay a mortage loan with amount 300000 (present value) with monthly interst rate of 4.25% over the next 30 years. What would be my monthly payment?
julia> pmt(0.0425/12, 30*12, 300000)
-1475.8196732384283
Rates
NPFinancial.rate
— Functionrate(nper::Integer, pmt::Real, pv::Real, fv::Real, when=:end, guess=0.1, tol=1e-6, maxiter=100)
Compute interest rate given present value pv
, future value fv
, and fixed periodic payment pmt
over a number of periods nper
.
This implementation uses Newton's iteration until the change is less than 1e-6. Newton's rule is
$r_{n+1} = r_{n} - g(r_n)/g'(r_n)$
where
- g(r) is the formula
- g'(r) is the derivative with respect to r.
Examples
julia> rate(1, 0, -100, 101)
0.010000000000000155
NPFinancial.irr
— Function irr(values::Real)
Calculate internal rate of return given an array of cash flow values
(nearest one first)
Examples
julia> irr([-100, 101])
0.010000000000000009
NPFinancial.mirr
— Functionmirr(values::AbstractVector{<:Real}, finance_rate::Real, reinvest_rate::Real)
Compute the modified internal rate of return (MIRR) given a series of cash flows, a finance_rate
(interest rate paid on the cash flows) and reinvest_rate
(interest rate received on the cash flows upon reinvestment).
Miscellaneous
NPFinancial.nper
— Functionnper(rate::Real, pmt::Real, pv::Real, fv = 0.0, when = :end)
Compute how many periods the present value pv
may accrue/repaid till the future value fv
given a specific interest rate rate
and a fixed payment pmt
. The payment is expected to be paid at the beginning of each period (:begin
) or :end
of the period, as specified in the when
argument.