%This m-file demonstrates the second setup simultaneously optimizing the %CDO portfolio and credit tranching subject to a risk constraint assuring %the rating of a tranche, a constraint on income spread payments, %and a budget constraint. clc clear; %Load data from file: load('Data_for_Step-up_CDO_II_Toolbox.mat'); tbpsg_export_to_workspace(toolboxstruc_arr); N_attach_points = 5; %Specify the set of values of upper bound on probability that the %cumulative collateral loss exceeds the tranche attachment point %at least once in periods 1,…, T). Columns correspond to credit rating %(BBB, A, AA, AAA) Param_Mult_Prob = [0.0281 0.0071 0.0036 0.0012]; %Specify the set of values of lower bound on income spread payments Param_lower_bound =[91 93 95 97]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Optimization Problem 6 (Example 4) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Generate fragments of the problem description common for all parameter %values within Optimization Problem 6 (Example 4) str1 = sprintf('Problem: problem_example_4, type = minimize'); str2 = sprintf('Objective: objective_linear_sum_of_x_5, linearize = 0'); str3 = sprintf('linear_sum_of_x_5(matrix_sum_of_x_5)'); str5 = sprintf('prmulti_pen_5_periods(0.00000000,matrix_example_4_1,matrix_example_4_2,matrix_example_4_3,matrix_example_4_4,matrix_example_4_5)'); str7 = sprintf('linear_spread(matrix_spread)'); str8 = sprintf('Constraint: constraint_budget, lower_bound = 1, upper_bound = 1, linearize = 0'); str9 = sprintf('linear_budget(matrix_budget)'); str10 = sprintf('Box_of_Variables: lowerbounds = point_lowerbounds, upperbounds = point_upperbounds'); str11 = sprintf('Solver: VAN, precision = 2, stages = 6'); %Begin two loops for Optimization Problem 6 (Example 4) over parameter values for i=1:1:length(Param_Mult_Prob) %Generate parameter-specific fragment of the problem description str4 = sprintf('%s%.4f','Constraint: constraint_mult_prob, upper_bound = ',Param_Mult_Prob(i)); for j1=1:1:length(Param_lower_bound) %Generate parameter-specific fragment of the problem description str6 = sprintf('%s%.0f','Constraint: constraint_spread, lower_bound = ',Param_lower_bound(j1)); %Generate problem statement clear problem_statement; problem_statement = sprintf('%s\n', str1, str2, str3, str4, str5,... str6, str7, str8, str9, str10, str11); %Uncomment the following line to open the problem in Toolbox Window: %tbpsg_toolbox(problem_statement,toolboxstruc_arr); %Optimize the problem [solution_str, outargstruc_arr] = tbpsg_run(problem_statement, toolboxstruc_arr); %Extract optimal solution point_variables = tbpsg_optimal_point_vars(solution_str, outargstruc_arr); loc = tbpsg_optimal_point_data(solution_str, outargstruc_arr); Points_Problem_6(:,j1,i)= loc'; Sum_Attach_Points_Problem_1(j1,i) = tbpsg_objective(solution_str, outargstruc_arr); constr_data = tbpsg_constraints_data(solution_str, outargstruc_arr); Multiple_Probabilities_Problem_1(j1,i) = constr_data(2); end end warning('on', 'all'); str_ = ['BBB ' 'A ' 'AA ' 'AAA ']; ratings = strread(str_, '%s'); clear str_; str_ = ['Attachment_Point_1 ' 'Attachment_Point_2 ' 'Attachment_Point_3 ' 'Attachment_Point_4 ' 'Attachment_Point_5 ' ]; attach_points_names = strread(str_, '%s'); attach_points_names = strrep(attach_points_names, '_', ' '); clear str_; str_ = ['Attach._Point_1 ' 'Attach._Point_2 ' 'Attach._Point_3 ' 'Attach._Point_4 ' 'Attach._Point_5 ' ]; attach_points_names_graph = strread(str_, '%s'); attach_points_names_graph = strrep(attach_points_names_graph, '_', ' '); clear str_; str_ = ['period_t=1 ' 'period_t=2 ' 'period_t=3 ' 'period_t=4 ' 'period_t=5 ']; period_names = strread(str_, '%s'); period_names = strrep(period_names, '_', ' '); clear str_; % display and save table with results of calculations outfilename = 'Step-up_CDO_II_Output_Short.txt'; fid = fopen(outfilename, 'w'); fprintf('Table 1. Example 4: Attachment Points vs. Rating for Lower Bound on Income Spread Payments = 91\n'); fprintf(fid, 'Table 1. Example 4: Attachment Points vs. Rating for Lower Bound on Income Spread Payments = 91\n'); fprintf('Rating Attach.Point 1 Attach.Point 2 Attach.Point 3 Attach.Point 4 Attach.Point 5\n'); fprintf(fid, 'Rating Attach.Point 1 Attach.Point 2 Attach.Point 3 Attach.Point 4 Attach.Point 5\n'); for i=1:1:length(Param_Mult_Prob) fprintf('%5s',ratings{i}); fprintf(fid,'%5s',ratings{i}); for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 fprintf('%16f',Points_Problem_6(j,1,i)); fprintf(fid,'%16f',Points_Problem_6(j,1,i)); end end fprintf('\n'); fprintf(fid,'\n'); end fprintf('\n'); fprintf(fid,'\n'); fprintf('Table 2. Example 4: Attachment Points vs. Rating for Lower Bound on Income Spread Payments = 93\n'); fprintf(fid, 'Table 2. Example 4: Attachment Points vs. Rating for Lower Bound on Income Spread Payments = 93\n'); fprintf('Rating Attach.Point 1 Attach.Point 2 Attach.Point 3 Attach.Point 4 Attach.Point 5\n'); fprintf(fid, 'Rating Attach.Point 1 Attach.Point 2 Attach.Point 3 Attach.Point 4 Attach.Point 5\n'); for i=1:1:length(Param_Mult_Prob) fprintf('%5s',ratings{i}); fprintf(fid,'%5s',ratings{i}); for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 fprintf('%16f',Points_Problem_6(j,2,i)); fprintf(fid,'%16f',Points_Problem_6(j,2,i)); end end fprintf('\n'); fprintf(fid,'\n'); end fprintf('\n'); fprintf(fid,'\n'); fprintf('Table 3. Example 4: Attachment Points vs. Rating for Lower Bound on Income Spread Payments = 95\n'); fprintf(fid, 'Table 3. Example 4: Attachment Points vs. Rating for Lower Bound on Income Spread Payments = 95\n'); fprintf('Rating Attach.Point 1 Attach.Point 2 Attach.Point 3 Attach.Point 4 Attach.Point 5\n'); fprintf(fid, 'Rating Attach.Point 1 Attach.Point 2 Attach.Point 3 Attach.Point 4 Attach.Point 5\n'); for i=1:1:length(Param_Mult_Prob) fprintf('%5s',ratings{i}); fprintf(fid,'%5s',ratings{i}); for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 fprintf('%16f',Points_Problem_6(j,3,i)); fprintf(fid,'%16f',Points_Problem_6(j,3,i)); end end fprintf('\n'); fprintf(fid,'\n'); end fprintf('\n'); fprintf(fid,'\n'); fprintf('Table 4. Example 4: Attachment Points vs. Rating for Lower Bound on Income Spread Payments = 97\n'); fprintf(fid, 'Table 4. Example 4: Attachment Points vs. Rating for Lower Bound on Income Spread Payments = 97\n'); fprintf('Rating Attach.Point 1 Attach.Point 2 Attach.Point 3 Attach.Point 4 Attach.Point 5\n'); fprintf(fid, 'Rating Attach.Point 1 Attach.Point 2 Attach.Point 3 Attach.Point 4 Attach.Point 5\n'); for i=1:1:length(Param_Mult_Prob) fprintf('%5s',ratings{i}); fprintf(fid,'%5s',ratings{i}); for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 fprintf('%16f',Points_Problem_6(j,4,i)); fprintf(fid,'%16f',Points_Problem_6(j,4,i)); end end fprintf('\n'); fprintf(fid,'\n'); end fprintf('\n'); fprintf(fid,'\n'); fprintf('Table 5. Structure of Optimal CDO Portfolio (rating BBB) for Different Lower Bounds on Income Spread Payments\n'); fprintf(fid, 'Table 5. Structure of Optimal CDO Portfolio (rating BBB) for Different Lower Bounds on Income Spread Payments\n'); fprintf('Instrument Spread Payment = 91 Spread Payment = 93 Spread Payment = 95 Spread Payment = 97\n'); fprintf(fid, 'Instrument Spread Payment = 91 Spread Payment = 93 Spread Payment = 95 Spread Payment = 97\n'); for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1) == 0 fprintf('%7s',point_variables{j}); fprintf(fid,'%7s',point_variables{j}); for j1=1:1:size(Param_lower_bound,2) fprintf('%21f',Points_Problem_6(j,j1,1)); fprintf(fid,'%21f',Points_Problem_6(j,j1,1)); end end fprintf('\n'); fprintf(fid,'\n'); end fprintf('\n'); fprintf(fid,'\n'); fprintf('Table 6. Structure of Optimal CDO Portfolio (rating A) for Different Lower Bounds on Income Spread Payments\n'); fprintf(fid, 'Table 6. Structure of Optimal CDO Portfolio (rating A) for Different Lower Bounds on Income Spread Payments\n'); fprintf('Instrument Spread Payment = 91 Spread Payment = 93 Spread Payment = 95 Spread Payment = 97\n'); fprintf(fid, 'Instrument Spread Payment = 91 Spread Payment = 93 Spread Payment = 95 Spread Payment = 97\n'); for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1) == 0 fprintf('%7s',point_variables{j}); fprintf(fid,'%7s',point_variables{j}); for j1=1:1:size(Param_lower_bound,2) fprintf('%21f',Points_Problem_6(j,j1,2)); fprintf(fid,'%21f',Points_Problem_6(j,j1,2)); end end fprintf('\n'); fprintf(fid,'\n'); end fprintf('\n'); fprintf(fid,'\n'); fprintf('Table 7. Structure of Optimal CDO Portfolio (rating AA) for Different Lower Bounds on Income Spread Payments\n'); fprintf(fid, 'Table 7. Structure of Optimal CDO Portfolio (rating AA) for Different Lower Bounds on Income Spread Payments\n'); fprintf('Instrument Spread Payment = 91 Spread Payment = 93 Spread Payment = 95 Spread Payment = 97\n'); fprintf(fid, 'Instrument Spread Payment = 91 Spread Payment = 93 Spread Payment = 95 Spread Payment = 97\n'); for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1) == 0 fprintf('%7s',point_variables{j}); fprintf(fid,'%7s',point_variables{j}); for j1=1:1:size(Param_lower_bound,2) fprintf('%21f',Points_Problem_6(j,j1,3)); fprintf(fid,'%21f',Points_Problem_6(j,j1,3)); end end fprintf('\n'); fprintf(fid,'\n'); end fprintf('\n'); fprintf(fid,'\n'); fprintf('Table 8. Structure of Optimal CDO Portfolio (rating AAA) for Different Lower Bounds on Income Spread Payments\n'); fprintf(fid, 'Table 8. Structure of Optimal CDO Portfolio (rating AAA) for Different Lower Bounds on Income Spread Payments\n'); fprintf('Instrument Spread Payment = 91 Spread Payment = 93 Spread Payment = 95 Spread Payment = 97\n'); fprintf(fid, 'Instrument Spread Payment = 91 Spread Payment = 93 Spread Payment = 95 Spread Payment = 97\n'); for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1) == 0 fprintf('%7s',point_variables{j}); fprintf(fid,'%7s',point_variables{j}); for j1=1:1:size(Param_lower_bound,2) fprintf('%21f',Points_Problem_6(j,j1,4)); fprintf(fid,'%21f',Points_Problem_6(j,j1,4)); end end fprintf('\n'); fprintf(fid,'\n'); end fprintf('\n'); fprintf(fid,'\n'); % build graph showing attachment points for various ratings for Problem 6, % (CS.42)-(CS.46), with the lower bound on received average spread % payments = 91 in the constraint (CS.44). clear Y; for i=1:1:length(Param_Mult_Prob) j1 =0; for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 j1 = j1+1; Y(j1,i)= Points_Problem_6(j,1,i); end end end figure bar(Y,'group'); set(gca,'XTick',1:1:length(attach_points_names_graph)); hAxes = gca; set(hAxes, 'XTickLabel', attach_points_names_graph); grid on; legend(ratings, 'Location', 'NorthWest'); %xlabel('Names of Attachment Points'); ylabel('Values of Attachment Points'); title('Attachment Points for Problem 6 with the lower bound spread payments = 91 '); % build graph showing attachment points for various ratings for Problem 6, % (CS.42)-(CS.46), with the lower bound on received average spread % payments = 93 in the constraint (CS.44). clear Y; for i=1:1:length(Param_Mult_Prob) j1 =0; for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 j1 = j1+1; Y(j1,i)= Points_Problem_6(j,2,i); end end end figure bar(Y,'group'); set(gca,'XTick',1:1:length(attach_points_names_graph)); hAxes = gca; set(hAxes, 'XTickLabel', attach_points_names_graph); grid on; legend(ratings, 'Location', 'NorthWest'); %xlabel('Names of Attachment Points'); ylabel('Values of Attachment Points'); title('Attachment Points for Problem 6 with the lower bound spread payments = 93 '); % build graph showing attachment points for various ratings for Problem 6, % (CS.42)-(CS.46), with the lower bound on received average spread % payments = 95 in the constraint (CS.44). clear Y; for i=1:1:length(Param_Mult_Prob) j1 =0; for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 j1 = j1+1; Y(j1,i)= Points_Problem_6(j,3,i); end end end figure bar(Y,'group'); set(gca,'XTick',1:1:length(attach_points_names_graph)); hAxes = gca; set(hAxes, 'XTickLabel', attach_points_names_graph); grid on; legend(ratings, 'Location', 'NorthWest'); %xlabel('Names of Attachment Points'); ylabel('Values of Attachment Points'); title('Attachment Points for Problem 6 with the lower bound spread payments = 95 '); % build graph showing attachment points for various ratings for Problem 6, % (CS.42)-(CS.46), with the lower bound on received average spread % payments = 97 in the constraint (CS.44). clear Y; for i=1:1:length(Param_Mult_Prob) j1 =0; for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 j1 = j1+1; Y(j1,i)= Points_Problem_6(j,4,i); end end end figure bar(Y,'group'); set(gca,'XTick',1:1:length(attach_points_names_graph)); hAxes = gca; set(hAxes, 'XTickLabel', attach_points_names_graph); grid on; legend(ratings, 'Location', 'NorthWest'); %xlabel('Names of Attachment Points'); ylabel('Values of Attachment Points'); title('Attachment Points for Problem 6 with the lower bound spread payments = 97 '); % build graph showing attachment points (rating BBB) for optimal points of Problem 6, % (CS.42)-(CS.46) on different values of the lower bound on received % average spread payments (91,93,95,97) in the constraint (CS.44). clear Y; for j1=1:1:length(Param_lower_bound) j2 =0; for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 j2 = j2+1; Y(j1,j2)= Points_Problem_6(j,j1,1); end end end figure bar(Y,'group'); set(gca,'XTick',1:1:length(Param_lower_bound)); hAxes = gca; set(hAxes, 'XTickLabel', Param_lower_bound'); grid on; legend(attach_points_names_graph, 'Location', 'NorthWest'); xlabel('Lower Bound on Income Spread Payments'); ylabel('Values of Attachment Points'); title('Attachment Points (rating BBB) vs. Lower Bound on Income Spread Payments'); % build graph showing attachment points (rating A) for optimal points of Problem 6, % (CS.42)-(CS.46) on different values of the lower bound on received % average spread payments (91,93,95,97) in the constraint (CS.44). clear Y; for j1=1:1:length(Param_lower_bound) j2 =0; for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 j2 = j2+1; Y(j1,j2)= Points_Problem_6(j,j1,2); end end end figure bar(Y,'group'); set(gca,'XTick',1:1:length(Param_lower_bound)); hAxes = gca; set(hAxes, 'XTickLabel', Param_lower_bound'); grid on; legend(attach_points_names_graph, 'Location', 'NorthWest'); xlabel('Lower Bound on Income Spread Payments'); ylabel('Values of Attachment Points'); title('Attachment Points (rating A) vs. Lower Bound on Income Spread Payments'); % build graph showing attachment points (rating AA) for optimal points of Problem 6, % (CS.42)-(CS.46) on different values of the lower bound on received % average spread payments (91,93,95,97) in the constraint (CS.44). clear Y; for j1=1:1:length(Param_lower_bound) j2 =0; for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 j2 = j2+1; Y(j1,j2)= Points_Problem_6(j,j1,3); end end end figure bar(Y,'group'); set(gca,'XTick',1:1:length(Param_lower_bound)); hAxes = gca; set(hAxes, 'XTickLabel', Param_lower_bound'); grid on; legend(attach_points_names_graph, 'Location', 'NorthWest'); xlabel('Lower Bound on Income Spread Payments'); ylabel('Values of Attachment Points'); title('Attachment Points (rating AA) vs. Lower Bound on Income Spread Payments'); % build graph showing attachment points (rating AAA) for optimal points of Problem 6, % (CS.42)-(CS.46) on different values of the lower bound on received % average spread payments (91,93,95,97) in the constraint (CS.44). clear Y; for j1=1:1:length(Param_lower_bound) j2 =0; for j=1:1:size(Points_Problem_6,1) if size(findstr(point_variables{j}, 'attach'),1)>0 j2 = j2+1; Y(j1,j2)= Points_Problem_6(j,j1,4); end end end figure bar(Y,'group'); set(gca,'XTick',1:1:length(Param_lower_bound)); hAxes = gca; set(hAxes, 'XTickLabel', Param_lower_bound'); grid on; legend(attach_points_names_graph, 'Location', 'NorthWest'); xlabel('Lower Bound on Income Spread Payments'); ylabel('Values of Attachment Points'); title('Attachment Points (rating AAA) vs. Lower Bound on Income Spread Payments'); %=======================================================================| %American Optimal Decisions, Inc. Copyright | %Copyright ©American Optimal Decisions, Inc. 2007-2016. | %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. | %=======================================================================|