In this Section we present the MATLAB functions used to perform the analysis and simulations. Functions used are:
Open image in new window
Function effront.m computes the mean variance efficient frontier solving a standard quadratic programming problem. Weights, expected returns and standard deviations of a set of efficient portfolios are provided as outputs. Optimal portfolios satisfy the expected return ranking constraint, i.e. they are equally distant in term of expected return. A short selling constraint is also imposed.
ERassets = row vector of asset expected returns;
Varcov = variance-covariance matrix of asset returns;
NumPortf = number of efficient portfolios to be computed.
Wmv = NumAsset*NumPortf - matrix of efficient portfolio weights;
ERmv = column vector of efficient portfolio expected returns;
SDmv = column vector of efficient portfolio standard deviations.
Function SimulMv.m performs out of sample simulation evaluating mean variance efficiency. Efficiency is in terms of realized Sharpe ratio and portfolio turnover.
RetSeriesTotal = Ttotal*NumAssets matrix collecting return time series (total stands for in-sample plus out-of-sample period);
T = length of in-sample period used in rolling simulations;
NumPortf = number of portfolios considered in the simulation.
ARRmv = vector collecting average realized returns for mean variance portfolios;
ASDmv = vector collecting average realized risk for mean variance portfolios;
ASR = vector collecting average realized Sharpe ratios for mean variance portfolios;
ATO = vector collecting average turnovers for mean variance portfolios.
Function SimulEW.m performs out of sample simulation evaluating equally weighted efficiency. Efficiency is in terms of realized Sharpe ratio and portfolio turnover.
RetSeriesTotal - Ttotal*NumAssets matrix collecting return time series. Total stands for in-sample plus out-of-sample period;
T - length of in-sample period used in rolling simulations;
NumPortf - number of portfolios considered in the simulation.
ARRew - vector collecting average realized returns for equally weighted portfolios;
ASDew - vector collecting average realized risk for equally weighted portfolios;
ASR - vector collecting average realized Sharpe ratios for equally weighted portfolios.
Function GetEwPortfolio.m generate the equally weighted portfolio, which is used as a benchmark for the mean-variance portfolio.
Function GetMyWeights.m generates a matrix containing mean variance portfolio weights for the set of ranks specified in PortSet (row vector collecting the ranks we want to analyze).
Wmv = NumAsset*NumPortf matrix collecting mean-variance portfolio weights
PortSet = 1 x NumRanks, collecting the ranks we want to analyze
MyWeights = NumAssets x NumRanks, mean-variance weights in a matrix
In next few steps we will explain how we performed in-sample and out-of-sample analysis.
To perform in-sample analysis:
Load a price time series, data.mat, into the workspace. Data.mat need to be a (T × K) matrix, where T indicates the number of prices and K the number of assets. Prices in data.mat start from the oldest observation up to the more recent ones. Then we compute discrete returns series:
RetSeriesTotal = price2ret (data,,’periodic’)
Call function GetEffront to generate mean variance efficient frontier
[Wmv, ERmv, SDmv] = GetEffront(RetSeries, NumPortf, InputType);
call function GetMyWeights in order to extract mean-variance weights for three portfolios ranks (GMV, I, M).
MyWeights = GetMyWeights(Wmv,PortSet);
Call function GetEwPortfolio to generate the equally weighted portfolio.
[Wew,ERew,SDew] = GetEwPortfolio(RetSeries,InputType);
To perform out-of-sample simulation:
Choose estimating window and number of rolling optimization to be performed in out of sample analysis - NumRoll. We choose that NUmRoll = 52 and three estimating windows – T = 90, T = 120 and T = 140.
Call function SimulMv.m - this function will repeatedly call mean variance procedure looking the performance of this method and storing results period by period. Input data T indicates the time length of the in-sample period; where we choose three estimating windows – T = 90, T = 120 and T = 140.
[ARR,ASD,ASR,ATO] = SimulMv(RetSeries,T,NumPortf,InputType)
We call function GetMyTable.m which give us a table which elements are: Average Portfolio Return (ARR), Average Standard Deviation (ASD), Average Sharpe Ratio (ASR) and Average Turnover (ATO):
Table = [ARR ASD ASR ATO].
MyTable = GetMyTable(Table,PortSet).
We did the same out of sample analysis reference to equally weighted portfolio!