View Source Money.Financial (Money v5.15.3)

A set of financial functions, primarily related to discounted cash flows.

Some of the algorithms are from finance formulas

Summary

Functions

Calculates the future value for a list of cash flows and an interest rate.

Calculates the future value for a present value, an interest rate and a number of periods.

Calculates the effective interest rate for a given present value, a future value and a number of periods.

Calculates the interal rate of return for a given list of cash flows.

Calculates the net present value of an initial investment, a list of cash flows and an interest rate.

Calculates the net present value of an initial investment, a recurring payment, an interest rate and a number of periods

Calculates the payment for a given loan or annuity given a present value, an interest rate and a number of periods.

Calculates the number of periods between a present value and a future value with a given interest rate.

Calculates the present value for a list of cash flows and an interest rate.

Calculates the present value for future value, an interest rate and a number of periods

Functions

Link to this function

future_value(flows, interest_rate)

View Source
@spec future_value([{number(), Money.t()}], number()) :: Money.t()

Calculates the future value for a list of cash flows and an interest rate.

  • flows is a list of tuples representing a cash flow. Each flow is represented as a tuple of the form {period, %Money{}}

  • interest_rate is a float representation of an interest rate. For example, 12% would be represented as 0.12

Example

iex> Money.Financial.future_value([{4, Money.new(:USD, 10000)}, {5, Money.new(:USD, 10000)}, {6, Money.new(:USD, 10000)}], 0.13)
Money.new(:USD, "34068.99999999999999999999999")

iex> Money.Financial.future_value [{0, Money.new(:USD, 5000)},{1, Money.new(:USD, 2000)}], 0.12
Money.new(:USD, "7600.000000000000000000000000")
Link to this function

future_value(money, interest_rate, periods)

View Source
@spec future_value(Money.t(), number(), number()) :: Money.t()

Calculates the future value for a present value, an interest rate and a number of periods.

  • present_value is a %Money{} representation of the present value

  • interest_rate is a float representation of an interest rate. For example, 12% would be represented as 0.12

  • periods in an integer number of periods

Examples

iex> Money.Financial.future_value Money.new(:USD, 10000), 0.08, 1
Money.new(:USD, "10800.00")

iex> Money.Financial.future_value Money.new(:USD, 10000), 0.04, 2
Money.new(:USD, "10816.0000")

iex> Money.Financial.future_value Money.new(:USD, 10000), 0.02, 4
Money.new(:USD, "10824.32160000")
Link to this function

interest_rate(present_value, future_value, periods)

View Source
@spec interest_rate(Money.t(), Money.t(), number()) :: Decimal.t()

Calculates the effective interest rate for a given present value, a future value and a number of periods.

  • present_value is a %Money{} representation of the present value

  • future_value is a %Money{} representation of the future value

  • periods is an integer number of a period

Examples

iex> Money.Financial.interest_rate Money.new(:USD, 10000), Money.new(:USD, 10816), 2
Decimal.new("0.04")

iex> Money.Financial.interest_rate Money.new(:USD, 10000), Money.new(:USD, "10824.3216"), 4
Decimal.new("0.02")
Link to this function

internal_rate_of_return(flows)

View Source
@spec internal_rate_of_return([{integer(), Money.t()}]) :: number()

Calculates the interal rate of return for a given list of cash flows.

  • flows is a list of tuples representing a cash flow. Each flow is represented as a tuple of the form {period, %Money{}}
Link to this function

net_present_value(flows, interest_rate)

View Source
@spec net_present_value([{integer(), Money.t()}], number()) :: Money.t()

Calculates the net present value of an initial investment, a list of cash flows and an interest rate.

  • flows is a list of tuples representing a cash flow. Each flow is represented as a tuple of the form {period, %Money{}}

  • interest_rate is a float representation of an interest rate. For example, 12% would be represented as 0.12

  • investment is a %Money{} struct representing the initial investment

Example

iex> flows = [{0, Money.new(:USD, 5000)},{1, Money.new(:USD, 2000)},{2, Money.new(:USD, 500)},{3, Money.new(:USD,10_000)}]
iex> Money.Financial.net_present_value flows, 0.08, Money.new(:USD, 100)
Money.new(:USD, "15118.84367220444038002337042")
iex> Money.Financial.net_present_value flows, 0.08
Money.new(:USD, "15218.84367220444038002337042")
Link to this function

net_present_value(flows, interest_rate, investment)

View Source
@spec net_present_value([{integer(), Money.t()}], number(), Money.t()) :: Money.t()
@spec net_present_value(Money.t(), number(), number()) :: Money.t()

Calculates the net present value of an initial investment, a recurring payment, an interest rate and a number of periods

  • investment is a %Money{} struct representing the initial investment

  • future_value is a %Money{} representation of the future value

  • interest_rate is a float representation of an interest rate. For example, 12% would be represented as 0.12

  • periods in an integer number of a period

Example

iex> Money.Financial.net_present_value Money.new(:USD, 10000), 0.13, 2
Money.new(:USD, "7831.466833737959119743127888")

iex> Money.Financial.net_present_value Money.new(:USD, 10000), 0.13, 2, Money.new(:USD, 100)
Money.new(:USD, "7731.466833737959119743127888")
Link to this function

net_present_value(future_value, interest_rate, periods, investment)

View Source
@spec net_present_value(Money.t(), number(), number(), Money.t()) :: Money.t()
Link to this function

payment(present_value, interest_rate, periods)

View Source
@spec payment(Money.t(), float(), number()) :: Money.t()

Calculates the payment for a given loan or annuity given a present value, an interest rate and a number of periods.

  • present_value is a %Money{} representation of the present value

  • interest_rate is a float representation of an interest rate. For example, 12% would be represented as 0.12

  • periods is an integer number of periods

Example

iex> Money.Financial.payment Money.new(:USD, 100), 0.12, 20
Money.new(:USD, "13.38787800396606622792492299")
Link to this function

periods(present_value, future_value, interest_rate)

View Source
@spec periods(Money.t(), Money.t(), float()) :: Decimal.t()

Calculates the number of periods between a present value and a future value with a given interest rate.

  • present_value is a %Money{} representation of the present value

  • future_value is a %Money{} representation of the future value

  • interest_rate is a float representation of an interest rate. For example, 12% would be represented as 0.12

Example

iex> Money.Financial.periods Money.new(:USD, 1500), Money.new(:USD, 2000), 0.005
Decimal.new("57.68013595323872502502238648")
Link to this function

present_value(flows, interest_rate)

View Source
@spec present_value([{integer(), Money.t()}], number()) :: Money.t()

Calculates the present value for a list of cash flows and an interest rate.

  • flows is a list of tuples representing a cash flow. Each flow is represented as a tuple of the form {period, %Money{}}

  • interest_rate is a float representation of an interest rate. For example, 12% would be represented as 0.12

Example

iex> Money.Financial.present_value([{4, Money.new(:USD, 10000)}, {5, Money.new(:USD, 10000)}, {6, Money.new(:USD, 10000)}], 0.13)
Money.new(:USD, "16363.97191111964880256655144")

iex> Money.Financial.present_value [{0, Money.new(:USD, -1000)},{1, Money.new(:USD, -4000)}], 0.1
Money.new(:USD, "-4636.363636363636363636363636")
Link to this function

present_value(money, interest_rate, periods)

View Source
@spec present_value(Money.t(), number(), number()) :: Money.t()

Calculates the present value for future value, an interest rate and a number of periods

  • future_value is a %Money{} representation of the future value

  • interest_rate is a float representation of an interest rate. For example, 12% would be represented as 0.12

  • periods in an integer number of periods

Examples

iex> Money.Financial.present_value Money.new(:USD, 100), 0.08, 2
Money.new(:USD, "85.73388203017832647462277092")

iex> Money.Financial.present_value Money.new(:USD, 1000), 0.10, 20
Money.new(:USD, "148.6436280241436864020760472")