Documentation ¶
Overview ¶
Package finance implements financial functions with the Excel function names and parameter order.
Terms Definition ¶
rate: the interest rate for the loan. (monthly rate) nper: the total number of payments for the loan. pv: the present value, or the total amount that a series of future payments is worth now; also known as the principal. fv: the future value, or a cash balance you want to attain after the last payment is made. pmt: the payment made each period and cannot change over the life of the annuity. due: adjust the payment to the beginning or end of the period. 0, At the end of the period; 1, At the beginning of the period.
Index ¶
- Constants
- Variables
- func FV(rate float64, nper int, pmt float64, pv float64, due float64) float64
- func IPMT(rate float64, per int, nper int, pv float64, fv float64, due float64) float64
- func NPER(rate float64, pmt float64, pv float64, fv float64, due float64) float64
- func PMT(rate float64, nper int, pv float64, fv float64, due float64) float64
- func PPMT(rate float64, per int, nper int, pv float64, fv float64, due float64) float64
- func PV(rate float64, nper int, pmt float64, fv float64, due float64) float64
- func RATE(nper int, pmt float64, pv float64, fv float64, due float64, guess float64) float64
- type Installment
- type Loan
- func (loan Loan) CalculateInstallments() []Installment
- func (loan Loan) CalculateInterest(period int) float64
- func (loan Loan) CalculatePayment(period int) float64
- func (loan Loan) CalculatePrincipal(period int) float64
- func (loan Loan) CalculateTotalInterest() float64
- func (loan Loan) CalculateTotalPayment() float64
Constants ¶
const ( EqualPayment = iota EqualPrincipal )
installment methods
Variables ¶
var Accuracy = 1.0e-6
Accuracy is the accuracy in numeric approximations
var MaxIterations = 100
MaxIterations is the max iterations
var Precision = 2
Precision is the precision in installment
Functions ¶
func FV ¶
FV returns the future value of an investment based on periodic, constant payments and a constant interest rate.
For a more complete description of the arguments in FV, see the PV function.
If rate = 0: FV = -(PV + PMT * nper)
Else
/ nper \ | 1 - (1 + rate) | nper
FV = PMT * (1 + rate * due) * | ------------------ | - PV * (1 + rate)
\ rate /
func IPMT ¶
IPMT returns the interest payment for a given period for an investment based on periodic, constant payments and a constant interest rate.
func NPER ¶
NPER returns the number of periods for an investment based on periodic, constant payments and a constant interest rate.
If rate = 0:
-(FV + PV)
nper = -----------
PMT
Else
/ PMT * (1 + rate * due) - FV * rate \ log | ------------------------------------ | \ PMT * (1 + rate * due) + PV * rate /
nper = -----------------------------------------------
log (1 + rate)
func PMT ¶
PMT calculates the payment for a loan based on constant payments and a constant interest rate.
If rate = 0:
-(FV + PV)
PMT = ------------
nper
Else
nper FV + PV * (1 + rate)
PMT = --------------------------------------------
/ nper \ | 1 - (1 + rate) | (1 + rate * due) * | ------------------ | \ rate /
func PPMT ¶
PPMT returns the payment on the principal for a given period for an investment based on periodic, constant payments and a constant interest rate.
func PV ¶
PV returns the present value of an investment. The present value is the total amount that a series of future payments is worth now. For example, when you borrow money, the loan amount is the present value to the lender.
If rate = 0: PV = -(FV + PMT * nper)
Else
/ nper \ | 1 - (1 + rate) | PMT * (1 + rate * due) * | ----------------- | - FV \ rate /
PV = ------------------------------------------------------
nper (1 + rate)
func RATE ¶
RATE calculates interest rate per period of an annuity.
The basic rate formula derivation is to solve for the future value taking into account the present value: https://en.wikipedia.org/wiki/Future_value
Types ¶
type Installment ¶
type Installment struct { Period int Payment float64 Principal float64 Interest float64 RemainingAmount float64 }
Installment is an installment
type Loan ¶
Loan is a loan, default method is EqualPayment
func (Loan) CalculateInstallments ¶
func (loan Loan) CalculateInstallments() []Installment
CalculateInstallments calculates installments
func (Loan) CalculateInterest ¶
CalculateInterest calculates interest in given period
func (Loan) CalculatePayment ¶
CalculatePayment calculates payment in given period
func (Loan) CalculatePrincipal ¶
CalculatePrincipal calculates principal in given period
func (Loan) CalculateTotalInterest ¶
CalculateTotalInterest calculates total interest
func (Loan) CalculateTotalPayment ¶
CalculateTotalPayment calculates total payment