Skip to main content

Module net_present_value

Module net_present_value 

Source
Expand description

Net Present Value calculations. Given cashflows (including the time-0 investment), periods, and fixed or varying discount rates, what is the net value of the series right now?

Prefer net_present_value_schedule_solution when rates or cashflows vary — it carries period detail and pretty tables. For a constant rate and constant periodic cashflow, use [net_present_value] / net_present_value_solution.

§Schedule input shapes

net_present_value_schedule accepts rates and cashflows with flexible lengths. Cashflows always include the time-0 investment as cashflows[0] (negative or zero). Rates apply to the forward periods (not time 0).

Shaperates lengthcashflows lengthMeaning
A. Single period12 ([t0, t1])One discount rate, one future cashflow
B. Full seriesNN+1Rate per period 1..=N; cashflow per t0..=tN
C. Repeating cashflowN2 ([t0, c])Rate series; cashflow c repeats each period
D. Repeating rate1N+1One rate broadcast to every period; full cashflows

Invalid combinations (both sides incomplete, empty slices, positive t0 investment, length mismatch on full series) return FinanceError.

§Shape A — single period

use finance_solution::net_present_value_schedule;
let npv = net_present_value_schedule(&[0.05], &[-1_000.0, 1_100.0]).unwrap();
assert!((npv - 47.6190476).abs() < 1e-6);

§Shape B — full varying rates and cashflows

use finance_solution::net_present_value_schedule;
let rates = [0.034, 0.089, 0.055];
let cashflows = [-1_000.0, 200.0, 300.0, 500.0];
let npv = net_present_value_schedule(&rates, &cashflows).unwrap();
assert!((npv - (-127.8016238)).abs() < 1e-6);

§Shape C — rate series, constant periodic cashflow

use finance_solution::net_present_value_schedule;
// rates for 3 periods; cashflows = [investment, repeating payment]
let npv = net_present_value_schedule(&[0.03, 0.04, 0.05], &[-1_000.0, 400.0]).unwrap();
assert!(npv.is_finite());

§Shape D — constant rate, full cashflow ladder

use finance_solution::net_present_value_schedule;
let npv = net_present_value_schedule(&[0.034], &[-1_000.0, 300.0, 400.0, 500.0]).unwrap();
assert!(npv.is_finite());

§Constant rate + constant cashflow (non-schedule API)

use finance_solution::net_present_value_solution;
let (rate, periods, initial_investment, cashflow) = (0.034, 3, -1000, 400);
let npv = net_present_value_solution(rate, periods, initial_investment, cashflow).unwrap();
let _ = npv; // .print_table() in apps

Sample table:

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

§Schedule solution with table

use finance_solution::net_present_value_schedule_solution;
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).unwrap();
let _ = npv; // .print_table() in apps

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..