When the New Oven Pays

net present value · break-even interest rate · bisection · monotone functions

A bakery can buy a new oven. flows[t] is the money the oven brings in during year t, in thousands of euros: flows[0] is today's price of the oven (negative), and every later entry is the extra profit at the end of year t (zero or positive). The project's net present value at interest rate r is

NPV(r) = \sum_{t} \frac{\text{flows}[t]}{(1 + r)^t}

A positive NPV means the oven earns more than putting the same money in the bank at rate r. The higher the rate, the less the future profits are worth today, so NPV falls as r rises. The break-even rate is the rate at which NPV is exactly 0: the bakery should buy the oven when it can borrow (or save) at any rate below it.

Write oven(flows, r) that returns a tuple (npv, break_even):

  • npv: the net present value at rate r;
  • break_even: the rate between 0 and 1 (0 % and 100 %) at which the NPV is 0, or None if the NPV is already negative at rate 0 (the oven never pays for itself). The tests promise that the NPV at rate 1 is negative, so when there is a break-even rate it lies in that range.

Examples

Input:  flows = [-1000, 400, 400, 400], r = 0.05
Output: (89.29921175, 0.0970102574)
Explanation: at 5 % the three profits are worth 1089.30 today, 89.30 more than the
oven costs. The NPV reaches 0 at a rate of about 9.70 %.

Input:  flows = [-1000, 300, 300, 300], r = 0.05
Output: (-183.02559119, None)
Explanation: 900 in profits never repay 1000, whatever the rate.

Input:  flows = [-500, 0, 0, 0, 0, 1000], r = 0.1
Output: (120.92132306, 0.148698355)

Constraints

  • both numbers are compared with a tolerance of 1e-6, so aim for a break-even rate accurate to about 1e-9

Goals

  • Compute a project's net present value at a given interest rate
  • Find the break-even rate where the net present value is zero by repeated halving
  • Read the investment decision from the comparison of the two rates
Starting Python…