Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Quantitative Finance with R

You're reading from   Learning Quantitative Finance with R Implement machine learning, time-series analysis, algorithmic trading and more

Arrow left icon
Product type Paperback
Published in Mar 2017
Publisher Packt
ISBN-13 9781786462411
Length 284 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
PRASHANT VATS PRASHANT VATS
Author Profile Icon PRASHANT VATS
PRASHANT VATS
Dr. Param Jeet Dr. Param Jeet
Author Profile Icon Dr. Param Jeet
Dr. Param Jeet
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Introduction to R FREE CHAPTER 2. Statistical Modeling 3. Econometric and Wavelet Analysis 4. Time Series Modeling 5. Algorithmic Trading 6. Trading Using Machine Learning 7. Risk Management 8. Optimization 9. Derivative Pricing

Linear filters


The first step in time series analysis is to decompose the time series in trend, seasonality, and so on.

One of the methods of extracting trend from the time series is linear filters.

One of the basic examples of linear filters is moving average with equal weights.

Examples of linear filters are weekly average, monthly average, and so on.

The function used for finding filters is given as follows:

Filter(x,filter)

Here, x is the time series data and filter is the coefficients needed to be given to find the moving average.

Now let us convert the Adj.Close of our StockData in time series and find the weekly and monthly moving average and plot it. This can be done by executing the following code:

> StockData <- read.zoo("DataChap4.csv",header = TRUE, sep = ",",format="%m/%d/%Y") 
>PriceData<-ts(StockData$Adj.Close, frequency = 5)
> plot(PriceData,type="l")
> WeeklyMAPrice <- filter(PriceData,filter=rep(1/5,5))
> monthlyMAPrice <- filter(PriceData,filter=rep...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image