Strange result on to.Monthly (quantmod package) cut series

Asked

Viewed 145 times

2

Problem with my to.monthly. He cuts my data series, I don’t know why.

####install.packages("quantmod")
library(quantmod)
####install.packages("PerformanceAnalytics")
library(PerformanceAnalytics)
####install.packages("zoo")
library(zoo)

####Definindo diretório principal
setDefaults(getSymbols, src='google')

StartDate = as.Date("2004-01-01") ####data de começo
EndDate = as.Date("2017-01-01") ####data de término


ibovespa <- getSymbols('IBOV', from=StartDate, to=EndDate, auto.assign = F)
ibovespa_monthly <- to.monthly(ibovespa) #->->->->->->->->->problem#####
colnames(ibovespa_monthly) <- c("Open", "High", "Low", "Close","Volume")
ibovespa_return <- (Return.calculate(ibovespa_monthly$Close)[-1,])*100
plot.zoo(ibovespa_return, xlab="Mês", ylab = "Porcentagem")

table.CalendarReturns(ibovespa_return)

1 answer

3


Note that from 2013-06-27, the column ibovespa$IBOV.Volume has only NA. The function to.monthly cannot, as far as I know, deal with this lack of information.

Note that if I switch assets, this error ceases to occur:

petr4         <- getSymbols('petr4', from=StartDate, to=EndDate, auto.assign = F)
petr4_monthly <- to.monthly(petr4)
petr4_monthly

I know little about the stock market, but I don’t think it makes sense to record the volume of the Bovespa index as a whole. It makes sense to think of the volume of negotiations of a particular role, whether VALE5, ITUB4 or PETR4, as in the example. But of Bovespa as a whole I think it makes no sense. I, at least, have never seen.

Therefore, what I suggest is to remove column 5 from the object bovespa for the other results to be calculated correctly.

ibovespa         <- getSymbols('IBOV', from=StartDate, to=EndDate, auto.assign = F)
ibovespa         <- ibovespa[, -5]
ibovespa_monthly <- to.monthly(ibovespa)
  • I hadn’t noticed, but there were NA values in my file. When I applied the function Monthly it only calculated up to the NA value. Thank you, Marcos!!!

  • I’m glad I could help. Please accept my answer so that in the future other people can consult you and solve this same problem if it arises.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.