Appendix B: Time Series Data

Bernhard Pfaff · 2012

Time series dataThere are several possibilities for dealing with time series data in R. In this appendix a concise account is provided of the date-time classes and the available implementations for creating and handling time series data objects.This is based on Ripley and Hornik (2001), Grothendieck and Petzoldt (2004), Zeileis and Grothendieck (2005), Würtz et al. (2009) and Chalabi et al. (2011).In the next section the classes and methods for handling dates and times are presented.In the rest of this appendix the various possibilities of creating a time series object and its manipulations are discussed. B.1 Date-time classesClasses and methods for defining and manipulating dates and times are provided in the base R distribution as well as in contributed packages.In the following the classes and methods are presented with increasing degree of complexity.The class Date was introduced to base R in version R-1.9.0.This class supports only dates without a time stamp.Internally, dates are represented as the day count since 1 January 1970.The printing of these objects can be adjusted according to the percentage abbreviations listed in ?strptime with the format() method defined for these objects.A coercion method (as.Date()) and utility functions for extracting the day of week (weekdays()) and the month (months()) are available, too.Furthermore, methods for axis labelling in plots and histograms are available as well as facilities for computing and manipulating objects of this class.A second class for handling dates only was implemented in the CRAN package date (see Therneau et al. 2011).In this package an S3 class date is defined in which dates are stored as the count of days since 1 January 1960.This origin is identical to the chosen reference date in SAS.The package offers methods for converting Julian calendar dates to Gregorian calendar dates, where the latter can be expressed Financial Risk Modelling and Portfolio Optimization with R, First Edition.

Read the paper · More papers on PaperTik