[−][src]Module finance_solution::net_present_value
Net Present Value calculations. Given a series of cashflows, an initial investment (the cashflow at time0), a number of periods such as years, and fixed or varying interest rates, what is the net value of the series of cashflows right now?
For most common usages, we recommend the net_present_value_schedule_solution
function, to provide a better debugging experience and additional features.
This function allows you to provide varying cashflows and/or varying rates.
For very simple NPV calculations involving a constant cashflow and constant rate, the net_present_value_solution
function can be used.
Examples
Simple Usage:
let (rate, periods, initial_investment, cashflow) = (0.034, 3, -1000, 400); let npv = net_present_value_solution(rate, periods, initial_investment, cashflow); dbg!(npv.print_table());
outputs to terminal:
period rate present_value future_value investment_value
------ ------ ------------- ------------ ----------------
0 0.0000 -1_000.0000 -1_000.0000 -1_000.0000
1 0.0340 386.8472 400.0000 -613.1528
2 0.0340 374.1269 400.0000 -239.0259
3 0.0340 361.8248 400.0000 122.7989
More typical usage (varying cashflows):
let rates = vec![0.034, 0.034, 0.034]; let cashflows = vec![-1000, 300, 400, 500]; let npv = net_present_value_schedule_solution(&rates, &cashflows); dbg!(npv.print_table());
outputs to terminal:
period rate present_value future_value investment_value
------ ------ ------------- ------------ ----------------
0 0.0000 -1_000.0000 -1_000.0000 -1_000.0000
1 0.0340 290.1354 300.0000 -709.8646
2 0.0340 374.1269 400.0000 -335.7377
3 0.0340 452.2810 500.0000 116.5433
Structs
NpvPeriod | |
NpvSeries | |
NpvSolution | The custom solution information of a NPV scenario. The struct values are immutable by the user of the library. |
Functions
net_present_value | Returns the net present value of a future series of constant cashflows and constant rate, subtracting the initial investment cost. Returns f64. |
net_present_value_schedule | Returns the net present value of a schedule of rates and cashflows (can be varying), subtracting the initial investment cost. Returns f64. |
net_present_value_schedule_solution | Returns the net present value of a schedule of rates and cashflows (can be varying), subtracting the initial investment cost. Returns a custom solution struct with detailed information and additional functionality. |
net_present_value_solution | Returns the net present value of a future series of constant cashflows and constant rate, subtracting the initial investment cost. Returns a solution struct with additional features.. |