% This case study solves two optimization problems: % (1) maximizing annualized portfolio return on multiple sample % paths subject to constraint on CDaR Deviation Multiple; % (2) maximizing annualized portfolio return on a single sample % path, which is the union of all scenarios extracted from % multiple sample paths, subject to constraint on CDaR Deviation. % Finally, it compares solutions of these two optimization problems. clc clear %Load data prepared in PSG Toolbox format and packed in structure 'toolboxstruc_arr': load CS_CDaR_Single_Path_vs_CDaR_Multiple_Paths_Toolbox_data.mat 'toolboxstruc_arr' tbpsg_export_to_workspace(toolboxstruc_arr); %Generate problem statement for CDaR Deviation Multiple: str1_1 = sprintf('maximize'); str1_2 = sprintf('linear_average_returns(matrix_average_annualized_returns)'); str1_3 = sprintf('Constraint: <= 0.023'); str1_4 = sprintf('cdarmulti_dev(0.8, matrix_1,...,matrix_11)'); str1_5 = sprintf('Box: >= point_lowerbounds, <= point_upperbounds'); str1_6 = sprintf('Solver: TANK, precision = 9'); clear problem_statement1; problem_statement1 = sprintf('%s\n', str1_1, str1_2, str1_3, str1_4, str1_5, str1_6); %Optimize the first problem: [solution_str1, outargstruc_arr1] = tbpsg_run(problem_statement1, toolboxstruc_arr); %Extract optimal solution: point_variables1 = tbpsg_optimal_point_vars(solution_str1, outargstruc_arr1); Points1 = tbpsg_optimal_point_data(solution_str1, outargstruc_arr1)'; %Generate problem statement for CDaR Deviation Single: str2_1 = sprintf('maximize'); str2_2 = sprintf('linear(matrix_average_annualized_returns)'); str2_3 = sprintf('Constraint: <= 0.023'); str2_4 = sprintf('cdar_dev(0.8, matrix_H)'); str2_5 = sprintf('Box: >= point_lowerbounds, <= point_upperbounds'); str2_6 = sprintf('Solver: TANK, precision = 9'); clear problem_statement2; problem_statement2 = sprintf('%s\n', str2_1, str2_2, str2_3, str2_4, str2_5, str2_6); %Optimize the second problem: [solution_str2, outargstruc_arr2] = tbpsg_run(problem_statement2, toolboxstruc_arr); %Extract optimal solution: point_variables2 = tbpsg_optimal_point_vars(solution_str2, outargstruc_arr2); Points2 = tbpsg_optimal_point_data(solution_str2, outargstruc_arr2)'; %Display table comparing two solutions: fprintf('\n%s','Components Solution with CDaR_DEV Multiple Solution with CDaR_DEV Single'); for j=1:size(point_variables2,2) fprintf('\n%s\t\t\t\t\t%.4f\t\t\t\t\t\t\t%.4f', point_variables2{j}, Points1(j), Points2(j)); end fprintf('\n'); %Generate graph comparing two solutions. %Select instruments that have different positions in two optimal solutions: i = 0; for j=1:size(point_variables2,2) if abs(Points1(j)- Points2(j))>1E-6 i = i + 1; point_variables(i) = point_variables2(j); Point1(i) = Points1(j); Point2(i) = Points2(j); end end Points =[Point1' Point2']; str_points = ['CDaR_Dev_Multiple ' 'CDaR_Dev_Single ']; leg = strread(str_points, '%s'); leg = strrep(leg, '_', ' '); figure plot(Points,'.', 'MarkerSize',20) set(gca,'XTick',1:1:size(point_variables',1)); hAxes = gca; set(hAxes, 'XTickLabel', point_variables'); grid on; legend(leg, 'Location', 'NorthWest'); xlabel('Instruments Having Different Positions in Two Optimal Solutions'); ylabel('Value of Position '); title('Comparison of Solutions Obtained with CDaR Dev Multiple and CDaR Dev Single'); %=======================================================================| %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. | %=======================================================================|