The Black-Litterman Model 1 The Black Litterman Model for Portfolio Optimization and Analysis Samuel Wood Washington University in St. Louis Department of Electrical and Systems Engineering The Black-Litterman Model 2 ABSTRACT The Black-Litterman model for risky asset allocation attempts to improve on the portfolio optimization techniques defined under Modern Portfolio Theory first proposed by Henry Markowitz in the 1950s. In this paper, I attempt to explain the model and construct an experiment to test its effectiveness in both establishing a benchmark and expressing views by comparing it to a portfolio weighted using market capitalization and a portfolio constructed using the mean-variance optimizations methods from Markowitz. The experiment was conducted in a blind round and a non-blind round using historical data and different sets of portfolio assets. Through this experiment I learned about poor implementations of the model and how they can affect results negatively. Even though my results were not impressive, I was able to establish that with the proper understanding and forecasting ability, the Black-Litterman model can be an improved alternative to the original portfolio optimization methods. The Black-Litterman Model 3 Table of Contents Introduction and Background ......................................................................................................... 4 Problem Statement and Objectives ................................................................................................. 5 Methods........................................................................................................................................... 6 Results ........................................................................................................................................... 12 Discussion ..................................................................................................................................... 13 Conclusions ................................................................................................................................... 13 References ..................................................................................................................................... 16 Appendix A ................................................................................................................................... 17 Appendix B ................................................................................................................................... 19 Appendix C ................................................................................................................................... 21 The Black-Litterman Model 4 Introduction and Background In March of 1952, Harry Markowitz published the paper “Portfolio Selection” in The Journal of Finance. In it, he outlines a method for portfolio marking the inception of Modern Portfolio Theory in finance. The method attempts to maximize portfolio expected return given a certain level of risk using the mean and variance of expected returns for individual assets. This paper, along with two others, outline one of the most significant contributions to modern day finance and earned Markowitz a Nobel Prize in economics. While mean-variance optimization might be the best structured theory we have for optimizing portfolios it is difficult to implement in practice. The output asset weights are extremely sensitive to inputs and the inputs are extremely difficult to obtain. It also is not possible for investors to express their opinions on relative asset performance and their confidence in their selected expected asset returns. There are several methods beyond Markowitz that use its basic structure but attempt to address its major implementation problems. One notable method that attempts to improve upon the standard mean-variance optimization model is the Black-Litterman model for portfolio allocation. It was first created in 1990 at Goldman Sachs by Fischer Black and Robert Litterman and published in the paper “Global Portfolio Optimization” published in 1992 September/October edition of Financial Analysts Journal. In it they outline a model that provides a better method asset return generation than estimating returns and a method that provides and intuitive and clear way for investors to express, or on the contrary not express, their relative views on future asset performance. Their method for asset return generation attempts to create a starting point for shrinkage of the covariance matrix by using reverse optimization to back into distributions of returns from the equilibrium market portfolio. From this equilibrium distribution, investors views, both partial The Black-Litterman Model 5 and complete, are allowed to be combined with prior information generating adjusted returns that are incorporated into the mean-variance optimization model. After the Black-Litterman method was published in 1992 many other versions of the method were created some being more mathematically sound that others. One partial reason for the variation of methods is that a complete mathematical representation was not published in the initial article. Only framework for the method along with a difficult worked example based on the global equilibrium. Many of the methods published include incorrect speculations and mathematically unsound adjustments. This includes many so called “Beyond Black-Litterman” models that attempt to remove some of the canonical structures. Many of these have been debunked as useful models. Many legitimate extensions to the Black-Litterman model have been created some of which are not consistent with the original. Models truly based of BlackLitterman must have its estimates as distributions and include the parameter Tau. Problem Statement and Objectives I would like to implement the Black-Litterman model for asset allocation in its canonical form and test its performance in comparison with the market and the original mean-variance optimization method. Investors have been searching for an improved method of portfolio optimization for years. There is much discrepancy in the effectiveness of certain methods of portfolio optimization because of the inability in reproducing a consistent test experiment. I will use various methods for portfolio comparison to test multiple portfolios against each other using sets of historical data obtained from Yahoo finance. My first objective will to be to set up a portfolio construction tool using MATLAB that will take in names of stocks and a historical time horizons and generate a portfolio with weights based on market capitalization during the first date of the horizon. Functions included in the tool The Black-Litterman Model 6 will calculated portfolio performance measures based on risk, return, and the risk return trade off. The portfolio tool will also include functions that reallocate weights based on different both traditional mean-variance optimization and the Black-Litterman model for asset allocation. My second objective will to be to test the Black-Litterman model against the market weighted portfolio and the traditional mean-variance optimization method. This may be difficult because experiments are impossible to be completely controlled and opinions of future stock performance may be incorrect or they may change during the course of the horizon period. As the portfolio will not be rebalanced because of assumptions that it is costly, this could have an effect on the overall portfolio performance. Models will be evaluated on both risk and return but most importantly their risk-return trade off. Methods MATLAB Portfolio Implementation The main purpose of this paper was to compare different methods of portfolio optimization, specifically the Black-Litterman model, but in order to test these models an implementation framework was required. I chose to use MATLAB as the computing program for the implementation of my experiment. It is easy to use, allows for object oriented programing and allows for simple access to historical data on companies through Yahoo Finance. The portfolios were constructed using the Cell Array class and filled with stocks represented by using the Structures class. Functions were made to pull stock information and implant it into stocks, organize them into portfolios, optimize weights, and measure performance. I was going to use the object-oriented interface in MATLAB for the basis of the portfolio construction, but the other method was simpler to implement and accomplishes the same task. Normally, I would be The Black-Litterman Model 7 concerned with the speed and overall organization of the program but because this is only meant to explore historical data and will not be used in the future I don’t see it as a problem. Explanation of Markowitz and CAPM Basic Markowitz portfolio optimization uses linear algebra and statistical assumptions of future asset returns to create optimal weights for asset allocation. The optimal portfolio is based off of the interpretation that risk is represented by volatility and the method minimizes a portfolios standard deviation while maximizing its expected return. It makes the assumption that all investors are risk averse, meaning that given two different portfolios of with the same expected return, the portfolio with less risk will be chosen. Investors are assumed to only take higher risks if it pays off with a higher expected return. First, an ordered vector of individual asset expected returns1. is constructed. A covariance matrix2 comparing all assets is then constructed which is equal to the variance matrix for the portfolio. This is important because its non-diagonal entries represent the correlations between each asset and the diagonal entries represent the variance of each asset. The correlations are used to minimize the idiosyncratic risk of the portfolio by minimizing the overall correlation between stocks used and thus minimizing the portfolio variance. Unfortunately, we are not able to get rid of all the portfolio risk. The idiosyncratic risk is lowered by portfolio diversification. Even when all non-systematic risk is diversified away the systematic remains. The efficient frontier of portfolios for a set of risky assets is the portfolios that contain combinations of these assets with the best possible expected return for each given level of risk. Markowitz’s method weights the assets so it is the efficient portfolio for the given level of risk or target return. The portfolio with the greatest risk-return trade of on the efficient frontier is called the tangency portfolio3.. The Black-Litterman Model 8 The capital asset pricing model4. (CAPM) is a model used to determine the theoretically appropriate required rate of return on an asset. It only considers the systematic risk of an asset because it assumes the asset is being added to a portfolio with its idiosyncratic risk diversified away. The linear models inputs are the assets sensitivity to non-systematic risk, or beta, and the expected return of the market and the risk free rate. The CAPM assumes that the sensitivity to systematic risk with respect to the market determines the required return of on the asset. Portfolio Performance and Risk Measures The three performance measures that I used in analyzing the portfolios was the Sharpe ratio, the Modigliani- Modigliani measure (M Squared) and Jensen’s alpha. The Sharpe ratio5. is a performance measure that takes the return on an investment and then adjusts it for its underlying risk. It allows for the ranking of portfolios that take different levels of risk. For instance, one portfolio might have a high return might have a lower Sharpe ratio than a portfolio that gives medium returns but takes on a significantly lower amount of risk. The second measure is the M Squared measure6.. It is the Sharp ratio adjusted into units of percent return compared to a benchmark. This gives a significant advantage over the traditional Sharpe ratio which is unitless and abstract. The last measure of portfolio performance is Jensen’s alpha7.. Alpha represents the abnormal returns of an asset or a group of assets over the expected returns. The expected returns for an asset or portfolio are usually calculated using the CAPM. The three risk metrics that I used to measure the different underlying risks of the tested portfolios are the portfolio beta, volatility, and the value at risk (VaR.) The portfolio beta8. is the measure of a its exposure to systematic risk. As mentioned before, systematic risk is the risk arising from general exposure to the stock market and it cannot be diversified away. The beta measure is calculated using a set of benchmark returns representing the market portfolio and compares them The Black-Litterman Model 9 to the returns of an asset. A beta greater than zero but less than one indicates an asset that trends with the market with smaller movements. A beta of one indicates an asset trends with the market with the same amount of movement. A beta greater than one indicates an asset trends with the market, but with larger movement. A portfolio beta is calculated using a weighted average of the asset betas. The volatility9. of an asset is a measure of the variation or standard deviation in its price over a period of time. In financial theory, it is the most quantifiable measure of an asset or a group of assets risk. A portfolios VaR is the risk of loss on a specific portfolio of assets. If a stock has a one-week 10% VaR of $1 thousand then there is a ten percent chance that the portfolio will fall in value by more than $1 thousand in a week’s period. VaR can be calculated using a set of historical returns based off the period length that is in order. Then the lowest percent of the histogram equal to the percent VaR is market and the closest return is multiplied by the portfolio to get the historical VaR. Explanation of Black-Litterman Two of the most significant contributions of the Black-Litterman model to portfolio optimization are its intuitive prior distribution17. and its method for specify investor’s views on returns represented as a conditional distribution16.. The model seeks to improve on the unintuitive and input-sensitive nature of the mean variance optimization model. The Black-Litterman model begins by solving for the prior distribution of return by using weights based on market capitalization. This gives a neutral and effective platform for expressing our views. The implied risk aversion coefficient10. is solved by dividing the expected Sharpe Ratio of the market capitalization portfolio by the variance of the market capitalization portfolio. The covariance matrix is solved is found using the same method used by mean- The Black-Litterman Model 10 variance optimization. Reverse optimization is used to solve for the Implied Equilibrium Return Vector11. which is the estimate for the unknown mean of the expected returns. Next, we solve for the conditional distribution that will store relative and absolute views on assets. When defining views in the Black-Litterman model K represents the number of views and N the number of assets. K can be less than or equal to the number of assets N. Views are expressed in the P12. matrix by rows that assign numbers corresponding assets that are represented by columns. Asset will correspond to the number column that is the same as its order in the rest of the model inputs. The Q matrix then corresponds to the expected returns that correspond to each view. Views can be relative in which case the sum of the row will be zero, or absolute where it will be represented by a one in a single column. The Omega matrix corresponds to the covariance of the views or the relative confidence associated with the view. The most intuitive way to calculate the elements of Omega13.15. is by specifying a confidence14. associated with the view and solving backwards using Idzorek’s extension. The extension uses the Alternative Reference Model which drops and allows us to drop the factor Tau. The prior and conditional distributions are then combined to eventually solve for the final portfolio weights using mean-variance optimization and Bayesian Probability18.. First, the posterior estimate distribution of the expected returns is solved for using Bayes Theorem19.. A posterior distribution is a probability distribution of an unknown quantity that is treated as a random variable and is conditional on prior or experimental data. The posterior probability is the probability or the parameter given the evidence while the likelihood function in contrast is the probability of the evidence give the parameter. The mean return20. and variance21. of the posterior distribution are solved for. The posterior covariance23. of returns is solved for by adding the variance of the estimate about the mean to the variance of the posterior distribution. The Black-Litterman Model 11 The final weights24. can then be solved using the posterior estimates for the mean and variance of the returns. Experiment Setup Details In order to test the Black-Litterman model I used historical data of large companies from the S&P 500 stock index. The S&P 500 is one of the best representations of the status of the United States equities market. This is because it consists of equity for large publically traded companies sold on the New York Stock Exchange or the NASDAQ weighted based on market capitalization. For each portfolio I constructed I used twenty different stocks from different sectors of the economy. I used equity because it is the best representation of a risky asset. Twenty large stocks were used because I wanted to diversify much of the idiosyncratic risk out of the portfolio but I also wanted to minimize the number of expected returns I would have to predict. Ideally, I would have include fifty stocks to minimize the idiosyncratic risk. Three portfolios were considered. Each portfolio will consist of the same sets of stocks but different weights. The first portfolio was weighted using the period’s initial market caps. This is a decent baseline because it behaves much like the S&P 500. The biggest differences are its asset count and the lack of free-floating weights. This unfortunately could not be dealt with and so must be taken into consideration when used as a benchmark. The second portfolio used has weights based on traditional mean-variance optimizations. This portfolio’s weights were not readjusted during the test period. The input expected asset returns will be predicted based on financial return data from the previous years. The last portfolio had weights based on the BlackLitterman model. The inputs to this model came from my opinions on some stocks for the period and historical data prior to the test period. The Black-Litterman Model 12 Test periods were three years in length. This is enough to see results in the true performance of the portfolios. This was be done fifteen times for each portfolio in two rounds. The first round consisted of a blind study of ten different combinations for stock sets during the early eighties. I expect that the three portfolios will perform very similarly as I don’t think I will be able to correctly and consistently speculate the performance of the individual assets. The second round consisted of the same study but knowing the outcome of the stocks of the S&P during the period. I expect that because I know the outcome of the individual assets the expected returns of the assets will be much easier to obtain and thus the Black-Litterman model portfolio model will perform the best followed by the mean-variance portfolio and then the market capitalization weighed portfolio. The data used for the prediction period will be from three years prior to the investment period for all inputs except for the individual stock beta and volatility values. Those values will be calculated using five years prior. Results For the most part, the results turned out as expected. For the first round, the Sharpe ratios for the optimization methods hovered slightly higher than the market capitalized portfolio sharp of .58. The beta for the market capitalization portfolio was around 1.2, the beta for the mean-variance optimization portfolio was around 1.4 and the beta for the Black-Litterman method was around .9. They have volatilities and VaRs that ranked in the same order. The VaR and volatility for the Markowitz method were substantially higher than the others. For the second round, the Sharpe ratios for the Black-Litterman was around 1.13 and the Markowitz and market portfolios were close to or the same as in the first round. The returns of each were different but the betas of each were also very different. The beta for the market capitalization portfolio was around 1.2, the beta for the mean-variance optimization portfolio was around .86 and the beta for the Black- The Black-Litterman Model 13 Litterman method was around 2.46. They have volatilities and VaRs that ranked in the same order. The VaR and volatility for the Markowitz method and Black-Litterman Model were substantially higher than the others. Discussion The results of the experiment shed light on the quality of the Black-Litterman model in comparison with the original mean-variance optimization model. I tested the Black-Litterman model to see if I could identify it as a relative success in the field of portfolio optimization. The biggest advantage I could see from using the Black-Litterman model was having the ability to adjust expected returns from a base line and weighting them based on confidence. This is what I would be focusing on when testing. During the analysis, I did not thoroughly look into the alphas and M Squared measures of performance even though I included them. In comparing portfolios together, the alpha is difficult to interpret and the M Squared measure displays the same information as the Sharpe ratio. The most important evaluation of the relative success of a portfolio is the Sharpe measure. In the blind round, I was only able to look at financial information for the portfolio companies before the start of the testing period. Although, because I was testing historical period, the blindness of the experiment was not perfect. That being said, I tried not to incorporate any obvious outcome views into my expected return predictions. The results of this experiment were performances slightly higher for optimized portfolios than I previously expected. This may have resulted from including knowledge of the economy in general during the period in question. It was difficult to not include this information because of some knowledge of previous market performance. The risk measures for the mean-variance portfolio turned out to all be high which The Black-Litterman Model 14 may stem from the difficulty in expressing weights and there are indications of high amounts of idiosyncratic risk taken when comparing the size of the value at risk and the beta. The inputs to the Black-Litterman model were all conservative this round which is reflected in the lower-thanmarket risk measures. In the un-blind round, I was able to look at the financial performance for the portfolio companies during the period in question. That being said, I restricted myself to only simple and short estimation calculations to save time. The results of this experiment were similar to the first round with the exception of the risk metrics of the mean-optimized portfolio and the higher performance of the Black-Litterman model. The market capitalization portfolio remained constant as it should. The mean-variance model turned out to have a slightly lower Sharpe and beta but a higher volatility and value at risk. This may have been a result of my inability to successfully identify proper expected returns for all twenty assets in the portfolio. The performance of the Black-Litterman model was greater in the second round. This could be due to me using expected returns for stocks that I was sure of. The risk measures for the BlackLitterman model were also substantially higher than in the first round. This would most likely be explained by the overweighting of individual stocks and the portfolio in general. This is due to specifying much higher confidences. Conclusions The experiments performed, both blind and un-blind, were revealing to the relative performance of the Black-Litterman model. It seems to be the superior model to the mean-variance optimization model in many ways, it is still difficult to use and only produces results if you can predict some expected returns. The lack of complete documentation of the original model when it was announced resulted in a multitude of confusing and sometimes incorrect versions of the The Black-Litterman Model 15 model presented in literature. There are also many different correct variations of the model that improve upon it. It is difficult to tell the difference between the two which poses a potential problem. Although all of my model is correct, some of the chosen methods seem to have been substantially less superior to others later found in literature. I am specifically referring to specifying the correlation matrix of the investor’s views. I used Idzorek’s method from supplying confidences which was arbitrary and difficult to use. It would have been wiser for me to use a different method such as a proportion to the variance of the prior distribution or the method for supplying specific confidence intervals. This would have resulted in more reasonable weights for views that I expected a high confidence in. Even with these added weights, the Black-Litterman model performed significantly better in the second round showing that my estimated views helped with the overall performance. The Black-Litterman model is most useful to an investor that is able to optimize the variations of the model to his advantage, understands its complexities, and is able to successfully predict the expected return for a small number of assets. The Black-Litterman Model 16 References [1] R. C. Merton, “An Intertemporal Capital Asset Pricing Model,” Econometrica, vol. 41, no. 5, pp. 867–887, Sep. 1973. [2] F. Black and R. Litterman, “Global Portfolio Optimization,” Financial Analysts Journal, vol. 48, no. 5, pp. 28–43, Sep. 1992. [3] W. F. Sharpe, “Mutual Fund Performance,” The Journal of Business, vol. 39, no. 1, pp. 119–138, Jan. 1966. [4] H. Markowitz, “Portfolio Selection*,” The Journal of Finance, vol. 7, no. 1, pp. 77–91, Mar. 1952. [5] A. J. McNeil, R. Frey, and P. Embrechts, Quantitative Risk Management: Concepts, Techniques, and Tools: Concepts, Techniques, and Tools. Princeton University Press, 2010. [6] C. F. A. Walters, “The Black-Litterman Model in Detail,” Social Science Research Network, Rochester, NY, SSRN Scholarly Paper ID 1314585, Jun. 2014. [7] C. Mankert, “The Black-Litterman Model : mathematical and behavioral finance approaches towards its use in practice,” 2006. [8] C. Mankert, “The Black-Litterman Model : mathematical and behavioral finance approaches towards its use in practice,” 2006. [9] M. C. Jensen, F. Black, and M. S. Scholes, “The Capital Asset Pricing Model: Some Empirical Tests,” Social Science Research Network, Rochester, NY, SSRN Scholarly Paper ID 908569, Jun. 2006. [10] J. T. Chong, Y. Jin, and G. M. Phillips, “The Entrepreneur’s Cost of Capital: Incorporating Downside Risk,” Business Valuation Review, vol. 33, no. 3, pp. 81–91, Sep. 2014. [11] C. F. A. Walters, “The Factor Tau in the Black-Litterman Model,” Social Science Research Network, Rochester, NY, SSRN Scholarly Paper ID 1701467, Oct. 2013. [12] M. C. Jensen, “The Performance of Mutual Funds in the Period 1945-1964,” Social Science Research Network, Rochester, NY, SSRN Scholarly Paper ID 244153, May 1967. [13] P. Jorion, Value at Risk: The New Benchmark for Managing Financial Risk, 3rd Edition, 3rd edition. New York: McGraw-Hill, 2006. The Black-Litterman Model Appendix A: Equations References to equations in the main portion of the paper will be marked with a superscript corresponding ordering of equations below. Markowitz and CAPM 1. 2. 3. 4. Portfolio Performance and Risk Metrics 5. 6. 7. 8. 9. Black-Litterman Model 10. 17 The Black-Litterman Model 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 18 The Black-Litterman Model 22. 23. 24. 19 The Black-Litterman Model Appendix B: Portfolio Results Blind Test Results Un-Blind Test Results 20 The Black-Litterman Model 21 Appendix C: MATLAB Code Functions for the Creation and Analysis of Portfolios function [portfolio] = AddStocks(portfolio, stocks) %Adds a list of stocks to input portfolio cell array. Socks are set up %as structures and asigned ticker symbols based on the input cell array of %stock tickers [n, m] = size(stocks); if n == 1 n = m; end if ~(iscellstr(stocks)) error('Error: stocks attempting to be added are not in cell array or string') end for i = 2:(n+1) portfolio{i} = struct('Weights',0,'Ticker',stocks{(i-1)}, 'MarketCapital',0,'Historical_Prices',[], 'Historical_Returns',[],'Volume',0,'Value',0, 'First_HDate','','Last_HDate','','Beta',0,'Volatility',0); end end function [ portfolio, pmeasures ] = CreatePortfolio() %Function creates a cell array of structures called the portfolio and adds %the S&P 500 index fund in the form of a structure to the first positions %in the portfolio. The index is only used as a benchmark for the rest of %the stocks in the portfolio. The a structure of portfolio measures is also %created to store relevant portfolio data. if (nargin == 0) pmeasures = struct('StartingValue',0,'PWeights',[],'Historical_Value',[],'Returns',[], 'AverageReturns',0,'STDReturns',0,'RiskFree',0,'Beta',0,'Volatility', 0,'Sharpe',0,'Alpha',0,'MSquared',0,'hVaR',[],'hVaRD',0,'TotalValue',0); portfolio = cell(1,1); portfolio{1} = struct('Weights',0,'Ticker','^GSPC','MarketCapital',0, 'Historical_Prices',[], 'Historical_Returns',[],'Volume',0,'Value',0, 'First_HDate','','Last_HDate','','Beta',0,'Volatility',0); else error('Error 1: Wrong Amount Of Inputs') end end function [pmeasures] = H_Var( pmeasures, percentage) % Calculates the historical Value at Risk for a portfolio given a certain % input VaR percentage. It puts the portfolio returns in numerical order The Black-Litterman Model % and then multiplies the starting value of the portfolio by the return % that corresponds to the entry closest to the VaR percentage on the tail % of the histogram of returns. This represents the lowest value that % should be lost 1-VaR% of the time for the return period. [n m] = size(pmeasures.Returns); returnsinorder = sort(pmeasures.Returns); VaR = []; x = floor(n*percentage); for i = 1:x VaR(i) = returnsinorder(i); end pmeasures.hVaRD = VaR(x)*pmeasures.StartingValue; pmeasures.hVaR = VaR; end function [pmeasures] = MSquared(portfolio,pmeasures) %M Squared measure calculated period = pmeasures.Period; if period == 'm' mult = sqrt(12); elseif period == 'w' mult = sqrt(52); elseif period == 'd' mult = sqrt(252); end sharpe = pmeasures.Sharpe; rf = pmeasures.RiskFree; market = (portfolio{1}.Historical_Returns - rf); stdmarket = std(market); msquared = mult*(sharpe*stdmarket + rf); pmeasures.MSquared = msquared; end function [pmeasures] = PortfolioAlpha(portfolio, pmeasures) %Jensen's alpha is output. period = pmeasures.Period; if period == 'm' mult = sqrt(12); elseif period == 'w' mult = sqrt(52); elseif period == 'd' mult = sqrt(252); end market = mean(portfolio{1}.Historical_Returns); 22 The Black-Litterman Model pmeasures.Alpha = ... mult*(pmeasures.AverageReturns - ((pmeasures.Beta)*( market - pmeasures.RiskFree))); 23 ... end function [pmeasures] = PortfolioBeta( portfolio, pmeasures ) %Portfolio Beta is calculated using a weighted average of the portfolio %weights and individual sset betas. [n, m] = size(portfolio); if n == 1 n = m; end weights = pmeasures.PWeights; [z, w] = size(weights); if z < w weights = transpose(weights); end beta = 0; for i = 2:n beta = beta + ((weights(i-1))*(portfolio{i}.Beta)); end pmeasures.Beta = beta; end function [pmeasures] = PortfolioReturns(portfolio, pmeasures) %takes an weighted average of individual asset returns and outputs %portfolio returns. Also calculates the excess returns and average of the %excess returns using a set risk free rate. rf = pmeasures.RiskFree; [n, m] = size(portfolio); if n == 1 n = m; end [x, y] = size(portfolio{1}.Historical_Returns); if x == 1 x = y; end returns = zeros(x,1); The Black-Litterman Model weights = pmeasures.PWeights; [z, w] = size(weights); if z < w weights = transpose(weights); end for i = 2:n returns = returns + (weights(i-1)*portfolio{i}.Historical_Returns); end pmeasures.Returns = returns; exreturns = returns - rf; pmeasures.AverageReturns = mean(exreturns); pmeasures.STDReturns = std(exreturns); end function [pmeasures] = PortfolioSharpe(pmeasures) %Outputs portfolio Sharpe period = pmeasures.Period; if period == 'm' mult = sqrt(12); elseif period == 'w' mult = sqrt(52); elseif period == 'd' mult = sqrt(252); end pmeasures.Sharpe = (mult*(pmeasures.AverageReturns))/pmeasures.STDReturns; end function [portfolio, pmeasures] = PortfolioValue(portfolio,pmeasures) %Portfolio value is calulated by multiplying the individual asset prices %the initial volume. [n, m] = size(portfolio); value = 0; if n == 1 n = m; end for i = 2:n price = portfolio{i}.Historical_Prices; volume = portfolio{i}.Volume; portfolio{i}.Value = price*volume; value = value + (price*volume); end pmeasures.Historical_Value = value; end 24 The Black-Litterman Model function [pmeasures] = PortfolioVolatility(portfolio,pmeasures) %Weighted average of asset volatilties. [n, m] = size(portfolio); if n == 1 n = m; end weights = pmeasures.PWeights; [z, w] = size(weights); if z < w weights = transpose(weights); end volatility = 0; for i = 2:n volatility = volatility + (weights(i-1)*portfolio{i}.Volatility); end pmeasures.Volatility = volatility; end function [ pmeasures ] = SetRiskFree( pmeasures,rf,period ) %Sets the risk free rate and the period length. pmeasures.Period = period; pmeasures.RiskFree = rf; end function [ pmeasures ] = SetStartingValue(pmeasures,value) %Sets the staring value of the portfolio pmeasures.StartingValue = value; end function [portfolio] = UpdateBeta(portfolio) %Updates the beta for each indiviual asset in a portfolio for a time %horizon [n, m] = size(portfolio); if n == 1 n = m; end SandPreturns = portfolio{1}.Historical_Returns; 25 The Black-Litterman Model for i = 1:n returns = portfolio{i}.Historical_Returns; %check if cov is right later covar = cov(SandPreturns,returns,0); portfolio{i}.Beta = (covar(1,2)/var(SandPreturns)); end end function [portfolio, pmeasures] = UpdateHorizon(c,portfolio,pmeasures, firstdate, lastdate, period) %Updates the time horizon, and retreives prices for individual assets. %These historical values are used to to calulate volumes and market caps. %Calculates the total value of the portfolio using the market caps. [n, m] = size(portfolio); if n == 1 n = m; end for i = 1:n portfolio{i}.First_HDate = firstdate; portfolio{i}.Last_HDate = lastdate; ticker = portfolio{i}.Ticker; prices = flipud(fetch(c,ticker,'Adj Close',firstdate,lastdate,period)); portfolio{i}.Historical_Prices = prices(:,2); if ~(i == 1) volume = fetch(c,ticker,'Volume',firstdate); portfolio{i}.MarketCapital = volume(2)*prices(1,2); end end tvalue = 0; for i = 2:n tvalue = tvalue + portfolio{i}.MarketCapital; end pmeasures.TotalValue = tvalue; end function [portfolio] = UpdateReturns(portfolio) %Updates the historical returns of individual assets. [n, m] = size(portfolio); if n == 1 n = m; end z = portfolio{1}.Historical_Prices; 26 The Black-Litterman Model [x, y] = size(z); if x == 1 x = y; end for i = 1:n prices = portfolio{i}.Historical_Prices; for j = 1:(x-1) returns(j,1) = (prices(j+1)-prices(j))/prices(j); end portfolio{i}.Historical_Returns = returns; end end function [portfolio] = UpdateVolatility(portfolio, period) %Calculates the volatility of individual assets of a portfolio. [n, m] = size(portfolio); if n == 1 n = m; end if period == 'w' %check annualized number annualizer = sqrt(52); elseif period == 'd' annualizer = sqrt(252); else error('period is neither weekly or daily or is in improper format') end for i = 1:n returns = portfolio{i}.Historical_Returns; portfolio{i}.Volatility = std(returns)*annualizer; end end function [portfolio] = UpdateVolume(portfolio,pmeasures) %Updates the volume of individual assets in the portfoli using the starting %value weighted and and historical prices [n, m] = size(portfolio); if n == 1 n = m; end 27 The Black-Litterman Model tvalue = pmeasures.StartingValue; for i = 2:n weight = portfolio{i}.Weights; value = tvalue*weight; price = portfolio{i}.Historical_Prices(1); portfolio{i}.Volume = value/price; end end function [portfolio,pmeasures] = UpdateWeights(portfolio,pmeasures) %Updates portfolio weights using stock market capitalization [n, m] = size(portfolio); if n == 1 n = m; end value = pmeasures.TotalValue; for i = 2:n stockvalue = portfolio{i}.MarketCapital; portfolio{i}.Weights = (stockvalue/value); pmeasures.PWeights(i-1) = (stockvalue/value); end end Functions for Optimizing Portfolio function [pmeasures] = Markowitz( portfolio, pmeasures,mean) %Calculates weights using the mean-variance optimization method. [n, m] = size(portfolio); if n == 1 n = m; end covariance = []; s = []; rf = pmeasures.RiskFree; for i = 2:n covariance = ... [covariance portfolio{i}.Historical_Returns]; s = [s 1]; end sigma = cov(covariance); invsigma = inv(sigma); expected = (mean-rf); 28 The Black-Litterman Model num = invsigma*expected; den = s*num; t = num/den; pmeasures.PWeights = t; for i = 2:n portfolio{i}.Weights = t(i-1); end end function [views] = MakeViews(P,Q,Confidence) %Adding views for Black-Litterman model to a structure. [n, m] = size(P); if n > m P = transpose(P); end [x, y] = size(Q); if x < y Q = transpose(Q); end views = struct('P',P,'Q',Q,'Confidence',Confidence); end function [pmeasures] = BlackLitterman(portfolio,pmeasures,views) %Calclates portfolio weights using the Black-Litterman model. covariance = []; [n, m] = size(portfolio); if n == 1 n = m; end sharpe = .5; P = views.P; Q = views.Q; Confidence = views.Confidence; rf = pmeasures.RiskFree; weights_mc = transpose(pmeasures.PWeights); for i = 2:n covariance = [covariance (portfolio{i}.Historical_Returns-rf)]; end 29 The Black-Litterman Model 30 Sigma = cov(covariance); std_m = sqrt(transpose(weights_mc)*Sigma*weights_mc); delta = (sharpe)/std_m; alpha = (1-Confidence)./Confidence; Omega = diag(alpha*P*Sigma*transpose(P)); Pie = delta*Sigma*weights_mc; Postest = Pie + Sigma*transpose(P)*inv(( ... P*Sigma*transpose(P)) + Omega)*(Q-P*Pie); M = Sigma + Sigma*transpose(P)*inv(( ... P*Sigma*transpose(P)) + Omega)*(P*Sigma); Sigmap = Sigma+M; weights = transpose(Postest)*inv(delta*Sigmap); pmeasures.PWeights = weights; for i = 2:n portfolio{i}.Weights = weights(i-1); end end Example Portfolio Creation Script %script runs 3 portfolio models all with the same starting value and set of %stocks. This example script was not used in the testing. c = yahoo; Stocks = {'T','BA','C','COKE', 'GE','XOM','JPM','PFE', 'PG','HPQ','CAT','INTC', 'MCD','AA','DIS','MSFT', 'MMM','HON','DD','PEP'}; %[AT&T, Boeing, Citi, Coke, GE, Exxon, JPMorgan, Pfitzer %P&G, HP, Caterpillar, Intel, McDonalds, Alcoa, WaltDisney %Microsoft, 3m, Honeywell, duPont,] P = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Q = [.3 .07 .2 .09 .2]; 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0]; The Black-Litterman Model Confidence = [.10 .2 .3 .09 .09]; mean = [.07;.12;.06; .08; .08;.09;.09;.06; .10;.14;.10;.13; .02;.07;.01;.16; .03;.06;.06;.07;]; views = MakeViews(P,Q,Confidence); [market, marketMeasures] = CreatePortfolio(); [markowitz, markowitzMeasures] = CreatePortfolio(); [blacklitterman, blacklittermanMeasures] = CreatePortfolio(); Bstart = '01/03/2000'; Bend = '01/03/2004'; pstart = '01/03/2005'; pend = '01/03/2008'; market = AddStocks(market, Stocks); markowitz = AddStocks(markowitz, Stocks); blacklitterman = AddStocks(blacklitterman, Stocks); marketMeasures = SetRiskFree(marketMeasures,0.0005,'w'); markowitzMeasures = SetRiskFree(markowitzMeasures,0.0005,'w'); blacklittermanMeasures = SetRiskFree(blacklittermanMeasures,0.0005,'w'); marketMeasures = SetStartingValue(marketMeasures,10000); markowitzMeasures = SetStartingValue(markowitzMeasures,10000); blacklittermanMeasures = SetStartingValue(blacklittermanMeasures,10000); [market, marketMeasures] = UpdateHorizon(c,market,marketMeasures,Bstart,Bend,'w'); [markowitz, markowitzMeasures] = UpdateHorizon(c,markowitz,markowitzMeasures,Bstart,Bend,'w'); [blacklitterman, blacklittermanMeasures] = UpdateHorizon(c,blacklitterman,blacklittermanMeasures,Bstart,Bend,'w'); market = UpdateReturns(market); markowitz = UpdateReturns(markowitz); blacklitterman = UpdateReturns(blacklitterman); market = UpdateBeta(market); markowitz = UpdateBeta(markowitz); blacklitterman = UpdateBeta(blacklitterman); market = UpdateVolatility(market,'w'); markowitz = UpdateVolatility(markowitz,'w'); blacklitterman = UpdateVolatility(blacklitterman,'w'); [market, marketMeasures] = UpdateWeights(market,marketMeasures); [markowitz, markowitzMeasures] = UpdateWeights(markowitz,markowitzMeasures); 31 The Black-Litterman Model 32 [blacklitterman, blacklittermanMeasures] = UpdateWeights(blacklitterman,blacklittermanMeasures); markowitzMeasures = Markowitz(markowitz,markowitzMeasures,mean); blacklittermanMeasures = BlackLitterman(blacklitterman,blacklittermanMeasures,views); [market, marketMeasures] = UpdateHorizon(c,market,marketMeasures,pstart,pend,'w'); [markowitz, markowitzMeasures] = UpdateHorizon(c,markowitz,markowitzMeasures,pstart,pend,'w'); [blacklitterman, blacklittermanMeasures] = UpdateHorizon(c,blacklitterman,blacklittermanMeasures,pstart,pend,'w'); market = UpdateReturns(market); markowitz = UpdateReturns(markowitz); blacklitterman = UpdateReturns(blacklitterman); market = UpdateVolume(market,marketMeasures); markowitz = UpdateVolume(markowitz,markowitzMeasures); blacklitterman = UpdateVolume(blacklitterman,blacklittermanMeasures); [market, marketMeasures] = PortfolioValue(market,marketMeasures); [markowitz, markowitzMeasures] = PortfolioValue(markowitz,markowitzMeasures); [blacklitterman, blacklittermanMeasures] = PortfolioValue(blacklitterman,blacklittermanMeasures); marketMeasures = PortfolioBeta(market,marketMeasures); markowitzMeasures = PortfolioBeta(markowitz,markowitzMeasures); blacklittermanMeasures = PortfolioBeta(blacklitterman,blacklittermanMeasures); marketMeasures = PortfolioVolatility(market, marketMeasures); markowitzMeasures = PortfolioVolatility(markowitz,markowitzMeasures); blacklittermanMeasures = PortfolioVolatility(blacklitterman,blacklittermanMeasures); marketMeasures = PortfolioReturns(market,marketMeasures); markowitzMeasures = PortfolioReturns(markowitz,markowitzMeasures); blacklittermanMeasures = PortfolioReturns(blacklitterman,blacklittermanMeasures); marketMeasures = PortfolioSharpe(marketMeasures); markowitzMeasures = PortfolioSharpe(markowitzMeasures); blacklittermanMeasures = PortfolioSharpe(blacklittermanMeasures); marketMeasures = PortfolioAlpha(market,marketMeasures); markowitzMeasures = PortfolioAlpha(markowitz,markowitzMeasures); blacklittermanMeasures = PortfolioAlpha(blacklitterman,blacklittermanMeasures); marketMeasures = MSquared(market,marketMeasures); markowitzMeasures = MSquared(markowitz,markowitzMeasures); blacklittermanMeasures = MSquared(blacklitterman,blacklittermanMeasures); The Black-Litterman Model marketMeasures = H_Var(marketMeasures,.05); markowitzMeasures = H_Var(markowitzMeasures,.05); blacklittermanMeasures = H_Var(blacklittermanMeasures,.05); 33