7 Group 6
Managers: Gabriel Brosens and Marina Pitanga
7.1 The setup
<-c("MSFT","TSLA","ENPH","AMD")
p6_list <- c(0.6291 , 0.1028, 0.2256, 0.0425)
p6_w <- c("USD","USD","USD","USD" )
p6_exc <- cbind(p6_list, p6_w, p6_exc)
p6_wlist colnames(p6_wlist) <- c('ticker','weights','Currency')
#Download data Financial
<- yf_get(tickers = p6_list, first_date = start, last_date = end,freq_data = "daily", thresh_bad_data = 0.5)
p6 <- p6[, c("ticker", "ref_date", "price_adjusted" ) ]
p6 <- merge(p6, p6_wlist , by = "ticker")
p6 # 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(p6, exchanges, by = "ref_date")
p6 $BRL.USD[p6$Currency == "USD"] <- 1
p6# Adjusting currency
$price_adj <- p6$price_adjusted * p6$BRL.USD
p6# Calculating return
<- p6 %>%
ret group_by(ticker) %>%
tq_transmute(select = price_adj,
mutate_fun = periodReturn,
period = "daily",
col_rename = "ret")
<- merge(p6, ret, by = c("ref_date", "ticker"))
p6 # Data tabulation
$ret_product <- p6$ret * as.numeric(p6$weights)
p6# Creating a df of portfolios return
<- p6 %>%
p6_ret group_by(ref_date) %>%
summarise_at(vars(ret_product),
list(p6_return = sum)) %>% as.data.frame()
#Calculating cumulative return per day
for(i in (1:nrow(p6_ret) ) ) {
$p6_cum[i] <- Return.cumulative(p6_ret$p6_return[1:i])
p6_ret
}#Calculating cumulative return total
<- data.frame(matrix(NA, nrow = 1,ncol = 4))
p6_sharpe colnames(p6_sharpe) <- c('p6_return', 'p6_sd', 'p6_rf' , 'p6_sharpe')
$p6_return <- Return.cumulative(p6_ret$p6_return)
p6_sharpe$p6_sd <- sd(p6_ret$p6_return[2:nrow(p6_ret)])
p6_sharpe$p6_rf <- (1+0.03)^(nrow(p6_ret)/252) -1
p6_sharpe$p6_sharpe <- (p6_sharpe$p6_return - p6_sharpe$p6_rf) / p6_sharpe$p6_sd p6_sharpe
7.2 The portfolio
This is the portfolio of this group:
p6_wlist
ticker weights Currency
[1,] "MSFT" "0.6291" "USD"
[2,] "TSLA" "0.1028" "USD"
[3,] "ENPH" "0.2256" "USD"
[4,] "AMD" "0.0425" "USD"
Checking the sum of weights. The sum of weights is:
7.3 The performance
The current cumulative return of this Portfolio is -13.82 percent.
The current standard deviation of daily returns of this Portfolio is 2.08 percent.
The current Sharpe of this portfolio is -6.779.
ggplot(p6_ret, aes(x= ref_date, y= p6_cum) ) + geom_line(color = "darkgreen", size = 1.25) +
labs(y = "Portfolio return",
x = "Time",
title = "Group 6: Gabriel Brosens and Marina Pitanga") + theme_solarized()