% This case study maximizes annualized portfolio return on multiple sample % paths subject to constraint on Drawdown Deviation Maxinun Multiple. % It solves the optimization problem for several values of % upper bound on the Drawdown Deviation Maxinun Multiple by running % multiple times the mpsg-solver. % The program buillds tables with optimal points; builds efficient frontier % "Return vs. Drawdown Deviation Maximum Multiple"; % builds graph showing components of the optimal solution corresponding to % the first value of upper bound on the Drawdown Deviation Maxinun Multiple. clc clear %Generate list of matrices names: str_ = ['matrix_average_annualized_returns ' 'matrix_1 ' 'matrix_2 '... 'matrix_3 ' 'matrix_4 ' 'matrix_5 ' 'matrix_6 ' ... 'matrix_7 ' 'matrix_8 ' 'matrix_9 ' 'matrix_10 ' 'matrix_11']; matrices_names = strread(str_, '%s'); %Read and pack all matrices to PSG Toolbox format: clear toolboxstruc_arr; count = 1; for j=1:1:size(matrices_names,1) clear header_matrix; clear matrix_arr; [header_matrix, matrix_arr] = read_matrix([matrices_names{j} '.txt']); toolboxstruc_arr(count) = tbpsg_matrix_pack(matrices_names{j}, matrix_arr, header_matrix); count = count+1; end %Read and pack all points to PSG Toolbox format: clear header_point; clear point_arr; [header_point, lb] = read_point('point_lb.txt'); toolboxstruc_arr(count) = tbpsg_point_pack('point_lowerbounds', lb, header_point); count = count+1; clear header_point; clear point_arr; [header_point, ub] = read_point('point_ub.txt'); toolboxstruc_arr(count) = tbpsg_point_pack('point_upperbounds', ub, header_point); count = count+1; % Specifies a set of values of parameter (upper bound on risk) for which % runs should be conducted: Parameters = [0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.2 0.21 0.22]; %Generate fragments of the problem description common for all parameters: str1 = sprintf('maximize'); str2 = sprintf(' linear(matrix_average_annualized_returns)'); str4 = sprintf(' drawdownmulti_dev_max(matrix_1,...,matrix_11)'); str5 = sprintf('Box: >= point_lowerbounds, <= point_upperbounds'); str6 = sprintf('Solver: VAN, precision = 9'); for i=1:size(Parameters,2) %Generate parameter-specific fragment of the problem description str3 = sprintf('%s%.3f','Constraint: <= ', Parameters(i)); %Generate problem statement clear problem_statement; problem_statement = sprintf('%s\n', str1, str2, str3, str4, str5, str6); % 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); Points(:,i) = tbpsg_optimal_point_data(solution_str, outargstruc_arr)'; returns(i) = tbpsg_objective(solution_str, outargstruc_arr); risk(i) = tbpsg_constraints_data(solution_str, outargstruc_arr); end warning('on', 'all'); % output solution fprintf('Points: %d\n', length(risk)); str__ = ['Poin_1 ' 'Poin_2 ' 'Poin_3 ' 'Poin_4 ' 'Poin_5 ' 'Poin_6 ' 'Poin_7 ' 'Poin_8 ' 'Poin_9 ' 'Poin_10 ' 'Poin_11 ' 'Poin_12 ' 'Poin_13 ' 'Poin_14 ']; Point_N = strread(str__, '%s'); fprintf(' Point # Drawdown Deviation Maxinun Multiple Return\n'); for j=1:1: length(risk) fprintf('%7s%25f\t%19f\n', Point_N{j}, risk(j), returns(j)); end fprintf('\nOptimal Points:\n'); fprintf('\nComponent Point_1 Point_2 Point_3 Point_4 Point_5 Point_6 Point_7\n'); for i=1:1:length(point_variables) fprintf('%8s',point_variables{i}); for j=1:1: 7 fprintf('%12f', Points(i,j)); end fprintf('\n'); end fprintf('\nComponent Point_8 Point_9 Point_10 Point_11 Point_12 Point_13 Point_14\n'); for i=1:1:length(point_variables) fprintf('%8s',point_variables{i}); for j=8:1: 14 fprintf('%12f', Points(i,j)); end fprintf('\n'); end % display efficient frontier figure plot(risk,returns); grid on; xlabel('Drawdown Deviation Maximum Multiple'); ylabel('Return'); title('Efficient Frontier. Return vs. Drawdown Deviation Maximum Multiple '); % build graph showing components of the optimal solution corresponding to % the first value of the parameter. Only components exceeding lower bounds % are shown clear x; clear y; i = 0; for j=1:1:size(point_variables,2) if Points(j,1)> lb(j) i = i+1; x(i) = point_variables(j); y(i) = Points(j,1); end end figure bar(y,0.1,'c'); set(gca,'XTick',1:1:length(x)); hAxes = gca; set(hAxes, 'XTickLabel', x); grid on; xlabel('Components of Optimal Solution Exceeding Lower Bounds'); ylabel('Components Values'); title('Point 1: Drawdown Deviation Maximum Multiple = 0.05. Components of Optimal Solution Exceeding Lower Bounds'); %=======================================================================| %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. | %=======================================================================|