%% View Exposure Profiles of a Particular Counterparty
% After computing the mark-to-market contract values for a portfolio of swaps over many scenarios, view the exposure profiles of a particular counterparty.
% Load the data (ccr.mat) that contains the mark-to-market contract values for a portfolio of swaps over many scenarios.

load ccr.mat

%
% Compute the exposure by counterparty.

[exposures, expcpty] = creditexposures(values,swaps.Counterparty,...
'NettingID',swaps.NettingID);

%
% Compute the credit exposure profiles for all counterparties.

 cpProfiles = exposureprofiles(simulationDates,exposures)

%
% Visualize the exposure profiles for a particular counterparty.

cpIdx = find(expcpty == 4);
numDates = numel(simulationDates);
plot(simulationDates,cpProfiles(cpIdx).PFE,...
        simulationDates,cpProfiles(cpIdx).MPFE * ones(numDates,1),...
        simulationDates,cpProfiles(cpIdx).EE,...
        simulationDates,cpProfiles(cpIdx).EPE * ones(numDates,1),...
        simulationDates,cpProfiles(cpIdx).EffEE,...
        simulationDates,cpProfiles(cpIdx).EffEPE * ones(numDates,1));
legend({'PFE (95%)','Max PFE','Exp Exposure (EE)',...
        'Time-Avg EE (EPE)','Max past EE (EffEE)',...
        'Time-Avg EffEE (EffEPE)'})
datetick('x','mmmyy','keeplimits')
title(sprintf('Counterparty %d Exposure Profiles',cpIdx));
ylabel('Exposure ($)')
xlabel('Simulation Dates')

% Copyright 2012 The MathWorks, Inc.