financial

package module
v0.0.0-...-df23148 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2017 License: MIT Imports: 2 Imported by: 0

README

financial CircleCI GoDoc

package financial features common financial functions, and is intended to be a golang version of numpy's financial functions.

Supported Functions:

  • NPV(r, values): returns the NPV (Net Present Value) of a cash flow series given an interest rate r, or an error. See usage example.
  • IRR(values): returns the Internal Rate of Return (using newton raphson approximation). See usage example.
  • FV(pv, r, compoundedAnnually, n): gets the present value, the interest rate (compounded annually if needed) and the number of periods and returns the future value. See usage example.

TODO:

  • pv(rate, nper, pmt[, fv, when]) Compute the present value.
  • pmt(rate, nper, pv[, fv, when]) Compute the payment against loan principal plus interest.
  • ppmt(rate, per, nper, pv[, fv, when]) Compute the payment against loan principal.
  • ipmt(rate, per, nper, pv[, fv, when]) Compute the interest portion of a payment.
  • mirr(values, finance_rate, reinvest_rate) Modified internal rate of return.
  • nper(rate, pmt, pv[, fv, when]) Compute the number of periodic payments.
  • rate(nper, pmt, pv, fv[, when, guess, tol, ...]) Compute the rate of interest per period.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FV

func FV(pv, r float64, compoundedAnnually bool, n float64) float64

FV gets the present value, the interest rate (compounded annually if needed) and the number of periods and returns the future value.

Example
presentValue := 100.0
interestRate := 0.07
periods := 10.0
compoundedAnnually := false

fv := FV(presentValue, interestRate, compoundedAnnually, periods)
fmt.Printf("FV is: %f", fv)
Output:

FV is: 170.000000

func IRR

func IRR(values []float64) (float64, error)

IRR returns the Internal Rate of Return (IRR).

Example
initialInvestment := 100.0

cashFlowYear1 := 39.0
cashFlowYear2 := 59.0
cashFlowYear3 := 55.0
cashFlowYear4 := 20.0

irr, err := IRR([]float64{-initialInvestment, cashFlowYear1, cashFlowYear2, cashFlowYear3, cashFlowYear4})
if err != nil {
	fmt.Println(err.Error())
	return
}
fmt.Printf("IRR is: %f", irr)
Output:

IRR is: 0.280948

func NPV

func NPV(r float64, values []float64) (float64, error)

NPV returns the NPV (Net Present Value) of a cash flow series given an interest rate r, or an error.

Example
initialInvestment := 100.0

cashFlowYear1 := 39.0
cashFlowYear2 := 59.0
cashFlowYear3 := 55.0
cashFlowYear4 := 20.0

discountRate := 0.281

npv, err := NPV(discountRate, []float64{-initialInvestment, cashFlowYear1, cashFlowYear2, cashFlowYear3, cashFlowYear4})
if err != nil {
	fmt.Println(err.Error())
	return
}
fmt.Printf("NPV is: %f", npv)
Output:

NPV is: -0.008479

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL