Project appraisal: NPV and IRR Open ↗
Code
% Invest 10 000 now, receive growing cash flows for 6 years
cf = [-10000 1800 2300 2700 3000 3100 3200];
rates = linspace(0, 0.25, 200);
v = arrayfun(@(r) pvvar(cf, r), rates);
r_irr = irr(cf);
subplot(2, 1, 1)
bar(0:6, cf), xlabel('year'), ylabel('cash flow'), title('Cash flows')
subplot(2, 1, 2)
plot(100*rates, v, 'LineWidth', 2), hold on
yline(0, 'k'), xline(100*r_irr, '--', sprintf('IRR = %.1f %%', 100*r_irr))
plot(8, pvvar(cf, 0.08), 'o', 'MarkerSize', 7), hold off
xlabel('discount rate (%)'), ylabel('net present value')
title(sprintf('NPV at 8 %%: %.0f → invest if the cost of capital is below the IRR', pvvar(cf, 0.08)))