Finance.Depreciation (finance v1.4.3)

Copy Markdown View Source

Writing an asset down from its cost to its salvage value over its life.

sln/3 spreads the loss evenly; syd/4, ddb/5, and db/5 are accelerated methods that depreciate more early on and return the amount for a single period (counting from 1).

Summary

Functions

Computes fixed-declining-balance depreciation for a single period.

Same as db/5, but returns the value directly and raises ArgumentError on error.

Computes double-declining-balance depreciation for a single period.

Same as ddb/5, but returns the value directly and raises ArgumentError on error.

Computes straight-line depreciation: the equal amount an asset is written down by each period as it declines from its cost to its salvage value over life periods.

Same as sln/3, but returns the value directly and raises ArgumentError on error.

Computes sum-of-years'-digits depreciation for a single period (counting from 1).

Same as syd/4, but returns the value directly and raises ArgumentError on error.

Types

error()

@type error() :: Finance.error()

Functions

db(cost, salvage, life, period, month \\ 12)

@spec db(number(), number(), number(), number(), number()) ::
  {:ok, float()} | {:error, error()}

Computes fixed-declining-balance depreciation for a single period.

Like ddb/5, this applies a constant rate to the declining book value, but the rate is derived directly from cost, salvage, and life (and rounded to three decimal places, matching what spreadsheets do). Use month to say how many months the asset was in service during its first year; it defaults to a full 12, and a shorter first year spills the remaining depreciation into an extra final period.

iex> Finance.Depreciation.db(10_000, 1_000, 5, 1)
{:ok, 3690.0}

iex> Finance.Depreciation.db(10_000, 1_000, 5, 2)
{:ok, 2328.39}

db!(cost, salvage, life, period, month \\ 12)

@spec db!(number(), number(), number(), number(), number()) :: float()

Same as db/5, but returns the value directly and raises ArgumentError on error.

ddb(cost, salvage, life, period, factor \\ 2)

@spec ddb(number(), number(), number(), number(), number()) ::
  {:ok, float()} | {:error, error()}

Computes double-declining-balance depreciation for a single period.

This is another accelerated method: each period it takes a fixed fraction of the remaining book value, so the write-down shrinks as the asset ages. The factor sets how aggressive that fraction is, defaulting to 2 for the usual double-declining rate. The depreciation is capped so it never drives the book value below salvage.

iex> Finance.Depreciation.ddb(10_000, 1_000, 5, 1)
{:ok, 4000.0}

iex> Finance.Depreciation.ddb(10_000, 1_000, 5, 2)
{:ok, 2400.0}

ddb!(cost, salvage, life, period, factor \\ 2)

@spec ddb!(number(), number(), number(), number(), number()) :: float()

Same as ddb/5, but returns the value directly and raises ArgumentError on error.

sln(cost, salvage, life)

@spec sln(number(), number(), number()) :: {:ok, float()} | {:error, error()}

Computes straight-line depreciation: the equal amount an asset is written down by each period as it declines from its cost to its salvage value over life periods.

This is the plainest of the depreciation methods — it spreads the loss in value evenly, so every period sees the same write-down.

iex> Finance.Depreciation.sln(10_000, 1_000, 5)
{:ok, 1800.0}

sln!(cost, salvage, life)

@spec sln!(number(), number(), number()) :: float()

Same as sln/3, but returns the value directly and raises ArgumentError on error.

syd(cost, salvage, life, period)

@spec syd(number(), number(), number(), number()) ::
  {:ok, float()} | {:error, error()}

Computes sum-of-years'-digits depreciation for a single period (counting from 1).

This is an accelerated method: it charges more depreciation in the early periods and less later on, which suits assets that lose most of their value up front. It returns the write-down for the one period you ask about rather than the whole schedule.

iex> Finance.Depreciation.syd(10_000, 1_000, 5, 1)
{:ok, 3000.0}

iex> Finance.Depreciation.syd(10_000, 1_000, 5, 5)
{:ok, 600.0}

syd!(cost, salvage, life, period)

@spec syd!(number(), number(), number(), number()) :: float()

Same as syd/4, but returns the value directly and raises ArgumentError on error.