@webcarrot/xirr

1.0.3 • Public • Published

@webcarrot/xirr · GitHub license npm version

JavaScript implementation of the XIRR LibreOffice function. It should give the same results as equivalents from LibreOffice Calc, MS Excel, Google Spreadsheet etc.

Instalation

npm i @webcarrot/xirr

Usage

import { xirr, CashFlow } from "@webcarrot/xirr";

const flows: Array<CashFlow> = [
  {
    amount: 100,
    date: new Date("2019-02-02")
  },
  {
    amount: -120,
    date: new Date("2019-03-02")
  }
];

try {
  console.log("XIRR:", xirr(flows), "of", flows);
} catch (err) {
  console.log(err);
}

Methods and types

export declare type CashFlow = {
  readonly amount: number;
  readonly date: Date;
};
export declare type CashFlowNormalized = {
  readonly amount: number;
  readonly date: number;
};
export declare const calculateResult: (
  flowsFrom1: ReadonlyArray<CashFlowNormalized>,
  r: number
) => number;
export declare const calculateResultDerivation: (
  flowsFrom1: ReadonlyArray<CashFlowNormalized>,
  r: number
) => number;
export declare const calculate: (
  flows: ReadonlyArray<CashFlowNormalized>,
  guessRate?: number,
  maxEpsilon?: number,
  maxScans?: number,
  maxIterations?: number
) => number;
export declare const normalize: (
  flows: ReadonlyArray<CashFlow>
) => ReadonlyArray<CashFlowNormalized>;
export declare const xirr: (
  flows: ReadonlyArray<CashFlow>,
  guessRate?: number,
  maxEpsilon?: number,
  maxScans?: number,
  maxIterations?: number
) => number;

Readme

Keywords

Package Sidebar

Install

npm i @webcarrot/xirr

Weekly Downloads

1,820

Version

1.0.3

License

MIT

Unpacked Size

25.1 kB

Total Files

11

Last publish

Collaborators

  • webcarrot