• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Finance Train

Finance Train

High Quality tutorials for finance, risk, data science

  • Home
  • Data Science
  • CFA® Exam
  • PRM Exam
  • Tutorials
  • Careers
  • Products
  • Login

Time Series Transformation in R

Data Science

This lesson is part 11 of 27 in the course Financial Time Series Analysis in R

We will now learn about how we can perform the mathematical transformations in R in order to make a non-stationary series stationary.

We have the daily stock prices of an imaginary stock exhibiting rapid growth stored in a csv file. You can download the csv file and follow along this tutorial to perform the transformations in your R console. There are two hundred observations starting from 1st Jan , 2016.

stock_daily.csvDownload

We have placed the csv file in our working directory as shown below:

> setwd("C:/Users/Manish/Dropbox/Finance Train/Courses/Data")
> getwd()
[1] "C:/Users/Manish/Dropbox/Finance Train/Courses/Data"
> list.files()
 [1] "stock_daily.csv"

As you can see, the file stock_daily.csv in available in our working directory.

Load Data in R

We will read this csv file in R using read.csv() function and store the dataset in a variable called sp. The data will be stored as a dataframe.

> sp <- read.csv("stock_daily.csv", header=FALSE)
>
> str(sp)
'data.frame':    200 obs. of  1 variable:
 $ V1: num  254 229 277 262 264 ...
>

Convert dataframe to time series using ts() function

Now that we have the data in a dataframe, we can convert it into a time series object using the ts() function as shown below:

> sp_ts <- ts(sp, start=2016, frequency=365)

Plot the series

Let’s now plot the time series using the plot.ts() function.

> plot.ts(sp_ts,col=4, main="Daily Stock Prices", ylab="Price")

We can observe two things here:

  1. There is a clearly visible upward trend in the data
  2. The variability in the data is increasing over time.

Let’s now look at how we can remove both these patterns to stationarize the series.

Previous Lesson

‹ Transforming a Series to Stationary

Next Lesson

Differencing and Log Transformation ›

Join Our Facebook Group - Finance, Risk and Data Science

Posts You May Like

How to Improve your Financial Health

CFA® Exam Overview and Guidelines (Updated for 2021)

Changing Themes (Look and Feel) in ggplot2 in R

Coordinates in ggplot2 in R

Facets for ggplot2 Charts in R (Faceting Layer)

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

In this Course

  • 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

Latest Tutorials

    • Data Visualization with R
    • Derivatives with R
    • Machine Learning in Finance Using Python
    • Credit Risk Modelling in R
    • Quantitative Trading Strategies in R
    • Financial Time Series Analysis in R
    • VaR Mapping
    • Option Valuation
    • Financial Reporting Standards
    • Fraud
Facebook Group

Membership

Unlock full access to Finance Train and see the entire library of member-only content and resources.

Subscribe

Footer

Recent Posts

  • How to Improve your Financial Health
  • CFA® Exam Overview and Guidelines (Updated for 2021)
  • Changing Themes (Look and Feel) in ggplot2 in R
  • Coordinates in ggplot2 in R
  • Facets for ggplot2 Charts in R (Faceting Layer)

Products

  • Level I Authority for CFA® Exam
  • CFA Level I Practice Questions
  • CFA Level I Mock Exam
  • Level II Question Bank for CFA® Exam
  • PRM Exam 1 Practice Question Bank
  • All Products

Quick Links

  • Privacy Policy
  • Contact Us

CFA Institute does not endorse, promote or warrant the accuracy or quality of Finance Train. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.

Copyright © 2021 Finance Train. All rights reserved.

  • About Us
  • Privacy Policy
  • Contact Us