Function rust_finprim::tvm::npv_differing_rates
source · pub fn npv_differing_rates(flow_table: &[(Decimal, Decimal)]) -> Decimal
Expand description
NPV Differing Rates - Net Present Value with differing discount rates
The net present value (NPV) is the difference between the present value of cash inflows and the present value of cash outflows over a period of time. NPV is used in capital budgeting to analyze the profitability of an investment or project. The NPV is calculated by discounting all cash flows to the present value using a specified discount rate. If the NPV is positive, the investment is considered profitable. If the NPV is negative, the investment is considered unprofitable. This function allows for differing discount rates for each cash flow.
§Arguments
flow_table
- A slice of tuples representing the cash flows and discount rates for each period(cash_flow, discount_rate)
, note that the first cash flow is assumed to be at time value 0 (initial investment)
§Returns
- The net present value (NPV)
§Example
- Cash flows of $-100, $50, $40, $30, $20
- Discount rates of 5%, 6%, 7%, 8%, 9%
use rust_decimal_macros::*;
use rust_finprim::tvm::npv_differing_rates;
let flow_table = vec![
(dec!(-100), dec!(0.05)),
(dec!(50), dec!(0.06)),
(dec!(40), dec!(0.07)),
(dec!(30), dec!(0.08)),
(dec!(20), dec!(0.09)),
];
npv_differing_rates(&flow_table);
§Formula
The NPV is calculated by discounting all cash flows to the present value using a specified discount rate. $$NPV = \sum_{t=0}^{n} \frac{CF_t}{(1+r_t)^t}$$ Where:
- \(CF_t\) = cash flow at time \(t\)
- \(r_t\) = discount rate at time \(t\)