# 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.

#### Course Downloads

- Financial Time Series Data
- Exploring Time Series Data in R
- Plotting Time Series in R
- Handling Missing Values in Time Series
- Creating a Time Series Object in R
- Check if an object is a time series object in R
- Plotting Financial Time Series Data (Multiple Columns) in R
- Characteristics of Time Series
- Stationary Process in Time Series
- Transforming a Series to Stationary
- Time Series Transformation in R
- Differencing and Log Transformation
- Autocorrelation in R
- Time Series Models
- ARIMA Modeling
- Simulate White Noise (WN) in R
- Simulate Random Walk (RW) in R
- AutoRegressive (AR) Model in R
- Estimating AutoRegressive (AR) Model in R
- Forecasting with AutoRegressive (AR) Model in R
- Moving Average (MA) Model in R
- Estimating Moving Average (MA) Model in R
- ARIMA Modelling in R
- ARIMA Modelling - Identify Model for a Time Series
- Forecasting with ARIMA Modeling in R - Case Study
- Automatic Identification of Model Using auto.arima() Function in R
- Financial Time Series in R - Course Conclusion

# R Programming Bundle: 25% OFF

**R Programming - Data Science for Finance Bundle**for just $29 $39.