Finance.Solver behaviour (finance v1.4.1)

Copy Markdown View Source

The root-finding strategy behind the rate functions (Finance.CashFlow.irr/2, Finance.CashFlow.xirr/2, Finance.TVM.rate/6).

A solver receives a normalized list of {time, amount} flows and finds the rate r that brings their net present value to zero. The default is Finance.Solver.Newton; swap in another implementation of this behaviour with the :solver option or config :finance, solver: MySolver — for example a future Nx / GPU-accelerated solver.

Summary

Types

A normalized flow: {time, amount}, time in periods (or years).

Callbacks

Solve Σ amount_i / (1 + r)^t_i = 0 for r.

Types

flow()

@type flow() :: {number(), number()}

A normalized flow: {time, amount}, time in periods (or years).

Callbacks

solve(flows, opts)

@callback solve(flows :: [flow()], opts :: keyword()) :: {:ok, float()} | {:error, atom()}

Solve Σ amount_i / (1 + r)^t_i = 0 for r.

opts carries :guess, :tolerance, :max_iterations, and :precision. Returns {:ok, rate} (rounded to :precision) or {:error, :did_not_converge}.