Exercice 7.62
The data
w<-c(.30,.70) ## Wheights
m<-c(.12,.25) ## Expected Returns of Stocks
s<-c(.02,.15) ##Standard-deviations of Stocks
Question a.
rho<-.5
V<-c(s[1]^2,rho*s[1]*s[2],rho*s[1]*s[2],s[2]^2)
V<-matrix(V,nrow=2,ncol=2)
round((w%*%m)[1],3) ## Expected value of the portfolio
## [1] 0.211
round(sqrt((w%*%V%*%w)[1]),4) ## standard-deviation of the portfolio
## [1] 0.1081
Question b.
rho=.2
V<-c(s[1]^2,rho*s[1]*s[2],rho*s[1]*s[2],s[2]^2)
V<-matrix(V,nrow=2,ncol=2)
round((w%*%m)[1],3) ## Expected value of the portfolio
## [1] 0.211
round(sqrt((w%*%V%*%w)[1]),4) ## standard-deviation of the portfolio
## [1] 0.1064
Question c.
rho=0
V<-c(s[1]^2,rho*s[1]*s[2],rho*s[1]*s[2],s[2]^2)
V<-matrix(V,nrow=2,ncol=2)
round((w%*%m)[1],3) ## Expected value of the portfolio
## [1] 0.211
round(sqrt((w%*%V%*%w)[1]),4) ## standard-deviation of the portfolio
## [1] 0.1052
Exercice 7.64
w<-c(.60,.40) ## Wheights
m<-c(.09,.13) ## Expected Returns of Stocks
s<-c(.15,.21) ##Standard-deviations of Stocks
rho=0.4
V<-c(s[1]^2,rho*s[1]*s[2],rho*s[1]*s[2],s[2]^2)
V<-matrix(V,nrow=2,ncol=2)
round((w%*%m)[1],3) ## Expected value of the portfolio
## [1] 0.106
round(sqrt((w%*%V%*%w)[1]),4) ## standard-deviation of the portfolio
## [1] 0.1456
portfolio with data
library(readxl)
library(tidyverse)
library(stargazer)
library(knitr)
data <- read_excel("Financial_data.xlsx")
dataW<-data%>%
select(order(colnames(data)))%>%mutate(Date=1:60,.before=Amazon)
dataW%>%select(-Date)%>%as.data.frame()%>%
stargazer(type = "latex")
% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy
Institute. E-mail: marek.hlavac at gmail.com % Date and time: Fri, Apr
01, 2022 - 09:39:08
dataW%>%select(-Date)%>%colMeans()->m
kable(t(m),caption = "Expected return of stocks")
Expected return of stocks
0.0283382 |
0.0125269 |
0.0088102 |
0.0056227 |
dataW%>%select(-Date)%>%var()->V
kable(V,caption = "Covariance matrix of stock returns")
Covariance matrix of stock returns
Amazon |
0.0205459 |
-0.0017307 |
0.0016971 |
0.0018512 |
Barrick |
-0.0017307 |
0.0119424 |
0.0018724 |
-0.0005877 |
Coca Cola |
0.0016971 |
0.0018724 |
0.0023922 |
0.0014352 |
Disney |
0.0018512 |
-0.0005877 |
0.0014352 |
0.0044160 |
w<-c(.25,.25,.25,.25)
data.frame(mean=w%*%m,"st.dev"=sqrt(w%*%V%*%m))%>%kable(caption = "Portfolio Return")
Portfolio Return
0.0138245 |
0.014857 |
# On rajoute le portefeuille aux data
dataWP<-dataW%>% mutate(Portfolio=as.matrix(select(dataW,2:5))%*%w)
# On passe en format long
dataLP<-dataWP%>%gather(key="Stock",Return,-Date)
## Warning: attributes are not identical across measure variables;
## they will be dropped
# Le graphique
dataLP%>%ggplot(aes(x=Date,y=Return,color=Stock))+geom_line()+
ggtitle("Stocks and Portfolio historical returns")
