10 Group 9
Managers: Arthur Camis and Arthur Pillete
10.1 The setup
<-c("CVCB3.SA","USIM5.SA","VALE3.SA","GGBR4.SA", "NTCO3.SA")
p9_list <- c("0.3" , "0.3", "0.15", "0.10","0.15")
p9_w <- c("BRL","BRL","BRL","BRL", "BRL" )
p9_exc <- cbind(p9_list, p9_w, p9_exc)
p9_wlist colnames(p9_wlist) <- c('ticker','weights','Currency')
#Download data Financial
<- yf_get(tickers = p9_list, first_date = start, last_date = end,freq_data = "daily", thresh_bad_data = 0.5)
p9 <- p9[, c("ticker", "ref_date", "price_adjusted" ) ]
p9 <- merge(p9, p9_wlist , by = "ticker")
p9 # 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(p9, exchanges, by = "ref_date")
p9 $BRL.USD[p9$Currency == "USD"] <- 1
p9# Adjusting currency
$price_adj <- p9$price_adjusted * p9$BRL.USD
p9# Calculating return
<- p9 %>%
ret group_by(ticker) %>%
tq_transmute(select = price_adj,
mutate_fun = periodReturn,
period = "daily",
col_rename = "ret")
<- merge(p9, ret, by = c("ref_date", "ticker"))
p9 # Data tabulation
$ret_product <- p9$ret * as.numeric(p9$weights)
p9# Creating a df of portfolios return
<- p9 %>%
p9_ret group_by(ref_date) %>%
summarise_at(vars(ret_product),
list(p9_return = sum)) %>% as.data.frame()
#Calculating cumulative return per day
for(i in (1:nrow(p9_ret) ) ) {
$p9_cum[i] <- Return.cumulative(p9_ret$p9_return[1:i])
p9_ret
}#Calculating cumulative return total
<- data.frame(matrix(NA, nrow = 1,ncol = 4))
p9_sharpe colnames(p9_sharpe) <- c('p9_return', 'p9_sd', 'p9_rf' , 'p9_sharpe')
$p9_return <- Return.cumulative(p9_ret$p9_return)
p9_sharpe$p9_sd <- sd(p9_ret$p9_return[2:nrow(p9_ret)])
p9_sharpe$p9_rf <- (1+0.03)^(nrow(p9_ret)/252) -1
p9_sharpe$p9_sharpe <- (p9_sharpe$p9_return - p9_sharpe$p9_rf) / p9_sharpe$p9_sd p9_sharpe
10.2 The portfolio
This is the portfolio of this group:
p9_wlist
ticker weights Currency
[1,] "CVCB3.SA" "0.3" "BRL"
[2,] "USIM5.SA" "0.3" "BRL"
[3,] "VALE3.SA" "0.15" "BRL"
[4,] "GGBR4.SA" "0.10" "BRL"
[5,] "NTCO3.SA" "0.15" "BRL"
Checking the sum of weights. The sum of weights is:
10.3 The performance
The current cumulative return of this Portfolio is -0.92 percent.
The current standard deviation of daily returns of this Portfolio is 3.64 percent.
The current Sharpe of this portfolio is -0.324.
ggplot(p9_ret, aes(x= ref_date, y= p9_cum) ) + geom_line(color = "darkorchid2", size = 1.25) +
labs(y = "Portfolio return",
x = "Time",
title = "Group 9: Arthur Camis and Arthur Pillete") + theme_solarized()