joshuaulrich / quantmod

Quantitative Financial Modelling Framework
http://www.quantmod.com/
GNU General Public License v3.0
794 stars 219 forks source link

xts attributes added by getSymbols #378

Closed ggrothendieck closed 1 year ago

ggrothendieck commented 1 year ago

getSymbols adds xts attributes which results in the object being different than the same object after writing it out to a csv file and reading it back in. Suggest an argument to omit these or possibly a pseudo-class specified via return.class = "xts0" .

# https://stackoverflow.com/questions/75929177/75930141#75930141
library(quantmod) # also loads xts and zoo
getSymbols("000001.SZ", from = "1990-10-01")
# \/ if we did not do this then the identical at the end would be FALSE
xtsAttributes(`000001.SZ`) <- NULL

write.zoo(`000001.SZ`, "000001_yahoo.csv", sep = ",")

z <- read.csv.zoo("000001_yahoo.csv", check.names = FALSE)
x <- as.xts(z)

identical(`000001.SZ`, x)
## [1] TRUE
joshuaulrich commented 1 year ago

I wouldn't expect the getSymbols() object would be identical() to the object after it's been written to and then read from a CSV. Objects being identical() is a very strong assertion. For example, xts objects aren't identical() if the attribute order is different, which isn't particularly relevant.

That said, the objects aren't all.equal() either because the attributes are different. But I still don't think this is a problem for most (all?) users. The user in the Stackoverflow question wasn't concerned about whether the objects were identical.

I'm closing this for now, but I'm open to discussing and re-opening.