joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
219 stars 71 forks source link

xlim is not set until plot is rendered #375

Closed joshuaulrich closed 1 year ago

joshuaulrich commented 2 years ago

This is a regression from previous behavior. It causes this test in highfrequency to fail (the warning is expected).

library(highfrequency)
data("sampleOneMinuteData")
init <- list(sigma = 0.0013, sigma_mu = 0.03, sigma_h = 0.007,
             sigma_k = 0.03, phi = 0.194, rho = 0.986, mu = c(-0.12,1),
             delta_c = c(-0.6, 2, 1, -3, 1),
             delta_s = c(0.7, -3, 1.4, -2, 1.7))
spot <- spotVol(sampleOneMinuteData[, list(DT, PRICE = MARKET)],
                method = "detPer", control = list(trace = 0))

# plot is not automatically rendered
p1 <- plot(spot$periodic)
all.equal(p1$get_xlim(), c(996917700, 996940800))
## Warning message:
## In detPer(mR, rData = rData, options = options) :
##   Periodicity estimation is unstable when the sample data contains less than 50 days.
##   The quality of results may vary
##
## [1] "Mean relative difference: 181259863"

# force rendering
plot(p1)
all.equal(p1$get_xlim(), c(996917700, 996940800))
## [1] TRUE
joshuaulrich commented 2 years ago

This was changed in 6677010ed78e9dc76d7678ca9f9f6eda39c8991d in order to be able to add series that have new index values. A possible fix is to have get_xlim() calculate the current xlim at the time it's called. Not sure how plausible this is though.