Finance.Rates (finance v1.6.0)

Copy Markdown View Source

Converting between the different ways an interest rate can be quoted.

A nominal rate paired with a compounding frequency, the effective annual rate it actually earns, and a continuously-compounded rate all describe the same return in different terms. These functions move between them.

Summary

Functions

The per-period rate equivalent to a continuously-compounded annual rate, for periods periods a year.

Same as continuous_to_periodic/2, but returns the rate directly and raises ArgumentError on error.

The effective annual rate earned by a nominal rate compounded m times a year.

Same as effective_annual_rate/2, but returns the rate directly and raises ArgumentError on error.

The nominal rate that, compounded m times a year, produces the effective annual rate. The inverse of effective_annual_rate/2.

Same as nominal_rate/2, but returns the rate directly and raises ArgumentError on error.

Types

error()

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

Functions

continuous_to_periodic(rate, periods)

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

The per-period rate equivalent to a continuously-compounded annual rate, for periods periods a year.

e^(rate / periods)  1

iex> {:ok, r} = Finance.Rates.continuous_to_periodic(0.10, 1)
iex> Float.round(r, 6)
0.105171

continuous_to_periodic!(rate, periods)

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

Same as continuous_to_periodic/2, but returns the rate directly and raises ArgumentError on error.

effective_annual_rate(nominal, m)

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

The effective annual rate earned by a nominal rate compounded m times a year.

(1 + nominal / m)^m  1

iex> {:ok, ear} = Finance.Rates.effective_annual_rate(0.10, 12)
iex> Float.round(ear, 6)
0.104713

effective_annual_rate!(nominal, m)

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

Same as effective_annual_rate/2, but returns the rate directly and raises ArgumentError on error.

nominal_rate(effective, m)

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

The nominal rate that, compounded m times a year, produces the effective annual rate. The inverse of effective_annual_rate/2.

m · ((1 + effective)^(1/m)  1)

iex> {:ok, ear} = Finance.Rates.effective_annual_rate(0.10, 12)
iex> {:ok, nominal} = Finance.Rates.nominal_rate(ear, 12)
iex> Float.round(nominal, 10)
0.1

nominal_rate!(effective, m)

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

Same as nominal_rate/2, but returns the rate directly and raises ArgumentError on error.