8 Group 7
Managers: Giovanna Barreto, Isabella Pompeu, and Marcela Amarante Cruz
8.1 The setup
<- c("ITSA4.SA","TRPL4.SA","VALE3.SA","QUAL3.SA","SANB11.SA","ARZZ3.SA","PCAR3.SA","RDOR3.SA","EGIE3.SA","TAEE11.SA","GMAT3.SA","OXY","CEG","HES","CTRA","DVN","PVC","ENPH","XOM","META","GOOG")
p7_list <- c("0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476","0.0476190476")
p7_w <- c("BRL","BRL","BRL","BRL","BRL","BRL","BRL","BRL","BRL","BRL","BRL","USD","USD","USD","USD","USD","USD","USD","USD","USD","USD" )
p7_exc <- cbind(p7_list, p7_w, p7_exc)
p7_wlist colnames(p7_wlist) <- c('ticker','weights','Currency')
#Download data Financial
<- yf_get(tickers = p7_list, first_date = start, last_date = end,freq_data = "daily", thresh_bad_data = 0.5)
p7 <- p7[, c("ticker", "ref_date", "price_adjusted" ) ]
p7 <- merge(p7, p7_wlist , by = "ticker")
p7 # Download data Exchange rate
getFX("BRL/USD",from=start , to = end)
<- as.data.frame(BRLUSD)
exchanges $ref_date <- as.Date(rownames(exchanges))
exchanges# Merge
<- merge(p7, exchanges, by = "ref_date")
p7 $BRL.USD[p7$Currency == "USD"] <- 1
p7# Adjusting currency
$price_adj <- p7$price_adjusted * p7$BRL.USD
p7# Calculating return
<- p7 %>%
ret group_by(ticker) %>%
tq_transmute(select = price_adj,
mutate_fun = periodReturn,
period = "daily",
col_rename = "ret")
<- merge(p7, ret, by = c("ref_date", "ticker"))
p7 # Data tabulation
$ret_product <- p7$ret * as.numeric(p7$weights)
p7# Creating a df of portfolios return
<- p7 %>%
p7_ret group_by(ref_date) %>%
summarise_at(vars(ret_product),
list(p7_return = sum)) %>% as.data.frame()
#Calculating cumulative return per day
for(i in (1:nrow(p7_ret) ) ) {
$p7_cum[i] <- Return.cumulative(p7_ret$p7_return[1:i])
p7_ret
}#Calculating cumulative return total
<- data.frame(matrix(NA, nrow = 1,ncol = 4))
p7_sharpe colnames(p7_sharpe) <- c('p7_return', 'p7_sd', 'p7_rf' , 'p7_sharpe')
$p7_return <- Return.cumulative(p7_ret$p7_return)
p7_sharpe$p7_sd <- sd(p7_ret$p7_return[2:nrow(p7_ret)])
p7_sharpe$p7_rf <- (1+0.03)^(nrow(p7_ret)/252) -1
p7_sharpe$p7_sharpe <- (p7_sharpe$p7_return - p7_sharpe$p7_rf) / p7_sharpe$p7_sd p7_sharpe
8.2 The portfolio
This is the portfolio of this group:
p7_wlist
ticker weights Currency
[1,] "ITSA4.SA" "0.0476190476" "BRL"
[2,] "TRPL4.SA" "0.0476190476" "BRL"
[3,] "VALE3.SA" "0.0476190476" "BRL"
[4,] "QUAL3.SA" "0.0476190476" "BRL"
[5,] "SANB11.SA" "0.0476190476" "BRL"
[6,] "ARZZ3.SA" "0.0476190476" "BRL"
[7,] "PCAR3.SA" "0.0476190476" "BRL"
[8,] "RDOR3.SA" "0.0476190476" "BRL"
[9,] "EGIE3.SA" "0.0476190476" "BRL"
[10,] "TAEE11.SA" "0.0476190476" "BRL"
[11,] "GMAT3.SA" "0.0476190476" "BRL"
[12,] "OXY" "0.0476190476" "USD"
[13,] "CEG" "0.0476190476" "USD"
[14,] "HES" "0.0476190476" "USD"
[15,] "CTRA" "0.0476190476" "USD"
[16,] "DVN" "0.0476190476" "USD"
[17,] "PVC" "0.0476190476" "USD"
[18,] "ENPH" "0.0476190476" "USD"
[19,] "XOM" "0.0476190476" "USD"
[20,] "META" "0.0476190476" "USD"
[21,] "GOOG" "0.0476190476" "USD"
Checking the sum of weights. The sum of weights is:
8.3 The performance
The current cumulative return of this Portfolio is -0.01 percent.
The current standard deviation of daily returns of this Portfolio is 2.13 percent.
The current Sharpe of this portfolio is -0.1247.
ggplot(p7_ret, aes(x= ref_date, y= p7_cum) ) + geom_line(color = "cyan4", size = 1.25) +
labs(y = "Portfolio return",
x = "Time",
title = "Group 7: Giovanna Barreto, Isabella Pompeu, and Marcela Amarante Cruz") + theme_solarized()