www.gusucode.com > fininst 案例源码程序 matlab代码 > fininst/ViewContractValuesandExposuresOverTimeforaParticularCounExample.m
%% View Contract Values and Exposures Over Time for a Particular Counterparty % Copyright 2015 The MathWorks, Inc. %% % After computing the mark-to-market contract values for a portfolio of % swaps over many scenarios, compute the credit exposure for % a particular counterparty. View the contract values and credit exposure % over time. First, load data containing the mark-to-market contract values for a portfolio of swaps over many scenarios. load ccr.mat % Look at one counterparty. cpID = 4; cpValues = squeeze(sum(values(:,swaps.Counterparty == cpID,:),2)); subplot(2,1,1) plot(simulationDates,cpValues); title(sprintf('Mark-to-Market Contract Values for Counterparty: %d',cpID)); datetick('x','mmmyy') ylabel('Portfolio Value ($)') % Compute the exposure by counterparty. [exposures, expcpty] = creditexposures(values,swaps.Counterparty,... 'NettingID',swaps.NettingID); % View the credit exposure over time for the counterparty. subplot(2,1,2) cpIdx = find(expcpty == cpID); plot(simulationDates,squeeze(exposures(:,cpIdx,:))); title(sprintf('Exposure for counterparty: %d',cpIdx)); datetick('x','mmmyy') ylabel('Exposure ($)') xlabel('Simulation Dates')