% =========================================================================
% Filename: Unrecov3.m
% Copyright (c) 2015 John George Anasis
% Code to compute unrecovered costs for resources that peak, then drop off
% over the time horizon of study. The version of the code is for the case
% where the peak occurs less than lambda years away from the end of the
% simulation. The number of years that have to be looked at for
% unrecovered costs is simply the time from the peak to the end of the
% simulation.
% Read in the initial optimization results of the resource of interest,
% along with the resource lifetime (lambda), time length of the simulation, time
% of the resource peak, and resource capital cost K, discount rate, and the
% total number of years that the resource was actually used.
% Note that the total number of years the resource was deployed may be made
% up of more than one time block (such as a few years of deployment early
% in the simulation, no deployment, then another block of deployment).
q = xlsread('peakq.xls');
peakparameters3 = xlsread('peakparameters3.xls');
lambda = peakparameters3(1); % Resource lifetime.
time = peakparameters3(2); % Total length of the simulation.
peaktime = peakparameters3(3); % Time resource peak occured in the simulation.
K = peakparameters3(4); % Resource capital cost.
dis_rate = peakparameters3(5); % Assumed discount rate.
usetime = peakparameters3(6); % Total number of years the resource was deployed in the actual simulation.
% Compute the resource's annual capital recovery cost per unit of resource
% deployed.
AnnCap = K * ( (dis_rate/(((1+dis_rate)^lambda)- 1)) + dis_rate );
% Create matrices to track the unrecovered actual cost of the resource deployed.
unrecovcost3 = zeros(time,1);
% Compute the number of years that need to be reviewed for unrecovered
% costs.
n = time - peaktime;
% Compute the unrecovered resource costs. Each unrecovered cost is
% converted to a net present value (NPV).
for u = (peaktime - n):peaktime
for v = (u + 1):(u + n)
if q(u) - q(v) > 0
rho = 1/((1+dis_rate)^v);
unrecovcost3(u) = ((q(u) - q(v)) * AnnCap * rho) + unrecovcost3(u);
end
end
end
% Compute the per unit unrecovered cost based on the total resource
% deployed over the entire simulation. Sum the NPV's of all the unrecovered costs
% and convert this to an annual payment stream over the total number of years the resource was actually deployed.
% Divide this annual stream by the sume of all the resource deployed over
% the full simulation to get a per unit annual adjustment value that can
% then be added to the resource cost.
unrecovpu3 = (sum(unrecovcost3(1:time)) * ( (dis_rate/(((1+dis_rate)^usetime)- 1)) + dis_rate )) /sum(q(1:time));
% Write out the results.
xlswrite('unrecovcost3.xls',unrecovcost3);
xlswrite('unrecovpu3.xls',unrecovpu3);