Converting data to time series

A time series is a sequence of data points where each data point is associated with a particular time.

For example, the adjusted close of a stock is the closing price of a stock on a particular day. The time series data is stored in an R object called a time series object and it is created by using the function ts() in R.

The basic syntax of ts is given here:

ts(data, start, end, frequency) 

Here:

  • data: It is a vector or matrix containing the data values
  • start: It is the starting point or time of first observation
  • end: It is the time point of last observation
  • frequency: It is the number of data points per unit time

Let us consider a vector which is given by the following code:

> StockPrice< -c(23.5,23.75,24.1,25.8,27.6,27,27.5,27.75,26,28,27,25.5) ...

Get Learning Quantitative Finance with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.