finance

package module
v0.0.0-...-893867a Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PeriodAnnual     = 1
	PeriodSemiAnnual = 2
	PeriodQuarterly  = 4
	PeriodMonthly    = 12
	PeriodDaily      = 365
)

Period* constants are used as "times per year" values.

Variables

This section is empty.

Functions

func CompoundInterest

func CompoundInterest(principal, rate float64, timesPerYear, years int) float64

CompoundInterest is interest calculated on the initial principal inclusive of the accumulated interest over a period of time

func FormatDollars

func FormatDollars(f float64) string

FormatDollars format a float to a humanized dollar amount.

func MonthlyLoanPayment

func MonthlyLoanPayment(amount, rate float64, years int) float64

MonthlyLoanPayment returns the monthy loan payment.

func PadDecimal

func PadDecimal(s string, precision int) string

PadDecimal pads decimals with "0" to two decimal places.

func PadRight

func PadRight(str, pad string, length int) string

PadRight pads a string with a value.

func PresentValue

func PresentValue(desiredAmount, rate float64, timesPerYear, years int) float64

PresentValue calculates the present day value of an amount that is received at a future date.

func PrintlnDollars

func PrintlnDollars(f float64) (int, error)

PrintlnDollars prints a humanized dollar amount to STDOUT with a trailing newline character.

func Round

func Round(num float64, precision int) float64

Round rounds a float64 to the specified precision, i.e. the number of digits after the decimal point.

func Sigma

func Sigma(lower, upper int, fn SummandFunc) (sum float64)

Sigma sums up values as represented in Σ notation.

Assuming that n is the index of summation, lower is the lower limit of n, upper is the upper limit of n, and fn is the summand being summed up.

func SimpleMovingAverage

func SimpleMovingAverage(in []float64, num int) (out []float64, err error)

SimpleMovingAverage calculates a moving average for a float64 slice.

func SumFloat64

func SumFloat64(data []float64) (sum float64)

SumFloat64 sums the values in a float64 slice.

func SumInt

func SumInt(data []int) (sum int)

SumInt sums the values in an int slice.

func SumInt64

func SumInt64(data []int64) (sum int64)

SumInt64 sums the values in an int64 slice.

func SummandN

func SummandN(n int) float64

SummandN is a basic SumFunc that just sums up n.

func SummandNSquared

func SummandNSquared(n int) float64

SummandNSquared sums up n to the power of 2.

func TotalLoanPayment

func TotalLoanPayment(amount, rate float64, years int) float64

TotalLoanPayment returns the total loan payment over the whole term.

Types

type SummandFunc

type SummandFunc func(n int) float64

SummandFunc is a function definition for a summand in Σ notation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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