library(yfR)
library(ggplot2)
library(ggthemes)
<-c('SPY', 'IVV','VOO', 'SPLG' , '^GSPC')
stocks <-'2010-01-01'
start <-Sys.Date()
end <- yf_get(tickers = stocks,
data first_date = start,
last_date = end)
<-data[complete.cases(data),]
data<- subset(data, ticker == stocks[1])
stock1 <- subset(data, ticker == stocks[2])
stock2 <- subset(data, ticker == stocks[3])
stock3 <- subset(data, ticker == stocks[4])
stock4 <- subset(data, ticker == stocks[5])
stock5 $price_close2 <- stock1$price_close / stock1$price_close[1] * 100
stock1$price_close2 <- stock2$price_close / stock2$price_close[1] * 100
stock2$price_close2 <- stock3$price_close / stock3$price_close[1] * 100
stock3$price_close2 <- stock4$price_close / stock4$price_close[1] * 100
stock4$price_close2 <- stock5$price_close / stock5$price_close[1] * 100
stock5<- rbind(stock1, stock2, stock3, stock4, stock5)
data2 ggplot(data2, aes(ref_date , price_close2, color=ticker))+
geom_line() +
labs(x = "",
y='Closing prices',
title="SP500 against 4 ETFs, Initial price = 100",
subtitle = "Begin 01/01/2010") + theme_solarized()
5 ETFs
This is a book containing all class notes.
5.1 US
Let’s plot a graph of some Exchange-traded funds (ETFs) available in the US market that follows the SP 500 index. As you can see, the adherence is amazing.
5.2 Brazil
Here is the same graph for brazilian ETF Bova11. The adherence seems ok.
library(yfR)
library(ggplot2)
library(ggthemes)
<-c('BOVA11.SA', '^BVSP')
stocks <-'2010-01-01'
start <-Sys.Date()
end <- yf_get(tickers = stocks,
data first_date = start,
last_date = end)
<-data[complete.cases(data),]
data<- subset(data, ticker == stocks[1])
stock1 <- subset(data, ticker == stocks[2])
stock2 $price_close2 <- stock1$price_close / stock1$price_close[1] * 100
stock1$price_close2 <- stock2$price_close / stock2$price_close[1] * 100
stock2<- rbind(stock1, stock2)
data2 ggplot(data2, aes(ref_date , price_close2, color=ticker))+
geom_line() +
labs(x = "",
y='Closing prices',
title="Ibov against 2 ETFs, Initial price = 100",
subtitle = "Begin 01/01/2010") + theme_solarized()