mortgage

package
v0.0.0-...-70b24aa Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2022 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParametersMissing = errors.New("invalid data, calculation failed due to missing parameters")
	ErrCalculationFailed = errors.New("calculation failed")
)

Common errors.

Functions

func NewLinearGrowthIP

func NewLinearGrowthIP(bd financial.Date, bi, curve decimal.Decimal) (i indexGrowthLinear)

NewLinearGrowthIP create new index predictor (linear curve)

Types

type CalculationType

type CalculationType int
const (
	Shpitzer CalculationType = iota + 1
	ConstFromPrincipal
)

type CashFlowCreator

type CashFlowCreator interface {
	NewCashFlowTable() (FlowTab, error)
}

type Flow

type Flow struct {
	Index           int64
	Date            financial.Date
	Principal       decimal.Decimal
	Interest        decimal.Decimal
	Payment         decimal.Decimal
	PrincipalLeft   decimal.Decimal
	KnownIndex      decimal.Decimal
	PaymentFactored decimal.Decimal
}

Flow is full cashflow of mortgage

func (Flow) ToCashFlow

func (f Flow) ToCashFlow() (cf financial.CashFlow)

func (Flow) ToCashFlowIndexed

func (f Flow) ToCashFlowIndexed() (cf financial.CashFlow)

type FlowTab

type FlowTab []Flow

FlowTab is table of flows, represent full cash flow

func CreateFlowTable

func CreateFlowTable(t CalculationType, a, r decimal.Decimal, m int64, ad, pd financial.Date, ip IndexPrediction, kf financial.CashFlowTab) (ft FlowTab, e error)

CreateShpitzerFlowTable calculate and create cashflow. a = amount r = monthly rate (note: not yearly rate, divide by 12 if needed) m = number of months ad = receiving the loan -> date pd = start paying -> date ed = end paying -> date bi = Base index kf = Known flows (down payment, fees and so on...)

func (FlowTab) Irr

func (ft FlowTab) Irr() (decimal.Decimal, error)

func (FlowTab) IrrIndexed

func (ft FlowTab) IrrIndexed() (decimal.Decimal, error)

func (FlowTab) Len

func (ft FlowTab) Len() int

Len impl "Interface" to support sorting, using sort.Sort.

func (FlowTab) Less

func (ft FlowTab) Less(i, j int) bool

Less impl "Interface" to support sorting, using sort.Sort.

func (FlowTab) OrderByDate

func (ft FlowTab) OrderByDate() (r FlowTab)

func (FlowTab) Rearrange

func (ft FlowTab) Rearrange() (result FlowTab)

func (FlowTab) String

func (ft FlowTab) String() string

String output is the data as CSV

func (FlowTab) Swap

func (ft FlowTab) Swap(i, j int)

Swap impl "Interface" to support sorting, using sort.Sort.

func (FlowTab) ToCashFlowTab

func (ft FlowTab) ToCashFlowTab() (cft financial.CashFlowTab)

func (FlowTab) ToCashFlowTabIndexed

func (ft FlowTab) ToCashFlowTabIndexed() (cft financial.CashFlowTab)

type IndexPrediction

type IndexPrediction interface {
	GetIndex(date financial.Date) decimal.Decimal
	GetBaseIndex() (financial.Date, decimal.Decimal)
}

IndexPrediction allow prediction of future index

type ShpitzerCashflow

type ShpitzerCashflow struct {
	Amount          decimal.Decimal
	Months          int64
	MonthlyRate     decimal.Decimal
	CashRecieveDate financial.Date
	StartPayingDate financial.Date
	IndexPredict    IndexPrediction
	KnownCashFlows  financial.CashFlowTab
}

func GetShpitzerCashflowInstance

func GetShpitzerCashflowInstance(a, r decimal.Decimal, m int64, cashDate, fromDate financial.Date, ip IndexPrediction, kf financial.CashFlowTab) (result *ShpitzerCashflow)

GetShpitzerCashflowInstance Creates instance. Parameters are: a : Amount of money r : Rate (monthly rate, not yearly) m : How many months cashDate : Date the money is taken from the bank fromDate : The first payment (to the bank) date ip : instance of index prediction. can be null if not relevant. kf : Known cash flows. Optional: additional known flows, like: down payment, taxes and so on.

func (ShpitzerCashflow) NewCashFlowTable

func (s ShpitzerCashflow) NewCashFlowTable() (ft FlowTab, e error)

Jump to

Keyboard shortcuts

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