Closed HLatte closed 3 years ago
This is not a bug.
==
is an exact comparison. Aside from the index, the two data sets also have different column names. How do you expect ==
an R primitive, to match these things up?
I suggest that you compare the numeric values of the columns, after normalizing the index.
I agree with @braverock that this isn't a bug, so there isn't anything we should change in xts. You can use all.equal()
to see the differences between the two objects.
R$ all.equal(amd_tiingo, amd_yahoo)
[1] "Attributes: < Component \"index\": Attributes: < Component \"tclass\": Lengths (2, 1) differ (string compare on first 1) > >"
[2] "Attributes: < Component \"index\": Attributes: < Component \"tclass\": 1 string mismatch > >"
[3] "Attributes: < Component \"index\": Attributes: < Component \"tzone\": 1 string mismatch > >"
[4] "Attributes: < Component \"index\": Mean relative difference: 1.111932e-05 >"
[5] "Attributes: < Component \"src\": 1 string mismatch >"
[6] "Attributes: < Component \"updated\": Mean absolute difference: 46.64628 >"
[7] "Mean relative difference: 0.0002269158"
That said, it may be an issue/infelicity with getSymbols.tiingo()
when it returns daily data. Other getSymbols()
methods return daily data with a Date index, not a POSIXct index. And (as you noticed), that's what causes the issue.
Thank you both. Indeed the problem is with the index. As suggested by braverock, a workaround is to normalize the index. This can be done with the following action before the comparison:
index(amd_tiingo) <- as.Date( index(amd_tiingo), tz="")
The catch is that you must use the parameter tz="" in as.Date(). Otherwise, as.Date() will mess up with the timezone, and the dates are shifted one day backwards. This solution was in one of the comments of this question on Stackoverflow.
I hope this will help somebody in the future.
HL
Description
When comparing 2 xts created by quantmod it returns an "empty" variable. As per below (return from the minimal example):
The only difference I can spot is that the yahoo xts index type is: Indexed by objects of class: [Date] TZ: UTC while the tiingo index is: Indexed by objects of class: [POSIXct,POSIXt] TZ:
Otherwise, everything seems to be similar.
Expected behavior
expected to return TRUE or FALSE if the data for each column and each date are the same or not, respectively.
Minimal, reproducible example
NOTE: replace/add tiingo's API key.
Session Info