I am retrieving data from yahoo using the getSymbols to get then monthly returns. But I want to subset the data, I want to have monthly returns from January 2016 until May 2017. I am running this:
library(quantmod)
list <- c("AAL","AAPL","ADBE","AMZN", "FB", "GOOGL", "MSFT", "NFLX", "TSLA", "VOD")
df <- data.frame()
##get monthly returns from january 2016 until today
for (stock in list){
data <- monthlyReturn(to.monthly(getSymbols(stock, auto.assign = FALSE)),from='2016-01-01', to='2017-05-31' )
colnames(data)[1] <- paste('r_', stock, sep = "")
df <- cbind(df, data)
}
df <- as.data.frame(df)
attach(df)
And it is not working as I get values from the entire dataset. Instead if I use this:
for (stock in list){
data <- monthlyReturn(to.monthly(getSymbols(stock, auto.assign = FALSE)),subset = "2016::")
colnames(data)[1] <- paste('r_', stock, sep = "")
df <- cbind(df, data)
}
df <- as.data.frame(df)
I get monthly data from January 2016 until today, but that's not what I want as I want to fix the close date too. Any ideas on how to solve that?