Hands-On Financial Trading with Python by Jiri Pik Sourav Ghosh
Author:Jiri Pik, Sourav Ghosh
Language: eng
Format: epub
Publisher: Packt Publishing Limited
Published: 2021-04-29T00:00:00+00:00
Figure 6.4 â Plot displaying synthetic prices with ETS components
In the preceding screenshot, we do see the seasonality component very clearlyâthe oscillation up and down from the median value. We also see the error noise since the oscillations are not perfect. Finally, we see that the values are increasingâthe trend component.
The Hodrick-Prescott filter
The Hodrick-Prescott (HP) filter is used to separate the trend and cyclical components from time series data by removing short-term fluctuations from the longer-term trend. In statsmodels, this is implemented as statsmodels.api.tsa.filters.hpfilter(...).
Let's use it with a lamb=129600 smoothing parameter to perform the decomposition (the value 129600 is the recommended value for monthly data). We use a pair of series values returned to generate a DataFrame with Price, hp_cycle, and hp_trend fields to represent the price, the seasonal component, and the trend components, as illustrated in the following code snippet:
hp_cycle, hp_trend =
sm.tsa.filters.hpfilter(dataset['Price'], lamb=129600)
decomp = dataset[['Price']]
decomp['HP_Cycle'] = hp_cycle
decomp['HP_Trend'] = hp_trend
decomp
The decomp DataFrame contains the following data:
Price HP_Cycle HP_Trend
2000-01-31 96.392059 -4.731153 101.123212
2000-02-29 99.659426 -1.839262 101.498688
... ... ... ...
2019-11-30 190.067039 -8.350371 198.417410
2019-12-31 190.676568 -8.107701 198.784269
240 rows à 3 columns
In the next section, we will look at the UnobservedComponents model.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Exploring Deepfakes by Bryan Lyon and Matt Tora(7482)
Robo-Advisor with Python by Aki Ranin(7358)
Offensive Shellcode from Scratch by Rishalin Pillay(5972)
Ego Is the Enemy by Ryan Holiday(4901)
Microsoft 365 and SharePoint Online Cookbook by Gaurav Mahajan Sudeep Ghatak Nate Chamberlain Scott Brewster(4750)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4422)
Python for ArcGIS Pro by Silas Toms Bill Parker(4051)
Elevating React Web Development with Gatsby by Samuel Larsen-Disney(3754)
Machine Learning at Scale with H2O by Gregory Keys | David Whiting(3467)
Learning C# by Developing Games with Unity 2021 by Harrison Ferrone(3267)
Speed Up Your Python with Rust by Maxwell Flitton(3222)
Liar's Poker by Michael Lewis(3197)
OPNsense Beginner to Professional by Julio Cesar Bueno de Camargo(3183)
Extreme DAX by Michiel Rozema & Henk Vlootman(3159)
Agile Security Operations by Hinne Hettema(3111)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic and Jasmin Redzepagic(3102)
Essential Cryptography for JavaScript Developers by Alessandro Segala(3074)
Cryptography Algorithms by Massimo Bertaccini(2990)
AI-Powered Commerce by Andy Pandharikar & Frederik Bussler(2971)
