%% Calculate Present Value for Regular and Irregular Cash Flow
% Calculate the net present value for a regular and irregular cash flow.
%% Regular Cash Flow
% This cash flow represents the yearly income from an initial investment of $10,000. The annual interest rate is 8%.
% Year 1 - $2000
% Year 2 - $1500
% Year 3 - $3000
% Year 4 - $3800
% Year 5 - $5000
% To calculate the net present value of this regular cash flow:

PresentVal = pvvar([-10000 2000 1500 3000 3800 5000], 0.08)

%
%% Irregular Cash Flow
% An investment of $10,000 returns this irregular cash flow. The original investment and its date are included. The periodic interest rate is 9%.
% January 12, 1987  -  ($1000)
% February 14, 1988 -  $1500
% March 3, 1988  -  $2000
% June 14, 1988  -  $3000
% December 1, 1988  - $4000
% To calculate the net present value of this irregular cash flow:

CashFlow = [-10000, 2500, 2000, 3000, 4000];

CFDates = ['01/12/1987'
            '02/14/1988'
            '03/03/1988'
            '06/14/1988'
            '12/01/1988'];

PresentVal = pvvar(CashFlow, 0.09, CFDates)

% The net present value of the same investment under different discount rates of 7%, 9%, and 11% is obtained by:

PresentVal = pvvar(repmat(CashFlow,3,1)', [.07 .09 .11], CFDates)

% Copyright 2020 The MathWorks, Inc.