www.gusucode.com > GAVPai_Book_MathworksCntrlFileEx_May2019 > GAVPai_Book_MathworksCntrlFileEx_May2019/Chapter1_Unconstrained_PortfolioOptmzn.m
% Vijayalakshmi Pai G A, Metaheuristics for Portfolio Optimization, An % Introduction using MATLAB, ISTE-Wiley, 2017. % Graphing the efficient frontier for the unconstrained portfolio optimization model % Chapter 1 Sec. 1.3 B % Portfolio optimization model represented by equations [1.19]-[1.22] for % optimizing Portfolio P shown in Table 1.1 % Program coding: Dr G A Vijayalakshmi Pai % Note: Coding style has been kept naive and direct to favor novices in % MATLAB. Users familiar with MATLAB are encouraged to improvise the code %------------------------------------------------------------------------ % Input : Portfolio size (portfolio_size), Stock prices data set as xls file (file_name), column numbers of assets selected (asset_index) % Output: Optimal Risk (minimum_var_point) and Return (expected_pf_ret_point), % and plot of the efficient frontier fix(clock) echo off clear all disp('Unconstrained portfolio optimization: Graphing the Efficient frontier'); % input portfolio size, daily stock prices (time series) file, asset indices (column positions in the daily stock prices file) portfolio_size = 10; file_name = 'PortfolioP.xls'; % column numbers of assets of Portfolio P (Chapter 1, Table 1.1) in the % daily stock prices file asset_index=[ 1 2 3 4 5 6 7 8 9 10]; % compute mean and covariance of daily returns (percentage) for the assets [mean_data, cov_data]= mean_covariance_extraction(file_name, asset_index); % max portfolio return computation using linear programming [x, fval] = max_ret_objfun(portfolio_size, mean_data); exp_pf_ret_max= (mean_data * x); disp('the maximum expected portfolio return'); exp_pf_ret_max % min variance return computation using quadratic programming [y, min_obj_fun_val]= min_var_objfun(portfolio_size, cov_data); exp_pf_ret_min= mean_data*y; disp(' expected portfolio return corresponding to min variance'); exp_pf_ret_min % generate portfolio returns between the minimum and maximum points and % compute minimum variance for each of the portfolio returns using quadratic % programming i1=1; for exp_port_val= exp_pf_ret_min :0.001: exp_pf_ret_max [var_x, min_obj_fun_val]= min_var_cnstrobjfun(portfolio_size, mean_data, cov_data, exp_port_val); x_optimal(i1,:) = var_x; exp_pf_ret_point(i1)= exp_port_val; min_var_point(i1)= min_obj_fun_val; i1=i1+1; clear var_x min_obj_fun_val; end % compute annualized return and annualized risk minimum_var_point = sqrt(min_var_point *261) expected_pf_ret_point= exp_pf_ret_point * 261 % graph efficient frontier plot(minimum_var_point, expected_pf_ret_point, 'bd'); title('Efficient frontier for the portfolio P over S&P BSE 200 index '); xlabel('Annualized risk(%)'); ylabel('Expected portfolio annual return(%)');