# Macro Library finance2

Financial Functions. Version 1. October 2020

Author: Amir Tavangar

Humber College, Toronto, ON
To import the library, include loadlibrary("finance2") in the common control.
The functions in this library can be used to compute almost all compound and annuity problems as well as different business investment-decision methods such as

- Simple, general, ordinary annuities, and annuity due
- Net present value (NPV) method
- Internal Rate of Return (IRR) method
- Interest and principal portions of payments in an amortization schedule
- TVM() function, which includes an iframe of a TVM solver in problems capable of computing all types of annuities

List of functions:

- fin_FV: Future value
- fin_PV: Present value
- fin_PMT: Payment
- fin_Nper: Number of payments
- fin_IY: Interest rate per year
- fin_iPMT: Interest portion of payment
- fin_pPMT: Principal portion of payment
- fin_IRR: Internal rate of return
- fin_NPV: Net present value
- fin_DBD: Days between dates
- fin_TVMs: Time-Value-of-Money solver

fin_FV(IY, Nper, PMT, PY, CY, [PV, type])
Function fin_FV computes the future value of a loan or investment based on a constant annual interest rate.

Parameters:

- IY: Nominal interest rate per year as a percent; for example, 2.35 should be entered for a nominal rate of 2.35%.
- Nper: Total number of payments (for annuities) or compounding periods (for compound interest) in the loan/investment term.
- PMT: The size of periodic payment; should be entered as a negative value for cash outflow and positive value for cash inflow.
- PY: The number of payments per year. Should be the same value as CY for compound interest problems where PMT=0; should be entered 1 for annual payments, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- CY: The number of interest compounding periods per year; should be entered 1 for compounded annually, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- PV: Optional - The present value (principal) of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow; default = 0.
- type: Optional - The type of annuity. Should be entered 1 for an annuity due and 0 (default) for a general annuity.

Returns

The future value of a loan or investment: a positive value for cash inflow and a negative value for cash outflow.

fin_PV(IY, Nper, PMT, PY, CY, [FV, type])
Function fin_PV computes the present value (principal) of a loan or investment based on a constant annual interest rate.

Parameters:

- IY: Nominal interest rate per year as a percent; for example, 2.35 should be entered for a nominal rate of 2.35%.
- Nper: Total number of payments (for annuities) or compounding periods (for compound interest) in the loan/investment term.
- PMT: The size of periodic payment; should be entered as a negative value for cash outflow and positive value for cash inflow.
- PY: The number of payments per year. Should be the same value as CY for compound interest problems where PMT=0; should be entered 1 for annual payments, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- CY: The number of interest compounding periods per year; should be entered 1 for compounded annually, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- FV: Optional - The future value of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow; default = 0.
- type: Optional - The type of annuity. Should be entered 1 for an annuity due and 0 (default) for a general annuity.

Returns

The present value of a loan or investment: a positive value for cash inflow and a negative value for cash outflow.

fin_PMT(IY, Nper, PV, PY, CY, [FV, type])
Function fin_PMT computes the periodic payment of a loan or investment based on a constant annual interest rate.

Parameters:

- IY: Nominal interest rate per year as a percent; for example, 2.35 should be entered for a nominal rate of 2.35%.
- Nper: Total number of payments (for annuities) or compounding periods (for compound interest) in the loan/investment term.
- PV: The present value (principal) of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow.
- PY: The number of payments per year. Should be the same value as CY for compound interest problems where PMT=0; should be entered 1 for annual payments, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- CY: The number of interest compounding periods per year; should be entered 1 for compounded annually, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- FV: Optional - The future value of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow; default = 0.
- type: Optional - The type of annuity. Should be entered 1 for an annuity due and 0 (default) for a general annuity.

Returns

The periodic payment of a loan or investment: a positive value for cash inflow and a negative value for cash outflow.

fin_Nper(IY, PMT, PV, PY, CY, [FV,type])

Function fin_Nper computes the total number of payments/compounding periods in the term of an investment or loan based on a constant annual interest rate.

Parameters:

- IY: Nominal interest rate per year as a percent; for example, 2.35 should be entered for a nominal rate of 2.35%.
- PMT: The size of periodic payments; should be entered as a negative value for cash outflow and positive value for cash inflow.
- PV: The present value (principal) of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow.
- PY: The number of payments per year. Should be the same value as CY for compound interest problems where PMT=0; should be entered 1 for annual payments, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- CY: The number of interest compounding periods per year; should be entered 1 for compounded annually, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- FV: Optional - The future value of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow; default = 0.
- type: Optional - The type of annuity. Should be entered 1 for an annuity due and 0 (default) for a general annuity.

Returns

The number of payments/compounding periods in the loan or investment term.

fin_IY(Nper, PMT, PV, PY, CY, [FV, type])

Function fin_IY computes the nominal interest rate per year in percent.

Parameters:

- Nper: Total number of payments (for annuities) or compounding periods (for compound interest) in a loan or investment term.
- PMT: The size of periodic payments; should be entered as a negative value for cash outflow and positive value for cash inflow.
- PV: The present value (principal) of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow.
- PY: The number of payments per year. Should be the same value as CY for compound interest problems where PMT=0; should be entered 1 for annual payments, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- CY: The number of interest compounding periods per year; should be entered 1 for compounded annually, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- FV: Optional - The future value of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow; default = 0.
- type: Optional - The type of annuity. Should be entered 1 for an annuity due and 0 (default) for a general annuity.

Returns

The nominal interest rate per year in percent (%).

fin_iPMT(per ,IY ,Nper ,PV ,PY ,CY , [FV, type])

Function fin_iPMT computes the interest portion of a payment or a period (a range of payments). Functions iPMT and pPMT can be used to generate an amortization schedule.

Parameters:

- per: Array of size two for the range of payments for which the interest amount paid is calculated. To find the interest portion of a single payment, both values in the array should be the same. For example, $per=array(1,1) is used to compute the interest portion of the first payment, while $per=array(1,12) is used to calculate the interest portion paid in the period ranging from the 1st payment to 12th payment inclusive.
- IY: Nominal interest rate per year as a percent; for example, 2.35 should be entered for a nominal rate of 2.35%.
- Nper: Total number of payments (for annuities) or compounding periods (for compound interest) in a loan or investment term.
- PV: The present value (principal) of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow.
- PY: The number of payments per year. Should be the same value as CY for compound interest problems where PMT=0; should be entered 1 for annual payments, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- CY: The number of interest compounding periods per year; should be entered 1 for compounded annually, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- FV: Optional - The future value of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow; default = 0.
- type: Optional - The type of annuity. Should be entered 1 for an annuity due and 0 (default) for a general annuity.

Returns

The interest portion of a payment or a period (a range of payments).

fin_pPMT(per ,IY ,Nper ,PV ,PY ,CY , [FV, type])

Function fin_pPMT computes the principal portion of a payment or a period (a range of payments). Functions pPMT and iPMT can be used to generate an amortization schedule.

Parameters:

- per: Array of size two for the range of payments for which the principal portion is calculated. To find the principal portion of a single payment, both values in the array should be the same. For example, $per=array(1,1) is used to compute the principal portion of the first payment, while $per=array(1,12) is used to calculate the principal portion paid in the period ranging from the 1st payment to 12th payment inclusive.
- IY: Nominal interest rate per year as a percent; for example, 2.35 should be entered for a nominal rate of 2.35%.
- Nper: Total number of payments (for annuities) or compounding periods (for compound interest) in a loan or investment term.
- PV: The present value (principal) of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow.
- PY: The number of payments per year. Should be the same value as CY for compound interest problems where PMT=0; should be entered 1 for annual payments, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- CY: The number of interest compounding periods per year; should be entered 1 for compounded annually, 2 for semi-annually, 4 for quarterly, 12 for monthly, 365 for daily.
- FV: Optional - The future value of a loan or investment; should be entered as a negative value for cash outflow and positive value for cash inflow; default = 0.
- type: Optional - The type of annuity. Should be entered 1 for an annuity due and 0 (default) for a general annuity.

Returns

The principal portion of a payment or a period (a range of payments).

fin_IRR(CF, FR)

Function fin_IRR computes the Internal Rate of Return (IRR), in percent, of a series of cash flows. IRR is the average periodically compounded rate of return that gives a net present value (NPV) of 0. In other words, IRR is the lowest rate of return from an investment that is acceptable to justify the investment.

Parameters:

- CF: Array of cash flows; cash outflows (investments) should be entered as negative values; cash inflows (expected returns on investment) should be entered as positive values.
- FR: Array of the frequency of each cash flow; initial cash flow is negative (cash outflow) and has a frequency of 1.

Both CF and FR arrays must be the same size. For example, if the initial investment is $50,000 (cash ouflow), and the annual returns on investment (cash inflow) are expected to be $10,000 in the first year and $20,000 in the next three subsequent years, CF = array(-50,000, 10000, 20000) and FR = array(1, 1, 3).

Returns

The Internal Rate of Return (IRR) in percent (%).

fin_NPV(CF, FR, IY)

Function fin_NPV computes the Net Present Value (NPV) of a series of cash flows. NPV is a method of evaluating the feasibility of investments by finding the difference of present values of all cash flows. Investment is accepted when NPV>=0 and rejected when NPV<0.

Parameters:

- CF: Array of cash flows; cash outflows (investments) should be entered as negative values; cash inflows (expected returns on investment) should be entered as positive values. The period of cash flows must be the same. For example all annual cash flows or all monthly cash flows.
- FR: Array of the frequency of each cash flow; initial cash flow is negative (cash outflow) and has a frequency of 1.
- IY: The required rate of return in percent. The interest period must match the cash-flow period. For example, if the cash flows are annual, IY should be the annual interest rate, while for monthly cash flows, the interest rate per month should be entered.

Both CF and FR arrays must be the same size. For example, if the initial investment is $50,000 (cash ouflow), and the annual returns on investment (cash inflow) are expected to be $10,000 in the first year and $20,000 in the next three subsequent years, CF = array(-50,000, 10000, 20000) and FR = array(1, 1, 3).

Returns:

The Net Present Value (NPV) of a series of cash flows ($).

fin_DBD(Date1,Date2)

Function fin_DBD computes the number of days between the given dates (DBD). DBD function can be used for time-value-of-money problems (generally short-terms) where the term of the investment or loan is not given explicitly but rather in a form of two dates.

Parameters:

- Date1: Starting date in the form of 'YYYY-MM-DD', 'YYYY/MM/DD', or 'MM/DD/YYYY'.
- Date2: End date in the form of 'YYYY-MM-DD', 'YYYY/MM/DD', or 'MM/DD/YYYY'.

Returns:

The number of days between the given dates (DBD).

fin_TVM()

Function fin_TVM returns an iframe for displaying a Time-Value-of-Money (TVM) solver. It provides students with a solver that can be used to compute different values of loans or investments (works similar to the functions in this library).

Parameters: None

Returns:

An embedded iframe code for inserting the solver into a question.

Back to top of page