Transforming a Series to Stationary

Most financial and economic times series are not stationary. Even when you adjust them for seasonal variations, they will exhibit trends, cycles, random walk and other non-stationary behavior. We can use a variety of techniques to make a non-stationary series stationary depending on the kind of non-stationary behavior present in the series. The two techniques we will learn are called differencing and logarithmic transformations.

Differencing

Under this technique, we difference the data. That is, given the series Z(t), we create the new series:

Y(i) = Z(i) - Z(i-1)

The differenced data will contain one less point than the original data. Usually, one differencing is sufficient to stationarize the data. However, you can difference the data more than once, if needed. In R, differencing is done using the diff() function.

Differencing a time series can remove a linear trend from it. In finance or stock markets, a series of asset returns or stock returns is the differenced time series which is calculated by taking differences of prices on consecutive time intervals.

Seasonal Differencing

If a series has seasonality present in it, then we can use seasonal differencing to remove these periodic patterns. For monthly data, in which there are 12 periods in a season, the seasonal difference of Y at period t is Y(t) - Y(t-12). for quarterly data, the difference will be based on a lag of 4 data points.

Log Transformation

Log transformation can be used to stabilize the variance of a series with non-constant variance. This is done using the log() function. One limitation of log transformation is that it can be applied only to positively valued time series. Taking a log shrinks the values towards 0. For values that are close to 1, the shrinking is less and for the values that are higher, the shrinking is more, thus reducing the variance.

For negative data, you can add a suitable constant to make all the data positive before applying the transformation. This constant can then be subtracted from the model to obtain predicted (i.e., the fitted) values and forecasts for future points.

This also makes the case for why usage of log returns is popular in finance, rather than the prices or raw returns.

In the next lesson, we will learn about how we can apply these transformations.

Related Downloads

Data Science in Finance: 9-Book Bundle

Data Science in Finance Book Bundle

Master R and Python for financial data science with our comprehensive bundle of 9 ebooks.

What's Included:

  • Getting Started with R
  • R Programming for Data Science
  • Data Visualization with R
  • Financial Time Series Analysis with R
  • Quantitative Trading Strategies with R
  • Derivatives with R
  • Credit Risk Modelling With R
  • Python for Data Science
  • Machine Learning in Finance using Python

Each book includes PDFs, explanations, instructions, data files, and R code for all examples.

Get the Bundle for $39 (Regular $57)
JOIN 30,000 DATA PROFESSIONALS

Free Guides - Getting Started with R and Python

Enter your name and email address below and we will email you the guides for R programming and Python.

Data Science in Finance: 9-Book Bundle

Data Science in Finance Book Bundle

Master R and Python for financial data science with our comprehensive bundle of 9 ebooks.

What's Included:

  • Getting Started with R
  • R Programming for Data Science
  • Data Visualization with R
  • Financial Time Series Analysis with R
  • Quantitative Trading Strategies with R
  • Derivatives with R
  • Credit Risk Modelling With R
  • Python for Data Science
  • Machine Learning in Finance using Python

Each book comes with PDFs, detailed explanations, step-by-step instructions, data files, and complete downloadable R code for all examples.