Workshop 1, Investment Funds

Author

Alberto Dorantes, Ph.D.

Published

April 8, 2024

Abstract
In this workshop we review the foundations of portfolio theory and the single index (factor) model.

1 General directions for this Workshop

Using an RNotebook in Google Colab you have to:

  • Replicate all the R Code along with its output.

  • You have to do whatever is asked in the workshop. It can be: a) Responses to specific questions and/or do an exercise/challenge.

Any QUESTION or any INTERPRETATION you need to do will be written in CAPITAL LETTERS. For ANY QUESTION or INTERPRETATION, you have to RESPOND IN CAPITAL LETTERS right after the question.

  • It is STRONGLY RECOMMENDED that you write your OWN NOTES as if this were your personal notebook. Your own workshop/notebook will be very helpful for your further study.

You have to submit ONLY the link of your Google Colab. You must share your notebook with the Tec de Monterrey community.

2 Portfolio Theory - Review

2.1 What is a Portfolio

A portfolio is a set of 2 or more financial assets. A financial asset can of any type such as stock, bond, risk-free instrument, derivative, commodity. The portfolio owner needs to decide how much money allocate to each individual asset. The main advantage of financial portfolios is the possibility to diversify non-systematic (idiosyncratic) risk, while maintaining an expected rate of return.

In this section we review practical easy examples of 2-asset and 3-asset portfolios with the purpose to review portfolio theory and portfolio optimization.

It is recommended that you review the lecture notes posted in the course site where portfolio theory, matrix algebra, and portfolio optimization are explain in more detail.

The main contribution of portfolio theory to Finance is the method to estimate the expected risk and return of a portfolio. Before we review this method, we review how to estimate the expected return and risk of an asset.

Let’s start with an example of a 2-asset portfolio. Imagine we want to invest in a portfolio with the following composition:

WalMart: 70%

Tesla: 30%

We start reviewing the expected return of each asset:

2.2 Estimation of expected return of an asset

The most simple way to estimate expected return of an asset is by the geometric mean of historical returns. Other sophisticated methods to estimate expected stock return are the single-index model, the CAPM regression model, ARIMA models.

The geometric mean of historical returns is the period return needed so that holding an investment over several compounding periods, we get a final a final holding return of the stock.

The mathematical formula of geometric mean return is:

GeomMean(R)=\sqrt[N]{(1+R_{1})(1+R_{2})...(1+R_{N})}-1

Where R_t is the historical return for period t. In this formula we have N historical periods (can be months)

Another easier way to calculate geometric mean of returns is to calculate the arithmetic mean of continuously compounded returns, and then convert the result to simple return by applying the exponential function:

GeomMean(R)=e^{\bar{r}}-1

Where \bar{r} is the arithmetic mean of historical returns:

\bar{r}=\frac{r_{1}+r_{2}+...+r_{N}}{N}

Remember that continuously compounded return can be calculated from prices as follows:

r_t=log(price_t)-log(price_{t-1})

The the return of a stock today is the difference between the natural logarithm of the current price minus the natural logarithm of the price of the previous period.

Let’s practice with real data of our 2 assets. Calculate the expected monthly return of WalMart and Tesla using the same historical data from 2019 to date.

We get historical prices from Yahoo:

library(quantmod)
tickers = c("WMT","TSLA")
getSymbols(Symbols = tickers, periodicity="monthly",from="2019-01-01", to="2024-03-31")
[1] "WMT"  "TSLA"

We got 2 time-series monthly data for each stock. We merge both into 1 dataset and get only the adjusted price:

prices = merge(WMT, TSLA)
# We have several columns such as open, close, high, low, adjusted prices.
# Now we extract only the adjusted prices of both stocks:
prices = Ad(prices)
# We rename the columns with the tickers:
names(prices) = tickers

We calculate the continuously compounded returns of each stock (also called log returns):

r = diff(log(prices))
# The first month will have NA values, so we can drop this row:
r = na.omit(r)

Now we get the expected return for each stock as the geometric mean of their historical returns:

WMT_ccmean_returns = mean(r$WMT)
TSLA_ccmean_returns = mean(r$TSLA)

# Another faster way to calculate both mean returns is:
ccmean_returns  = colMeans(r)

colMeans calculate the arithmetic mean of 1 or more columns of a dataset.

Once we have the arithmetic mean cc returns, we apply the exponential function to get the geometric historical return:

WMT_geomreturns = exp(WMT_ccmean_returns) - 1 
TSLA_geomreturns = exp(TSLA_ccmean_returns) - 1
# A faster way to calculate both is: 
ER = exp(ccmean_returns) - 1
ER
       WMT       TSLA 
0.01162069 0.03529283 

We see that Tesla has offered an average of 3.5292828% monthly returns since 2019 to date. While WalMart has offered an average of 1.1620687% monthly returns since 2019 to date.

With this geometric average return we can estimate the holding return over the whole period as follows:

months = nrow(prices) - 1
HPR_WMT = (1 + WMT_geomreturns)^months - 1 
# The holding-period return of WalMart is:
HPR_WMT
[1] 1.046904
HPR_TSLA = (1 + TSLA_geomreturns)^months - 1
# The holding-period return of Tesla is:
HPR_TSLA
[1] 7.588528

We can test whether the stock price of each stock grows at the geometric monthly return over the whole period:

# I get the initial stock price for Walmart:
WMT_initial_price = as.numeric(first(prices$WMT))
# I calculate the final price as the future value of the investment at the holding period return: 
WMT_final_price = WMT_initial_price * ( 1 + HPR_WMT)
WMT_final_price
[1] 59.96577
last(prices$WMT)
                WMT
2024-03-01 59.96577
TSLA_initial_price = as.numeric(first(prices$TSLA))

# I calculate the final price as the future value of the investment at the holding period return: 
TSLA_final_price = TSLA_initial_price * ( 1 + HPR_TSLA)
TSLA_final_price
[1] 175.79
last(prices$TSLA)
             TSLA
2024-03-01 175.79

The last historical price is equal to the calculated price when invested to the holding-period return at the geometric average return.

2.3 Estimation of expected risk of an asset

A simple way to calculate the expected risk of an asset is through the standard deviation of historical returns.

Remember that the variance is the square of the standard deviation. Then, we start calculating the variance of historical returns.

2.3.1 Variance

Variance of any variable is the arithmetic mean of squared deviations. A squared deviation is the value resulting from subtracting the value of the variable minus its mean, and the square the value.

Why we square the deviations? This is a trick to convert the negative deviations into positive so that we can measure how much each value of the variable moves or deviates from its mean.

The mean of returns is estimated as:

\bar{r} =\frac{r_{1}+r_{2}+...+r_{N}}{N}

The variance is estimated as:

VAR(r)=\frac{(r_{1}-\bar{r})^{2}+(r_{2}-\bar{r})^{2}+...+(r_{N}-\bar{r})^{2}}{N}

Variance is a measure of dispersion. The higher the variance, the more dispersed the values are from its mean. It is hard to interpret the magnitude of variance. That is the reason why we need to calculate standard deviation, which is basically the squared root of the variance.

2.3.2 Standard deviation - volatility

Standard deviation of a variable is the squared root of the variance of the variable:

SD(r)=\sqrt{VAR(r)} Then, the standard deviation of returns can be interpreted as a standardized average distance from each value of the variable from its mean.

The standard deviation of returns is called volatility. Then, volatility of returns tells us an idea of how much on average (above or below) the period returns move from its historical mean.

We can calculate volatility of a single stock, or volatility of a portfolio composed of 2 or more stocks.

Let’s calculate the volatility (expected risk) of WalMart and Tesla:

We calculate the variance of each return series:

var_WMT = var(r$WMT)
var_TSLA = var(r$TSLA)

# A faster way to calculate both is calculating the variance-covarianc matrix:
cov = var(r)
cov
             WMT        TSLA
WMT  0.002634706 0.002630989
TSLA 0.002630989 0.041145543

We can calculate the standard deviation of returns as the squared root of the variance:

sd_WMT = sqrt(var_WMT[1,1])
sd_TSLA = sqrt(var_TSLA[1,1])

We can also use the sd function to get the standard deviation using the historical return series:

sd_WMT = sd(r$WMT)
sd_TSLA = sd(r$TSLA)

Both ways we get the same result.

Then the historical standard deviation of cc returns can be used as an estimation of the expected risk of 1 asset for the next future period.

Now that we have simple measures for expected return and risk of 1 asset, we move to methods to estimate the expected return of a portfolio.

2.4 Historical Sharpe ratio of a portfolio

The Sharpe ratio is a standardized measure of portfolio premium return after considering its volatility.

A premium return is the return above the risk-free rate. In Mexico the risk-free rate is the CETES; in the US, the risk-free rate is the Treasury Bills.

Then, the Sharpe ratio tells us how much portfolio returns (above the risk free rate) we can expect for each percent point of volatility. Let’s see the formula:

SharpeRatio=\frac{(PortfolioReturn-riskfreeRate)}{PortfolioVolatility}

3 Calculating expected portfolio return

Up to now we have calculated expected return and risk of 1 asset using historical mean and standard deviation of historical cc returns.

Here we review how to estimate future expected portfolio returns and risk based on Portfolio Theory developed by Harry Markowitz.

3.1 Expected portfolio return

The expected portfolio returns is the weighted average of the individual expected return of the stocks of the portfolio.

Imagine we have a 2-stock portfolio composed as follows:

WalMart: 70%

Tesla: 30%

3.1.1 Method 1: weighted average using a sum of products

We use the weights (%) allocated for each asset to calculate the weighted average as the portfolio expected return:

w1 = 0.7
w2 = 0.3
ER_Portfolio = w1 * ER[1] + w2 * ER[2]
#  ER is a vector of 2 numbers: the expected return of stock 1 and the expected return of stock 2 
names(ER_Portfolio)=c("ER_Portfolio")
ER_Portfolio
ER_Portfolio 
  0.01872233 

Then, the expected return of this portfolio for the future month is 1.8722329%.

3.1.2 Method 2: weighted average using matrix algebra

Another way to calculate the expected return of a portfolio is using matrix algebra. This is a very useful method when we have many assets in the portfolio since it is very easy to compute.

If you do not remember how to multiply matrices, it is strongly recommended to review this (you can read Note 2 of Portfolio Theory).

Matrix multiplication is used to compute sum of products or sum of multiplications.

For example, the way to estimate the expected return of our portfolio is the following:

ERPort=t\left(W\right)*ER

ERPort=\begin{bmatrix}w_{1} & w_{2}\end{bmatrix}*\begin{bmatrix}ER_{1}\\ ER_{2}\end{bmatrix}

We compute this in R as follows:

# We set a vector composed of the asset weights:
W = c(w1,w2)
# We multiply the transpose of the weight vector times the vector of expected returns
ER_portfolio = t(W) %*% ER
ER_portfolio
           [,1]
[1,] 0.01872233

The transposed of a matrix or a vector is the conversion of the rows by columns and columns by rows. Transposing is like rotating a vector or a matrix 90 degrees:

t\left(\left[\begin{array}{c}w_1\\w_2\end{array}\right]\right)=\left[\begin{array}{cc}w_1 & w_2\end{array}\right]

Then, the previous matrix multiplication was:

\begin{bmatrix}w_{1} & w_{2}\end{bmatrix}*\begin{bmatrix}ER_{1}\\ ER_{2} \end{bmatrix}

\begin{bmatrix}0.7 & 0.3\end{bmatrix}*\begin{bmatrix}0.0110\\ 0.0468 \end{bmatrix}=0.7*0.0110+0.3*0.0468 With this multiplication we got the same expected portfolio return as above.

3.2 Expected portfolio risk

Before we calculate the expected portfolio risk we need to understand what is the expected portfolio variance.

According to Portfolio Theory, the expected variance of a 2-asset portfolio returns is given by:

VAR(PortReturns)=w_{1}^{2}VAR(r_{1})+w_{2}^{2}VAR(r_{2})+2w_{1}w_{2}COV(r_{1},r_{2}) r_1 refers to returns of stock 1, and r_2 refers to returns of stock 2.

COV(r_1,r_2) is the covariance of return 1 and return 2.

Check the lecture note Basics of Portfolio Theory-Note 1 to understand why this is the way to estimate the expected variance of a 2-asset portfolio.

It is worth to remember what is covariance.

3.2.1 What is covariance of 2 stock returns?

The covariance of 2 stock returns is the arithmetic mean of the product return deviations. A deviation is the difference between the stock return in a period t and its mean. Here is the formula:

COV(r_{1},r_{2})=\frac{(r_{(1,1)}-\bar{r_{1}})(r_{(2,1)}-\bar{r_{2}})+(r_{(1,2)}-\bar{r_{1}})(r_{(2,2)}-\bar{r_{2}})+(r_{(1,3)}-\bar{r_{1}})(r_{(2,3)}-\bar{r_{2}})+...}{N}

Were:

r_{(1,1)} is the return of stock 1 in the period 1

r_{(2,1)} is the return of stock 2 in the period 1

Then:

r_{(i,j)} is the return of stock i in the period j

\bar{r_{1}} is the average return of stock 1

\bar{r_{2}} is the average return of stock 2

Then, in the numerator we have a sum of product deviations. Each product deviation is the deviation of the stock 1 return multiplied by the deviation of the stock 2 return.

The covariance is a measure of linear relationship between 2 variables. If covariance between stock return 1 and stock return 2 is positive this means that both stock returns are positively related. In other words, when stock 1 return moves up it is likely that stock 2 return moves up and vice versa; both returns move in the same direction (not always, but mostly).

If covariance is negative that means that stock 1 return is negatively related to stock 2 return; when stock 1 return moves up it is likely that stock 2 return moves down.

Covariance can be a negative or positive number (it is not limited to any number). It is very difficult to interpret the magnitude of covariance. It is much more intuitive if we standardize covariance.

The standardization of the covariance is called correlation.

3.2.2 What is correlation of 2 stock returns?

Correlation of 2 stock returns is also a measure of linear relationship between both returns. The difference compared to covariance is that the possible values of correlation is between -1 and +1, and the correlation gives us a percentage of linear relationship.

Correlation between 2 returns is the covariance between the 2 returns divided by the product of standard deviation of return 1 and standard deviation of return 2.

We calculate correlation as follows:

CORR(r_{1},r_{2})=\frac{COV(r_{1},r_{2})}{SD(r_{1})SD(r_{2})}

Correlation has the following possible values:

-1<=CORR(r_{1},r_{2})<=+1

3.3 Expected variance of a portfolio

Now we can calculate the expected variance of our portfolio according to the previous formula:

3.3.1 Method 1: using sum of products

We calculate the variance of each return series, and the covariance between them:

VAR1 = var(r$WMT)
VAR2 = var(r$TSLA)
COV = cov(r$WMT,y=r$TSLA)

Now we apply the formula to estimate the portfolio variance:

VarPortfolio = w1^2 * VAR1 + w2^2 * VAR2 + 2*w1*w2*COV
VarPortfolio
           WMT
WMT 0.00609912

3.3.2 Method 2: using matrix algebra

Another faster method to get the expected variance of a portfolio is by multiplying the following matrices:

t\left(W\right)*COV*W Where:

W=\begin{bmatrix}w_{1}\\ w_{2} \end{bmatrix}

And COV is the Variance-Covariance matrix, which has the return variances in the diagonal and the pair correlations in the non-diagonal:

COV=\begin{bmatrix}VAR(r_{2}) & COV(r_{1},r_{2})\\ COV(r_{2},r_{1}) & VAR(r_{1}) \end{bmatrix}

We can easily calculate the expected portfolio variance with matrix multiplication in R as follows:

# We calculate the Variance-Covariance matrix with the cov function:
COV =cov(r)
# Note cov function calculates the variance-covariance matrix if r has more than 1 column.
COV
             WMT        TSLA
WMT  0.002634706 0.002630989
TSLA 0.002630989 0.041145543
VarPortfolio = t(W) %*% COV %*% W
VarPortfolio
           [,1]
[1,] 0.00609912

We got the same result as above, but the result now is a matrix of 1 row and 1 element.

It is always good to review the correlation matrix of the asset returns of a portfolios. We can get the correlation matrix with the cor function:

CORR = cor(r)
CORR
           WMT      TSLA
WMT  1.0000000 0.2526921
TSLA 0.2526921 1.0000000

In this case we see 1’s in the diagonal since the correlation of an asset return with itself will always be equal to 1. In the diagonal we see the level of correlation between both asset returns.

3.4 Expected risk of a portfolio

To get the expected risk of a portfolio, we simply get the squared root of the expected variance:

PortRisk=SD(PortReturns)=\sqrt{VAR(PortReturns)}

We do this in R as follows:

PortRisk = sqrt(VarPortfolio[1,1])
PortRisk
[1] 0.07809687

The expected portfolio monthly risk is 7.8096866%. Remember that portfolio risk is also called portfolio volatility. We can annualize portfolio volatility:

AnnualPortRisk = sqrt(12) * PortRisk
AnnualPortRisk
[1] 0.2705355

The expected portfolio annual risk is 27.0535479%.

3.5 Drivers of Portfolio Diversification

Financial portfolios allow an investor to diversify the risk. The main drivers of portfolio diversification are:

  1. N - the number of financial assets. The more the financial assets, the higher the expected diversification.

  2. Combination of pair of correlations between asset returns. The less the correlation of the pair of assets, the more the diversification.

The first driver is just given by N, the number of assets.

The second driver can actually be manipulated by changing the weights allocated for each asset.

In the following section we illustrate how changing asset weights actually change both, the expected return of the portfolio and the expected portfolio volatility.

4 Risk-return space - set of feasible portfolios

Weight combination determines both expected risk and expected return of a portfolio. Let’s do an example with the same 2-asset portfolio:

4.1 Frontier of 2-asset portfolios

Let’s create a set of 11 portfolios where we change the weight assigned to the first stock from 0 to 1 changing by 0.10. We can create a matrix of weights, where each column represents one portfolio:

W=\begin{bmatrix}0 & 0.1 & 0.2 & 0.3 & 0.4 & 0.5 & 0.6 & 0.7 & 0.8 & 0.9\\ 1 & 0.9 & 0.8 & 0.7 & 0.6 & 0.5 & 0.4 & 0.3 & 0.2 & 0.1 \end{bmatrix}

We had already calculated the vector of expected return for each stock:

ER=\begin{bmatrix}ER_{1}\\ ER_{2} \end{bmatrix}=\begin{bmatrix}0.0110\\ 0.0468 \end{bmatrix}

Using the advantage of matrix algebra we can easily get the 11 portfolio expected returns as follows:

ERPortfolios=t(W)*ER

We compute this in R:

# I first create a vector for the weights of the first stock:
w1= seq(from=0,to=1,by=0.1)
w1
 [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
# The weight vector for stock 2 is just the complement of w1:
w2 = 1 - w1
w2
 [1] 1.0 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0.0
# I construct the weight matrix with the cbind function:

W = rbind(w1,w2)
W
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
w1    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1
w2    1  0.9  0.8  0.7  0.6  0.5  0.4  0.3  0.2   0.1     0
# I compute the expected return of the 11 portfolios:
ERPortfolios = t(W) %*% ER

We see that the portfolios with higher expected returns are the first, which are the portfolios with higher weight in stock 2.

Now we can compute the expected risk of the 11 portfolio as follows:

VARPortfolios = t(W) %*% COV %*% W

When we have more than 1 portfolio in the weight matrix, the result of the previous matrix multiplication will be a matrix of 11 rows and 11 columns. The expected variance of the 11 portfolio result in the diagonal of the previous multiplication:

VARPortfolios = diag(VARPortfolios)
VARPortfolios
 [1] 0.041145543 0.033827815 0.027280452 0.021503455 0.016496823 0.012260557
 [7] 0.008794656 0.006099120 0.004173950 0.003019146 0.002634706

Finally, the expected portfolio volatility is the squared root of these 11 expected variances:

RISKPortfolios = sqrt(VARPortfolios)
RISKPortfolios
 [1] 0.20284364 0.18392339 0.16516795 0.14664056 0.12843996 0.11072740
 [7] 0.09377983 0.07809687 0.06460612 0.05494675 0.05132939

Now that we have the 11 portfolio risk and 11 portfolio returns we can plot the 11 portfolios in the risk-return space:

plot(x=RISKPortfolios,y= ERPortfolios,
     xlab="Portfolio Expected Risk", ylab="Portfolio Expected Return")
text(x=RISKPortfolios,y= ERPortfolios,
     labels=w1, cex=0.7, pos=3)

Weights of stock 1 (WMT) are shown in each portfolio. We see that less the w1, the less the expected portfolio risk, but the less the expected portfolio return.

With this illustration we can see how asset weight combination in a portfolio actually change the expected return and risk of a portfolio!

This plot is called the frontier of feasible portfolios of 2 assets. Interestingly, for portfolios with 3 or more assets, the possibilities of feasible portfolios will not be a nice frontier like this. The feasible portfolios will be inside the frontier. In other words, for these portfolios some feasible portfolios will not be efficient since there will be other feasible portfolios with the same level of expected risk, but with higher expected return.

Let’s do an example of 4-asset portfolios.

4.2 Risk-return space of 4-asset portfolios

We will add 2 stocks to our portfolio: Oracle (ORCL) and Freeport-McMoran, Inc (FCX). This last firm is a mining company. I will collect the data for the 4 assets using the same code we used above:

tickers = c("WMT","TSLA","ORCL","FCX")
getSymbols(Symbols = tickers, periodicity="monthly",from="2019-01-01", to="2023-09-18")
[1] "WMT"  "TSLA" "ORCL" "FCX" 
prices = merge(WMT,TSLA,ORCL,FCX)
prices= Ad(prices)
names(prices) = tickers

#Calculating continuously compounded returns:

r = diff(log(prices))
r = na.omit(r)

Since we have now 4 assets, let’s create many feasible portfolios with random weights, but with the condition that the sum of the weights must be 1 (100%). Let’s create 1,000 random portfolios:

# Initialize the Weight matrix
W = c()
# Create 4 vectors of 1000 random values from 0 to 1:
for(i in 1:4) {
  W = rbind(W,runif(1000))
}
# The problem I have now is that some of the 1,000 portfolios
#  might end up having a sum of weights higher than one. 
# I can do a simple "trick" by 
#   dividing each of the 4 weights by the sum of these 4
#   weights. And I can do this # for all 1000 portfolios: 

# I first create a vector with the sum of weights for all portfolios:
sumw <- colSums(W)
# I do another loop to divide each weight by the sum of weights: 
for(i in 1:4)  {
  W[i,]<-W[i,]/sumw
  # In each iteration I divide one raw of W2 by the vector sumw, 
  #  which is the sum of the weights of all 1000 portfolios
}

# I check that the sum of weights is 1 (I do this for 5 portfolios)
W[,1:5]
          [,1]       [,2]        [,3]      [,4]       [,5]
[1,] 0.3159571 0.09623419 0.001943691 0.0267358 0.28616036
[2,] 0.2284452 0.42551281 0.439413589 0.2517846 0.06694027
[3,] 0.3524453 0.13607107 0.051963599 0.3202986 0.31292273
[4,] 0.1031524 0.34218193 0.506679121 0.4011810 0.33397664
colSums(W[,1:5])
[1] 1 1 1 1 1
# All sums are equal to 1, as expected

# Then each column of this matrix represents a random portfolio without allowing for short sales. 

I calculate the expected return of each asset:

ER = exp(colMeans(r)) - 1
ER
       WMT       TSLA       ORCL        FCX 
0.01061976 0.04571929 0.01482923 0.02203555 

I calculate the variance-covariance matrix:

COV = var(r)
COV
             WMT        TSLA        ORCL         FCX
WMT  0.002775657 0.003366656 0.001744690 0.002375802
TSLA 0.003366656 0.041572534 0.004606770 0.012912446
ORCL 0.001744690 0.004606770 0.005729883 0.005203694
FCX  0.002375802 0.012912446 0.005203694 0.021615984

I calculate the correlation matrix to review the correlation levels of pair of assets:

CORR = cor(r)
CORR
           WMT      TSLA      ORCL       FCX
WMT  1.0000000 0.3134098 0.4374843 0.3067184
TSLA 0.3134098 1.0000000 0.2984836 0.4307425
ORCL 0.4374843 0.2984836 1.0000000 0.4675751
FCX  0.3067184 0.4307425 0.4675751 1.0000000

The lowest correlations are the one between ORCL and TSLA and the correlation between WMT and FCX (around 0.12).

We can calculate the expected return of the 1,000 portfolios:

ERPortfolios = t(W) %*% ER

We can calculate the expected risk of the 1,000 portfolios:

VARPortfolios = diag(t(W) %*% COV %*% W) 
RISKPortfolios = sqrt(VARPortfolios)

Now we can visualize the feasible portfolios in the risk-return space:

plot(x=RISKPortfolios,y= ERPortfolios,
     xlabel="Portfolio Expected Risk", ylabel="Portfolio Expected Return")

We can see that for each level of expected risk there are many possible portfolios. The best portfolios will be those that lie in the frontier of this feasible portfolios.

The problem we have when we have 3 or more assets in a portfolio is that we need to find the efficient frontier to get only those portfolios that maximize the expected return for each level of expected risk.

Here is where we need to find optimization algorithms to do this.

In the lecture note Basics of Portfolio Theory - Part III I explain what type of optimization methods can be used.

Fortunately, we can use R packages that already do these complicated optimization algorithms.

5 Illustrating the effect of correlation in a portfolios of 2 assets.

You have to do the following:

  1. Download monthly price data for WMT and TSLA from Yahoo from Jan 2019 to date. Calculate cc returns
  2. Calculate the expected returns and store them in a vector
  3. Calculate the Variance-Covariance matrix of these 2 stock returns
  4. Create a vector wa for simulating different weights for WMT. Create this vector with sequential values from 0 to 1. Create the vector wb, that will be the complement of wa (1-wa) that represent the % invested in TSLA.
  5. Then, with these weight vectors of 11 elements you have to estimate the expected return, variance and expected standard deviation of each of these 11 portfolios.
  6. Do a scatter plot for the portfolio frontier, so that you can see the relationship between risk and return of these 11 portfolios.
  7. You have to simulate 5 portfolio frontiers using the weight vectors with positive weights. Each of these portfolio frontiers will have a hypothetical correlation between WMT and TSLA. Create the first portfolio frontier with a hypothetical correlation of -1, then the 2nd portfolio frontier with a correlation of -0.5, then the 3rd with a correlation of 0, then the 4rd frontier with a correlation of 0.5, and finally, the 5th frontier with a correlation of 1. Graph the 5 frontiers in one plot. What do you observe? Explain with your own words.
  8. Encapsulate the code you wrote in a function that receives the two tickers, initial date and end date, and do the previous steps finishing in the simulation of 5 portfolio frontiers with different levels of correlation.

5.1 Implementing the steps

#I bring prices of WMT and TSLA:

getSymbols(Symbols=c("WMT","TSLA"), 
            from="01-01-2019",
            src="yahoo",
            periodicity="monthly")
[1] "WMT"  "TSLA"
# I merge both datasets
port1<-merge(WMT,TSLA)
rm(WMT,TSLA)
# I calculate returns:
rets<-diff(log(port1))
# I select only adjusted prices
rets.df <-as.data.frame(na.omit(Ad(rets))) 
names(rets.df)<-c("rwmt","rtsla")
head(rets.df)
                   rwmt       rtsla
2010-08-01 -0.020725066 -0.02333895
2010-09-01  0.071055261  0.04663670
2010-10-01  0.012072266  0.06771792
2010-11-01 -0.001477808  0.48098923
2010-12-01 -0.002962755 -0.28269412
2011-01-01  0.044429588 -0.09982616
# I calculate the variance-covariance matrix:
COV<-var(rets.df)
# I calculate the expected (geometric) returns of each stock:
ER <-exp(apply(rets.df,2,mean))-1
ER
       rwmt       rtsla 
0.009517824 0.029875635 
# I create the weights for WMT, from 0 to 1 jumping by 0.10:
wa<-seq(0,1,by=0.1)
# I create the weights for TSLA, which is the complement of the WMT weight:
wb<-1-wa
# I bind both vectors, so that each portfolio will be represented in each column
W<-rbind(wa,wb)
W
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
wa    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1
wb    1  0.9  0.8  0.7  0.6  0.5  0.4  0.3  0.2   0.1     0
#Now I have a matrix in which I represent 11 portfolios. Each column is one portfolio
#Portfolio 1 is composed of 0% WMT, 100%TSLA, while Portfolio 11 is 100%WMT  and 0%TSLA
#I can estimate the Expected return of the 11 portfolio using Matrix Algebra:
ERP <- t(W) %*% ER
#I display the  expected returns of the 11 portfolios:
ERP
             [,1]
 [1,] 0.029875635
 [2,] 0.027839854
 [3,] 0.025804073
 [4,] 0.023768292
 [5,] 0.021732511
 [6,] 0.019696730
 [7,] 0.017660949
 [8,] 0.015625168
 [9,] 0.013589386
[10,] 0.011553605
[11,] 0.009517824
#Now I can get the expected variance and risk of each portfolio:
VARP <-t(W)%*% COV %*% W
#The expected variance of the portfolio will be in the diagonal of this Matrix:
VARP<-diag(VARP)
#I take the square root to get the standard deviation of each portfolio:
RISKP <-sqrt(VARP)
RISKP
 [1] 0.16665465 0.15053671 0.13462187 0.11899167 0.10377478 0.08918303
 [7] 0.07557936 0.06360100 0.05433373 0.04932992 0.04988936
ERP
             [,1]
 [1,] 0.029875635
 [2,] 0.027839854
 [3,] 0.025804073
 [4,] 0.023768292
 [5,] 0.021732511
 [6,] 0.019696730
 [7,] 0.017660949
 [8,] 0.015625168
 [9,] 0.013589386
[10,] 0.011553605
[11,] 0.009517824
class(ERP)
[1] "matrix" "array" 
class(RISKP)
[1] "numeric"
plot(RISKP,ERP, main="Portolio Risk vs Return")

## Now I will do the same, but I will create more portfolios starting with shorting WMT by 
#  40%:
wa2<-seq(-0.4,1.4,0.1)
wb2<-1-wa2
W2<-rbind(wa2,wb2)
W2
    [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
wa2 -0.4 -0.3 -0.2 -0.1    0  0.1  0.2  0.3  0.4   0.5   0.6   0.7   0.8   0.9
wb2  1.4  1.3  1.2  1.1    1  0.9  0.8  0.7  0.6   0.5   0.4   0.3   0.2   0.1
    [,15] [,16] [,17] [,18] [,19]
wa2     1   1.1   1.2   1.3   1.4
wb2     0  -0.1  -0.2  -0.3  -0.4
#Now I have a matrix in which I represent 19 portfolios. Each column is one portfolio
#Portfolio 1 is composed of -40% WMT, 140% TSLA, while Portfolio 11 is 140% WMT and -40% TSLA
#I can estimate the Expected return of the 11 portfolio using Matrix Algebra:
ERP2 <- t(W2) %*% ER
#I display the  expected returns of the 11 portfolios:
ERP2
             [,1]
 [1,] 0.038018760
 [2,] 0.035982979
 [3,] 0.033947197
 [4,] 0.031911416
 [5,] 0.029875635
 [6,] 0.027839854
 [7,] 0.025804073
 [8,] 0.023768292
 [9,] 0.021732511
[10,] 0.019696730
[11,] 0.017660949
[12,] 0.015625168
[13,] 0.013589386
[14,] 0.011553605
[15,] 0.009517824
[16,] 0.007482043
[17,] 0.005446262
[18,] 0.003410481
[19,] 0.001374700
#Now I can get the expected variance and risk of each portfolio:
VARP2 <-t(W2)%*% COV %*% W2
#The expected variance of the portfolio will be in the diagonal of this Matrix:
VARP2<-diag(VARP2)
#I take the square root to get the standard deviation of each portfolio:
RISKP2 <-sqrt(VARP2)
RISKP2
 [1] 0.23230553 0.21576957 0.19930222 0.18292202 0.16665465 0.15053671
 [7] 0.13462187 0.11899167 0.10377478 0.08918303 0.07557936 0.06360100
[13] 0.05433373 0.04932992 0.04988936 0.05584510 0.06574665 0.07810754
[19] 0.09194114
ERP2
             [,1]
 [1,] 0.038018760
 [2,] 0.035982979
 [3,] 0.033947197
 [4,] 0.031911416
 [5,] 0.029875635
 [6,] 0.027839854
 [7,] 0.025804073
 [8,] 0.023768292
 [9,] 0.021732511
[10,] 0.019696730
[11,] 0.017660949
[12,] 0.015625168
[13,] 0.013589386
[14,] 0.011553605
[15,] 0.009517824
[16,] 0.007482043
[17,] 0.005446262
[18,] 0.003410481
[19,] 0.001374700
names(wa)<-wa
wa
  0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9   1 
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 
plot(RISKP2,ERP2, main="Portolio Risk vs Return")

lines(RISKP2,ERP2,col="blue")
lines(RISKP,ERP,col="green")
text(RISKP2,ERP2,labels=wa2, cex=0.7, pos=3)

##Now I will simulate different levels of correlations between both assets, starting
# from -1 to 1 jumping by 0.5

#I can start with  the case of corr (r) = -1
# To calculate the expected variance of each of the portfolios, I can modify the VAriance-Covariance
#  matrix according to this simulated correlation

# Remember that the correlation is the standardized version of the covariance:
# Corr(r1,r2) = Cov(r1,r2) / (sd(r1)*sd(r2))
# Then:
#  Cov(r1,r2)= Corr(r1,r2) * sd(r1)* sd(r2)
#Then, for a simulated correlation= -1:
# Cov(r1,r2) = -1*sd(r1)*sd(r2)

#I can get the standard deviation of a column of a dataframe as:
sd(rets.df$rwmt)
[1] 0.04988936
#I can also use the apply function to the dataframe:
apply(rets.df,2,sd)
      rwmt      rtsla 
0.04988936 0.16665465 
#I can also get the standard deviation from the variance-covariance matrix:
covmat1 <-var(rets.df)  
sdrwmt <-sqrt(covmat1[1,1])
sdrwmt
[1] 0.04988936
sdrtsla <- sqrt(covmat1[2,2])
sdrtsla
[1] 0.1666547
#Then, if I assume a correlation of - 1, I can construct the variance-covariance matrix as follows:
covmat1[1,2]=-1*sd(rets.df$rwmt)*sd(rets.df$rtsla)
covmat1[2,1]<-covmat1[1,2]
covmat1
              rwmt        rtsla
rwmt   0.002488948 -0.008314294
rtsla -0.008314294  0.027773772
# The expected return is the same as the expected returns I calculated before since 
#   I am only manimpulating correlations, not mean returns

#Then, I can use a loop instead of repeating the same code for 5 different correlations:

RISKMAT<-matrix(0,nrow=19,ncol=5)
COV<-var(rets.df)
i=0
# I create a vector with colors, so that each correlation level will have one color
cols<-c("red","blue","green","brown","yellow")
for (r in seq(-1,1,by=0.5)) {
  i=i+1
  covmat1<-COV
  # I calculate the corresponding covariance between WMT and TSLA return for the corresponding
  #   level of correlation r
  covmat1[1,2]=r*sd(rets.df$rwmt)*sd(rets.df$rtsla)
  covmat1[2,1]<-covmat1[1,2]
  RISKMAT[,i]<-sqrt(diag(t(W2)%*%covmat1%*%W2))
  # Only in the first iteration I draw the plot, and then a line for the correlation
  if (i==1) {
    plot(RISKMAT[,i],ERP2, xlab="Portfolio volatility", ylab="Portfolio Expected Return",
         main="Portfolios of 2 Assets: WMT & TSLA",
         col=cols[i])
    lines(RISKMAT[,i],ERP2,type="b",col=cols[i])  
    text(RISKMAT[,i],ERP2,labels=wa, cex=0.7, pos=3)
  }
  # For the second iteration and the last one I just add a line for the corresponding set of
  #   portfolios with the corresponding correlation level r:
  else {
    lines(RISKMAT[,i],ERP2,col=cols[i])  
    text(RISKMAT[,i],ERP2,labels=wa, cex=0.7, pos=3)
  }
}
# I just add a legend for the frontiers according to each hypothetical correlation:
legend("bottomright",legend=c("r=-1","r=-0.5","r=0","r=0.5","r=1"),
       col=cols,lty=1:5,cex=0.7)

With this plot I can better appreciate the “magic” of diversification when the correlation between the assets change from a very high positive correlation to a low positive correlation, up to a very high negative correlation.

If both assets are perfectly correlated (correlation=+1), I can see that the risk-reward relationship is actually linear with positive trend, as exected. The reason is that making a portfolio with 2 assets that one correlates exactly than the other is like investing in only in the first assets since there is no diversification at all.

If the correlation starts to go down, then I can see how the straight line is transfored to a horizontal parabol. The lowest the correlation, the more the diversification. When the horizontal parabole is more pronounced towards the left is when we have more diversification since we can find portfolios with less expected risk.

When correlation is exactly -1 we can see like a triangle where I can see a portfolio with portfolio equal to zero. This happens when the weights of the assets is 0.50 for both. This case is similar to the case of a ruleta where I bet 50% of my money in even numbes and 50% in odd numbers. Then, for sure I have no risk since I will always win or lose the same amount of money.

I see this phenomenon in the Markowitz formula to estimate the expected variance of a portfolio. Remember the formula in the case of 2 assets returns (ra and rb):

VAR(P) = wa^2 * VAR(r_a) + wb^2 * VAR(r_b) + 2*wa*wb*COV(r_a,r_b)

Since correlation is the standardized version of the covariance, then I can also express portfolio variance as:

VAR(P) = wa^2 * VAR(r_a) + wb^2 * VAR(r_b) + 2*wa*wb*CORR(r_a,r_b)*\sigma_{ra}*\sigma_{rb}

Then I can clearly see that when CORRELATION is negative, then the variance of the portfolio will be reduced.

6 Portfolio optimization

Out of all feasible portfolios we might be interested in the following:

  1. The portfolio with the least expected risk of all - The Global Minimum Variance Portfolio (GMV)

  2. The efficient frontier - all portfolios that offer the highest expected return for any level of expected risk

  3. The tangent/optimal portfolio - The portfolio with the highest Sharpe Ratio

We need to install the IntroCompFinR package. You need to install this package using the Console, and typing:

install.packages(“IntroCompFinR”, repos=“http://R-Forge.R-project.org”)

6.1 Estimating the global minimum variance portfolio

We can easily get the GMV portfolio as follows:

library(IntroCompFinR)

GMVPort = globalMin.portfolio(ER,COV)
GMVPort
Call:
globalMin.portfolio(er = ER, cov.mat = COV)

Portfolio expected return:     0.0107325 
Portfolio standard deviation:  0.04885422 
Portfolio weights:
  rwmt  rtsla 
0.9403 0.0597 

Allowing for short-sales, the portfolio with the minimum variance has an expected return of 0.0107325, and expected risk of 0.0488542. We see that FCX has a negative weight, meaning that we need to short FCX with 3.4%.

We can estimate the GMV portfolio without allowing for short sales:

GMVPort = globalMin.portfolio(ER,COV, shorts = FALSE)
GMVPort
Call:
globalMin.portfolio(er = ER, cov.mat = COV, shorts = FALSE)

Portfolio expected return:     0.01073249 
Portfolio standard deviation:  0.04885422 
Portfolio weights:
  rwmt  rtsla 
0.9403 0.0597 

Now the GMV assigned 0% to FCX and 0% to TSLA. This makes sense since both stocks are very volatile. We can check the volatility of each of the stock returns:

library(PerformanceAnalytics)
table.Stats(r)
                  
Observations     1
NAs              0
Minimum          1
Quartile 1       1
Median           1
Arithmetic Mean  1
Geometric Mean   1
Quartile 3       1
Maximum          1
SE Mean         NA
LCL Mean (0.95) NA
UCL Mean (0.95) NA
Variance        NA
Stdev           NA
Skewness        NA
Kurtosis        NA

We can see that the historical volatility (Stdev) of Tesla and FCX are much higher than the volatility of ORCL and WMT.

6.2 Estimating the efficient frontier

efrontier <- efficient.frontier(ER, COV, nport = 100, 
                         alpha.min = -0.5, 
                         alpha.max = 1.5, shorts = FALSE)
plot(efrontier, plot.assets=TRUE, col="blue")

6.3 Estimating the optimal/tangent portfolio

rfree = 0
tangentPort = tangency.portfolio(ER, COV,rfree, shorts=FALSE)
tangentPort
Call:
tangency.portfolio(er = ER, cov.mat = COV, risk.free = rfree, 
    shorts = FALSE)

Portfolio expected return:     0.01394259 
Portfolio standard deviation:  0.0556831 
Portfolio weights:
  rwmt  rtsla 
0.7826 0.2173 
tangentPortWeights = getPortfolio(ER, COV, weights=tangentPort$weights)
plot(tangentPortWeights, col="blue")

Finally, we can plot the efficient frontier, the tangent portfolio and the Capital Market Line:

plot(efrontier, plot.assets=TRUE, col="blue", pch=16)
points(GMVPort$sd, GMVPort$er, col="green", pch=16, cex=2)
points(tangentPort$sd, tangentPort$er, col="red", pch=16, cex=2)
text(GMVPort$sd, GMVPort$er, labels="GLOBAL MIN", pos=2)
text(tangentPort$sd, tangentPort$er, labels="TANGENCY", pos=2)

SharpeRatio = (tangentPort$er - rfree)/tangentPort$sd

abline(a=rfree, b=SharpeRatio, col="green", lwd=2)

The Capital Market Line (CML) is the green line that goes from the risk-free rate to the tangent portfolio. One of the main findings of portfolio theory is that when we add 1 risk-free instrument to a portfolio composed of stocks, the new efficient frontier becomes the Capital Market Line (instead of the hyperbola), which is more efficient that the previous efficient frontier (the hyperbola).

Then, an investor can play between the tangent portfolio and the risk-free rate to move in the CML. If an investor has a middle-level aversion to risk, he/she might select to allocate 50% to the risk-free asset and the rest 50% in the tangent portfolio, locating the portfolio in a mid-point in the CML between the risk-free rate and the tangent portfolio.

6.4 Assumptions of Portfolio Theory

The main assumption of portfolio theory is that all investors behave as rational participants all the time. In other words, they always maximize return and minimize risk using the available information disclosed to the market in a rational way. In other words, they act with no emotions, no fear and they always understand what happen in the market.

7 The single-index model

The Single index model is a factor model to better understand how an asset return is linearly related with an index return over time. This index is usually the market index, so we can learn how much an asset return is following or is related with the return of the market.

The simple linear regression model is used to understand the linear relationship between two variables assuming that one variable, the independent variable (IV), can be used as a predictor of the other variable, the dependent variable (DV). In this part we illustrate a single index model as a simple regression model.

The single-index model states that the expected return of a stock is given by its alpha coefficient (b0) plus its market beta coefficient (b1) multiplied times the market return. In mathematical terms:

E[R_i] = α + β(R_M)

We can express the same equation using B0 as alpha, and B1 as market beta:

E[R_i] = β_0 + β_1(R_M)

We can estimate the alpha and market beta coefficient by running a simple linear regression model specifying that the market return is the independent variable and the stock return is the dependent variable. It is strongly recommended to use continuously compounded returns instead of simple returns to estimate the market regression model. The market regression model can be expressed as:

r_{(i,t)} = b_0 + b_1*r_{(M,t)} + ε_t

Where:

ε_t is the error at time t. Thanks to the Central Limit Theorem, this error behaves like a Normal distributed random variable ∼ N(0, σ_ε); the error term ε_t is expected to have mean=0 and a specific standard deviation σ_ε (also called volatility).

r_{(i,t)} is the return of the stock i at time t.

r_{(M,t)} is the market return at time t.

b_0 and b_1 are called regression coefficients.

7.1 Running a single-index model with real data

7.1.1 Data collection

We first load the quantmod package and download monthly price data for Tesla and the S&P500 market index. We also merge both datasets into one:

# load package quantmod
library(quantmod)

# Download the data
getSymbols(c("TSLA", "^GSPC"), from="2019-01-01", to= "2022-10-31", periodicity="monthly")
[1] "TSLA" "GSPC"
#Merge both xts-zoo objects into one dataset, but selecting only adjusted prices:

adjprices<-Ad(merge(TSLA,GSPC))

7.1.2 Return calculation

We calculate continuously returns for both, Tesla and the S&P500:

returns <- diff(log(adjprices)) 
#I dropped the na's:
returns <- na.omit(returns)

#I renamed the columns:
colnames(returns) <- c("TSLA", "GSPC")

7.1.3 Visualize the relationship

Do a scatter plot putting the S&P500 returns as the independent variable (X) and the stock return as the dependent variable (Y). We also add a line that better represents the relationship between the stock returns and the market returns.Type:

plot.default(x=returns$GSPC,y=returns$TSLA)
abline(lm(returns$TSLA ~ returns$GSPC),col='blue')

# As you see, I indicated that the Market returns goes in the X axis and 
#   Tesla returns in the Y axis. 
# In the single-index model, the independent variable is the market returns, while
#   the dependent variable is the stock return

Sometimes graphs can be deceiving. Always check the Y sale and the X scale. In this case, the X goes from -0.10 to 0.10, while the Y scale goes from -0.20 to 0.40. Then, the real slope of the line should be steeper.

We can change the X scale so that both Y and X axis have similar ranges:

# I indicate that X axis goes from -0.7 to 0.7
plot.default(x=returns$GSPC,y=returns$TSLA, xlim=c(-0.7,0.7))
abline(lm(returns$TSLA ~ returns$GSPC),col='blue')

Now we see that the the market and stock returns have a similar scale. With this we can better appreciate their linear relationship.

WHAT DOES THE PLOT TELL YOU? BRIEFLY EXPLAIN

7.2 Running the single-index regression model

We can run the market regression model with the lm() function. The first parameter of the function is the DEPENDENT VARIABLE (in this case, the stock return), and the second parameter must be the INDEPENDENT VARIABLE, also named the EXPLANATORY VARIABLE (in this case, the market return).

What you will get is called The single-index regression model. You are trying to examine how the market returns can explain stock returns from Jan 2017 to Dec 2020.

Assign your single-index model to an object named “model1”:

model1 <- lm(TSLA ~ GSPC, data=returns)
summary(model1)

Call:
lm(formula = TSLA ~ GSPC, data = returns)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.35579 -0.07596 -0.00766  0.10567  0.40883 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.03627    0.02386   1.520    0.136    
GSPC         2.16271    0.42682   5.067 8.13e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.1584 on 43 degrees of freedom
Multiple R-squared:  0.3739,    Adjusted R-squared:  0.3593 
F-statistic: 25.67 on 1 and 43 DF,  p-value: 8.126e-06

YOU HAVE TO INTERPRET THIS MODEL. MAKE SURE YOU RESPOND THE FOLLOWING THE QUESTIONS:

- IS THE STOCK SIGNIFICANTLY OFFERING RETURNS OVER THE MARKET?

- IS THE STOCK SIGNIFICANTLY RISKIER THAN THE MARKET?

We can save the regression summary in another variable and display the regression coefficients:

s <-summary(model1)
s$coefficients
              Estimate Std. Error  t value     Pr(>|t|)
(Intercept) 0.03626792 0.02386133 1.519945 1.358444e-01
GSPC        2.16271240 0.42682249 5.067007 8.125628e-06

The beta0 coefficient is in the first row (the intercept), while the beta1 coefficient is in the second raw.

The regression coefficients will be in the first column of this matrix. The second column is the standard error of the coefficients, which are the standard deviation of the coefficients. The third column is the t-value of each coefficient, and finally their p-values in the fourth column.

We can get beta0, beta1, standard errors, t-values and p-values and store in other variables:

b0= s$coefficients[1,1]
b1= s$coefficients[2,1]

stderr_b0 = s$coefficients[1,2]
stderr_b1 = s$coefficients[2,2]

tval_b0 = s$coefficients[1,3]
tval_b1 = s$coefficients[2,3]

pvalue_b0 = s$coefficients[1,4]
pvalue_b1 = s$coefficients[2,4]

The reference [2,1] of the matrix s$coefficients means that I want to get the element of the matrix that is in the row #2 and the column #1. In this position we can find the beta1 of the model.

Then, any R matrix you can make reference as matrix[#row,#column] to get the value of any cell according to its position in row and column numbers.

We can also get the coefficients applying the function coef to the regression object:

coefs <- coef(model1)
coefs
(Intercept)        GSPC 
 0.03626792  2.16271240 
b0 = coefs[1]
b1 = coefs[2]

8 CHALLENGE

You have to find the optimal portfolio of a 4 US stocks with 2 methods:

  • Estimate the Variance-Covariance matrix according to the Markowitz Portfolio Theory

  • Estimate the Variance-Covariance matrix according to the Single-Index Model. In this case you have to use the Single-index model to estimate the individual Expected return of each stock, so you have to make an assumption about the expected return of the market.

    The 4 stocks must be from different industries and will be announced in class. You have to use historical monthly data (3 to 5 years of data).

    You have to do the following:

  • Estimate the efficient frontier for both methods

  • Estimate the optimal portfolio for both methods for a risk-free rate of 4% annual rate

  • Compare the 2 methods and their results. Explain the differences and why do you think the results are different? Which method would you prefer and why?

9 QUIZ 1

You have to respond Quiz 1 related to the theory of this workshop. You will have 3 attempts.

10 W1 submission

The grade of this Workshop will be the following:

  • Complete (100%): If you submit an ORIGINAL and COMPLETE HTML file with all the activities, with your notes, and with your OWN RESPONSES to questions

  • Incomplete (75%): If you submit an ORIGINAL HTML file with ALL the activities but you did NOT RESPOND to the questions and/or you did not do all activities and respond to some of the questions.

  • Very Incomplete (10%-70%): If you complete from 10% to 75% of the workshop or you completed more but parts of your work is a copy-paste from other workshops.

  • Not submitted (0%)

Remember that you have to submit your .html file through Canvas BEFORE THE FIRST CLASS OF NEXT WEEK.