0

Very basic question. I have OHLC data as a dataframe object. What is the advantage of having data as an xts object as opposed to a dataframe?

  • 1
    xts is for time series so consider if you have one. An OHLC object for 1 instrument is a time series. If it contains many instruments in long form then it's not a time series. If it has many instruments in wide form then it still is a time series. – G. Grothendieck Apr 02 '21 at 14:04
  • 2
    (continued) xts is written in C for speed, automatically handles alignments, e.g. you can combine series of different lengths whereas with data frames you may be constantly padding or shortening them . xts & zoo separate index and data making many operations more convenient, is closer to R's built-in ts class for easier conversion and many time series functions use ts class. xts works with a variety of other packages including zoo, quantmod, PerformanceAnalytics, TTR and others. Note that this question borders on opinion so may not satisfy SO requirements. – G. Grothendieck Apr 02 '21 at 14:05
  • Another important point: xts and zoo **guarantee** your data will be ordered correctly, and almost all time series analysis assumes your data are ordered. A data.frame does not have to be ordered and there's no guarantee that what you do to a data.frame will return your data ordered by time. – Joshua Ulrich Feb 28 '23 at 18:11

0 Answers0