%This case study is conducted with the portfolio retail %loans dataset provided by the Kukmin Bank, Korea. %Default scenarios of bonds are generated at the %Kukmin Bank with the CreditMetrix software from the RiskMetrics Group. %Scenarios data are imported to PSG by the Converter_VaR_Optimizaion %intended for processing the outputs from the CreditMetrix. %For a portfolio of clusters of retail loans the expected return %is maximized subject to the constraint on VaR deviation. %It is assumed that weights for clusters can be rebalanced %within 10% and 20% of the original weights. %This example implements Problem 1 of case study, %where total estimated return is maximized subject to %internal constraint on credit risk. %Weights for clusters can be rebalanced within 10% of the original weights. clear; format long; %Convert the problem from File Format files into the riskprog function run format. %Input data is stored in the MAT-file. problem_name = 'problem_1_Korea_retail_bound_0_1'; path_to_store = '.\CS_Retail_Portfolio_Bonds_Short\'; %Load the problem data: load('problem_1_Korea_retail_bound_0_1_data.mat'); %Read current portfolio weights: load('point_current_portfolio_weights.mat'); %Turn off displaying messages posted by calculating process stroptions.Display = 'Off'; risk2='var_dev'; stroptions.Path_to_Export_to_Text='.\text'; %Solve the optimization problem for specified values of the parameter [xout, fval, status, output] = riskconstrprog([], risk2, [], [], [], [], w2,... H2, c2, p2, -d, r, [], [], [], [], lb, ub, [], stroptions); %Display the solution: fprintf('Maximum of total estimated return = %f\n', -fval); fprintf('Internal constraint on credit risk = %f\n', output.frval2); fprintf('Component Name Value\n'); for i=1:1:length(xout) fprintf('%6s\t', component_name_arr{i}); fprintf('%14f\n', xout(i)); end %Build graph showing contributions to VaR Deviation of individual clusters %in the Optimal Portfolio (Increment). The Increment is calculated as the %difference between the VaR Deviation of the portfolio and %the VaR Deviation of the portfolio without this cluster. %Set number of points to be shown on the graph. The graph shows %n_plot maximal absolute values of increments. n_plot = 10; if n_plot > size(xout,1) n_plot > size(xout,1); end %Calculate increments for all clusters in the Optimal Portfolio [Increment_Opt] = functionincrement(risk2, w2, H2, c2, p2, xout); u = sort(abs(Increment_Opt), 'descend'); i = 0; for j=1:1:size(xout,1) if abs(Increment_Opt(j)) >= u(n_plot) i = i + 1; point_variables(i) = component_name_arr(j); Point1(i) = Increment_Opt(j); end end figure plot(Point1,'.', 'MarkerSize',20) set(gca,'XTick',1:1:size(point_variables',1)); hAxes = gca; set(hAxes, 'XTickLabel', point_variables'); grid on; xlabel('Clusters'); ylabel('Contributions to VaR Deviation'); title(sprintf('%0.f%s',n_plot,' Significant Values of Contributions to VaR Deviation of Individual Clusters in Optimal Portfolio')); %Build graph showing ratio of the contributions to the VaR Deviation %of individual clusters to the VaR_DEV of the Optimal Portfolio %(Relative Contribution) %Extract value of the VaR_DEV for the Optimal Portfolio from the %solution of the problem risk_opt = output.frval2; figure plot(Point1/risk_opt,'.', 'MarkerSize',20) set(gca,'XTick',1:1:size(point_variables',1)); hAxes = gca; set(hAxes, 'XTickLabel', point_variables'); grid on; xlabel('Clusters'); ylabel('Relative Contributions to VaR Deviation'); title(sprintf('%0.f%s',n_plot,' Significant Values of Relative Contributions to VaR Deviation')); %Build graph showing difference between weights of the Optimal %Portfolio and the current portfolio %The graph shows n_plot maximal absolute values of the difference. %Calculate the difference z = xout - current_point'; clear u; clear point_variables; clear Point1; u = sort(abs(z), 'descend'); i = 0; for j=1:1:size(xout,1) if abs(z(j)) >= u(n_plot) i = i + 1; point_variables(i) = component_name_arr(j); Point1(i) = z(j); end end figure plot(Point1,'.', 'MarkerSize',20) set(gca,'XTick',1:1:size(point_variables',1)); hAxes = gca; set(hAxes, 'XTickLabel', point_variables'); grid on; xlabel('Clusters'); ylabel('Values of the Difference'); title(sprintf('%0.f%s',n_plot,' Significant Values of Difference Between Components of Optimal and Current Points')); %Build graph showing difference between contributions to VaR Deviation %(increments) of individual clusters in the Optimal Portfolio and the % Current Portfolio. %Calculate increments for all clusters in the Current Portfolio [Increment_Curr] = functionincrement(risk2, w2, H2, c2, p2, current_point'); %Calculate the difference Increment_Dif = Increment_Opt - Increment_Curr; clear u; clear point_variables; clear Point1; u = sort(abs(Increment_Dif), 'descend'); i = 0; for j=1:1:size(xout,1) if abs(Increment_Dif(j)) >= u(n_plot) i = i + 1; point_variables(i) = component_name_arr(j); Point1(i) = Increment_Dif(j); end end figure plot(Point1,'.', 'MarkerSize',20) set(gca,'XTick',1:1:size(point_variables',1)); hAxes = gca; set(hAxes, 'XTickLabel', point_variables'); grid on; xlabel('Clusters'); ylabel('Values of the Difference'); title(sprintf('%0.f%s',n_plot,' Values of Difference Between Contributions to VaR Deviation of Optimal and Current Points')); %Build graph showing difference between %the ratio of the contributions to the VaR Deviation of individual clusters %to the VaR_DEV of the Optimal Portfolio(Relative Contribution in the %Optimal Portfolio) %and %the ratio of the contributions to the VaR Deviation of individual clusters %to the VaR_DEV of the Current Portfolio(Relative Contribution in the %Current Portfolio) %Culculate value of the VaR_DEV for the Current Portfolio [risk_current] = functionvalue(risk2, w2, H2, c2, p2, current_point'); clear u; clear point_variables; clear Point1; clear Increment_Dif; %Calculate the difference Increment_Dif = Increment_Opt/risk_opt - Increment_Curr/risk_current; u = sort(abs(Increment_Dif), 'descend'); i = 0; for j=1:1:size(xout,1) if abs(Increment_Dif(j)) >= u(n_plot) i = i + 1; point_variables(i) = component_name_arr(j); Point1(i) = Increment_Dif(j); end end figure plot(Point1,'.', 'MarkerSize',20) set(gca,'XTick',1:1:size(point_variables',1)); hAxes = gca; set(hAxes, 'XTickLabel', point_variables'); grid on; xlabel('Clusters'); ylabel('Values of the Difference'); title(sprintf('%0.f%s',n_plot,' Values of Difference Between Relative Contribution to VaR Deviation of the Optimal and Current Portfolios')); % Build the graph showing the exposures of the current portfolio. % The graph shows n_plot maximal values of the exposures. % Exposures with less values are combined into category "Others". u = sort(abs(current_point), 'descend'); i = 0; other = 0; for j=1:1:size(xout,1) if abs(current_point(j)) >= u(n_plot) i = i + 1; point_variables(i) = component_name_arr(j); Point1(i) = current_point(j); else other = other + current_point(j); end end Point1(n_plot+1) = other; point_variables(n_plot+1)={'other'}; figure; pie(Point1); legend(point_variables, 'Location','EastOutside'); title(sprintf('%0.f%s',n_plot,' Largest Exposures of the Current Portfolio')); % Build the graph showing the exposures of the optimal portfolio. % The graph shows n_plot maximal values of the exposures. % Exposures with less values are combined into category "Others". u = sort(abs(xout), 'descend'); i = 0; other = 0; for j=1:1:size(xout,1) if abs(current_point(j)) >= u(n_plot) i = i + 1; point_variables(i) = component_name_arr(j); Point1(i) = xout(j); else other = other + xout(j); end end Point1(n_plot+1) = other; point_variables(n_plot+1)={'other'}; figure; pie(Point1); legend(point_variables, 'Location','EastOutside'); title(sprintf('%0.f%s',n_plot,' Largest Exposures of the Optimal Portfolio')); % Build the histogram of losses for the optimal portfolio losses = -H2*xout; % Calculate losses [L, IX] = sort(losses); n_bins = 25; % number of bins %Calculate the bin locations and frequencies delta = (L(size(L,1)) - L(1))/n_bins; Y(1) = L(1) + delta/2; n(1) = 0; for j=2:1:n_bins n(j) = 0; Y(j) = Y(j-1) + delta; end i = 1; for j=1:1:size(L,1) if L(j) < Y(i) + delta/2 n(i) = n(i) + p2(IX(j)); else i = i+1; end end figure; bar(Y,n); xlabel('Losses'); title('Histogram of Losses for the Optimal Portfolio'); %=======================================================================| %American Optimal Decisions, Inc. Copyright | %Copyright ©American Optimal Decisions, Inc. 2007-2014. | %American Optimal Decisions (AOD) retains copyrights to this material. | % | %Permission to reproduce this document and to prepare derivative works | %from this document for internal use is granted, provided the copyright | %and “No Warranty” statements are included with all reproductions | %and derivative works. | % | %For information regarding external or commercial use of copyrighted | %materials owned by AOD, contact AOD at support@aorda.com. | %=======================================================================|