www.gusucode.com > GAVPai_Book_MathworksCntrlFileEx_May2019 > GAVPai_Book_MathworksCntrlFileEx_May2019/Chapter1_MaxSharpeRatioOptmzn.m
% Vijayalakshmi Pai G A, Metaheuristics for Portfolio Optimization, An % Introduction using MATLAB, ISTE-Wiley, 2017. % A naive demonstration of Sharpe Ratio based Portfolio Optimization (equation [1.24]) % MATLAB Portfolio Object % Chapter 1 Sec. 1.3 D % 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 %------------------------------------------------------------------------ % risk free rate of return (r0) r0 = 0.01365; % mean return of assets in the portfolio - daily return (%) (mean_data) mean_data = [ 0.1370 0.0629 0.0955 0.1241 0.0467 0.0981 0.0582 0.1028 0.0815 0.0222]; % covariance of returns of assets in the portfolio - cov_data cov_data = [[ 6.379 2.547 2.285 3.893 4.650 3.290 3.285 3.651 2.000 3.041]; [2.547 4.747 1.493 2.527 3.127 2.289 2.071 2.180 1.294 3.573]; [2.285 1.493 4.416 2.249 2.465 1.949 1.953 2.301 1.912 1.828]; [3.893 2.527 2.249 7.294 4.731 3.359 3.259 3.763 2.066 2.922]; [4.650 3.127 2.465 4.731 9.540 5.011 3.754 5.081 2.490 3.397]; [3.290 2.289 1.949 3.359 5.011 6.267 2.895 3.644 1.700 2.515]; [3.285 2.071 1.953 3.259 3.754 2.895 5.367 2.944 1.966 2.367]; [3.651 2.180 2.301 3.763 5.081 3.644 2.944 6.587 1.980 2.648]; [2.000 1.294 1.912 2.066 2.490 1.700 1.966 1.980 4.524 1.667]; [3.041 3.573 1.828 2.922 3.397 2.515 2.367 2.648 1.667 5.592]]; % lower bounds of weights (LB) LB = [ 0 0 0 0 0 0 0 0 0 0]; % upper bounds of weights (UB) UB = [ 1 1 1 1 1 1 1 1 1 1 ]; % equality constraints (AE, BE) AE = [ 1 1 1 1 1 1 1 1 1 1]; BE =[1]; % declare portfolio object p p = Portfolio('RiskFreeRate', r0, 'AssetMean', mean_data, 'AssetCovar', cov_data, 'LowerBound', LB, 'UpperBound', UB, 'AEquality', AE, 'bEquality', BE ); % obtain optimal portfolio weights yielding maximal Sharpe Ratio pwgt = p.estimateMaxSharpeRatio; display(pwgt); % obtain annualized risk and return of the Sharpe Ratio based optimal portfolio risk_MaxSharpeRatio = p.estimatePortRisk(pwgt) *sqrt(261) return_MaxSharpeRatio = p.estimatePortReturn(pwgt)*261