[][src]Function finance_solution::net_present_value

pub fn net_present_value<C, I>(
    rate: f64,
    periods: u32,
    initial_investment: I,
    cashflow: C
) -> f64 where
    I: Into<f64> + Copy,
    C: Into<f64> + Copy

Returns the net present value of a future series of constant cashflows and constant rate, subtracting the initial investment cost. Returns f64.

Related functions:

The net present value annuity formula is:

npv = initial_investment + sum( cashflow / (1 + rate)period )

or

npv = initial_investment + cashflow * ((1. - (1. / (1. + rate)).powf(periods)) / rate)

Arguments

  • rate - The rate at which the investment grows or shrinks per period, expressed as a floating point number. For instance 0.05 would mean 5%. Often appears as r or i in formulas.
  • periods - The number of periods such as quarters or years. Often appears as n or t.
  • cashflow - The value of the constant cashflow (aka payment).
  • initial investment - The value of the initial investment (should be negative, or 0).

Panics

The call will fail if initial_investment is positive. This value should always be negative, and cashflows be positive, or the reverse, because these monies are going opposite directions.

Examples

Net Present Value of a series of -$1000 investment which will payback $500 yearly for 10 years.

use finance_solution::*;
let (rate, periods, initial_investment, cashflow) = (0.034, 10, -1000, 500);

// Find the present value of this scenario.
let net_present_value = net_present_value(rate, periods, initial_investment, cashflow);

// Confirm that the present value is correct to four decimal places (one hundredth of a cent).
assert_approx_equal!(3179.3410288, net_present_value);