% =========================================================================
% Filename: Unrecov4.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. This version covers the case where the
% peak occurs before time t=lambda.
% 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');
peakparameters = xlsread('peakparameters4.xls');
lambda = peakparameters4(1); % Resource lifetime.
time = peakparameters4(2); % Total length of the simulation.
peaktime = peakparameters4(3); % Time resource peak occured in the simulation.
K = peakparameters4(4); % Resource capital cost.
dis_rate = peakparameters4(5); % Assumed discount rate.
usetime = peakparameters4(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.
unrecovcost = zeros(time,1);
% Compute the unrecovered resource costs. Each unrecovered cost is
% converted to a net present value (NPV).
%for u = (peaktime - lambda):peaktime
for u = 1:peaktime
for v = (u + 1):(u + lambda)
if q(u) - q(v) > 0
rho = 1/((1+dis_rate)^v);
unrecovcost(u) = ((q(u) - q(v)) * AnnCap *rho) + unrecovcost(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 sum 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.
unrecovpu = (sum(unrecovcost(1:time)) * ( (dis_rate/(((1+dis_rate)^usetime)- 1)) + dis_rate ))/sum(q(1:time));
% Write out the results.
xlswrite('unrecovcost.xls',unrecovcost);
xlswrite('unrecovpu.xls',unrecovpu);