goxirr

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2022 License: GPL-3.0 Imports: 4 Imported by: 0 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

goxirr

GoDoc

Goxirr is a simple implementation of a function for calculating the Internal Rate of Return for irregular cash flow (XIRR).

This fork was modified by stevegt to support more extreme conditions:

  • handles case when IRR == -100%
  • handles case when cashflow == 0 in any given transaction
  • uses a bracketing function rather than stepwise successive approximation in order to handle cases where the limit of the residual is +/- infinity when approaching the correct IRR

There are these tunables:

  • Span: Initial successive approximation bracket size. You may need to increase this if you expect +/- IRR larger than the default. Defaults to 999.9.
  • SpanFactor: Span is multiplied by this factor after every iteration. Decreasing this will decrease computation time but will also limit accuracy in pathological cases. Defaults to 0.8.
  • Limit: Maximum number of successive approximation iterations. Defaults to 99999.
  • Epsilon: Tolerance for IRR error. Also used as an infinitesimal when cashflow == 0 in any transaction. Increasing this will decrease computation time as well as accuracy. Defaults to 0.0001.

Example

package main

import (
	"fmt"
	"time"

	"github.com/stevegt/goxirr"
)

func main() {
	goxirr.Limit = 10000000 // e.g.

	firstDate := time.Date(2019, time.January, 1, 0, 0, 0, 0, time.UTC)
	t1 := goxirr.Transaction{
		Date: firstDate,
		Cash: -123400,
	}

	t2 := goxirr.Transaction{
		Date: firstDate.Add(time.Hour * 24 * 365 * 1),
		Cash: 36200,
	}

	t3 := goxirr.Transaction{
		Date: firstDate.Add(time.Hour * 24 * 365 * 2),
		Cash: 54800,
	}

	t4 := goxirr.Transaction{
		Date: firstDate.Add(time.Hour * 24 * 365 * 3),
		Cash: 48100,
	}

	tas := goxirr.Transactions{t1, t2, t3, t4}
	fmt.Println(goxirr.Xirr(tas))
}

Documentation

Overview

Package goxirr is a simple implementation of a function for calculating the Internal Rate of Return for irregular cash flow (XIRR).

Index

Constants

This section is empty.

Variables

View Source
var Epsilon = 0.0001
View Source
var Max float64 = 1000
View Source
var Min float64 = -1000

Functions

func Xirr

func Xirr(transactions Transactions) float64

Xirr returns the Internal Rate of Return (IRR) for an irregular series of cash flows (XIRR)

Types

type Best added in v0.6.0

type Best struct {
	// contains filtered or unexported fields
}

type Bestset added in v0.6.0

type Bestset []Best

type Transaction

type Transaction struct {
	Date time.Time
	Cash float64
}

A Transaction represent a single transaction from a series of irregular payments.

type Transactions

type Transactions []Transaction

Transactions represent a cash flow consisting of individual transactions

Jump to

Keyboard shortcuts

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