interest

package module
v0.0.0-...-54da669 Latest Latest
Warning

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

Go to latest
Published: May 10, 2018 License: MIT Imports: 4 Imported by: 2

README

go-interest

Interest calculations in Go language

Documentation

Index

Constants

View Source
const (
	FormulaSimple   = "simple"
	FormulaCompound = "compound"
)
View Source
const (
	RatePeriodDaily   = 1
	RatePeriodWeekly  = 7
	RatePeriodMonthly = 30
	RatePeriodYearly  = 360
)

Variables

View Source
var (
	ErrFormulaIsNotSet = errors.New("interest formula is not set")
)
View Source
var KnownFormulas = []Formula{
	FormulaSimple,
	FormulaCompound,
}

Functions

func AgeInDays

func AgeInDays(periodStarts, periodEnds time.Time) int

func Calculate

func Calculate(reportTime time.Time, deal Deal, payments []Payment) (interest, outstanding decimal.Decimal64p2, err error)

func IsKnownFormula

func IsKnownFormula(formula Formula) bool

Types

type Calculator

type Calculator interface {
	Formula() Formula
	Calculate(reportTime time.Time, deal Deal, payments []Payment) (interest, outstanding decimal.Decimal64p2, err error)
}

type Credit

type Credit interface {
	Formula() Formula
	RatePeriod() RatePeriodInDays
	RatePercent() decimal.Decimal64p2
	MinimumPeriod() int
	GracePeriod() int
}

type Deal

type Deal interface {
	Credit
	Time() time.Time
	LentAmount() decimal.Decimal64p2
}

func NewDeal

func NewDeal(formula Formula, time time.Time, lentAmount, ratePercent decimal.Decimal64p2, ratePeriod RatePeriodInDays, minimumPeriod, gracePeriod int) Deal

type Formula

type Formula string

type Payment

type Payment interface {
	Time() time.Time
	Amount() decimal.Decimal64p2
}

func NewPayment

func NewPayment(time time.Time, amount decimal.Decimal64p2) Payment

type RatePeriodInDays

type RatePeriodInDays int

type SimplePercentCalculator

type SimplePercentCalculator struct {
}

func (SimplePercentCalculator) Calculate

func (SimplePercentCalculator) Calculate(reportTime time.Time, deal Deal, payments []Payment) (interest, outstanding decimal.Decimal64p2, err error)

func (SimplePercentCalculator) Formula

func (SimplePercentCalculator) Formula() Formula

Jump to

Keyboard shortcuts

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