Rafael Martínez Rafael Martínez - 2 months ago 21
R Question

Change data to numeric type to determine which distribution fits better

I am trying to figure out which distribution fits best logarithmic stock returns. Here is my code:

library(TTR)
sign="^GSPC"
start=19900101
end=20160101
x <- getYahooData(sign, start = start, end = end, freq = "daily")
x$logret <- log(x$Close) - lag(log(x$Close))
x=x[,6]


I want to use the function
descdist(x, discrete = FALSE)
which I got from this amazing post http://stats.stackexchange.com/questions/132652/how-to-determine-which-distribution-fits-my-data-best Nonetheless r gives me this error:
Error in descdist(x, discrete = FALSE) : data must be a numeric vector
How do I transform my data to numeric vector??

The output from
dput(head(x))
is:

structure(c(NA, -0.00258888580664607, -0.00865029791190164, -0.00980414107803274,
0.00450431207515223, -0.011856706127011), class = c("xts", "zoo"
), .indexCLASS = "Date", .indexTZ = "UTC", tclass = "Date", tzone = "UTC", index = structure(c(631238400,
631324800, 631411200, 631497600, 631756800, 631843200), tzone = "UTC", tclass = "Date"), .Dim = c(6L,
1L), .Dimnames = list(NULL, "logret"))

Answer

Pre-process x using as.numeric(na.omit(x)), or simply run

descdist(as.numeric(na.omit(x)), discrete = FALSE)