Seasonality of Stock Prices +
Seasonality of Stock Prices +
Time Series
Time Series
(Written February 2021)
Using time series I wanted to explore some predictive models and understand how things worked under the hood.
Using time series I wanted to explore some predictive models and understand how things worked under the hood.
To make it easier on myself I first explored using Facebook's Prophet, then subsequently with SARIMA. Both methods would forecast trends and seasonality, which I was especially interested in observing for stock price x time.
To make it easier on myself I first explored using Facebook's Prophet, then subsequently with SARIMA. Both methods would forecast trends and seasonality, which I was especially interested in observing for stock price x time.
As bonus, I wanted to create visualization other than the plots I have normally been doing via Python libraries. To that end I used Tableau Public which is Tableau's free offering for creating and sharing visualizations.
As bonus, I wanted to create visualization other than the plots I have normally been doing via Python libraries. To that end I used Tableau Public which is Tableau's free offering for creating and sharing visualizations.
Steps:
Steps:
Sourcing stock prices with yfinance Python library.
Sourcing stock prices with yfinance Python library.
Applied Facebook Prophet for time series prediction
Applied Facebook Prophet for time series prediction
Applied SARIMA for time series prediction
Applied SARIMA for time series prediction
Viz using Tableau Public
Viz using Tableau Public
First up...
First up...
Prophet was easy to implement and immediately able to plot predictions based on 5 years of stock prices. It simplicity can be extended and tuned based on one's own domain expertise. This model can be used in all types of scenarios where data indexed in time is available and there is an aspect of seasonality i.e. data experiences regular and predictable changes that recur during year/month/day/hour.
Prophet was easy to implement and immediately able to plot predictions based on 5 years of stock prices. It simplicity can be extended and tuned based on one's own domain expertise. This model can be used in all types of scenarios where data indexed in time is available and there is an aspect of seasonality i.e. data experiences regular and predictable changes that recur during year/month/day/hour.
I extracted the results into JSON files which I loaded into Tableau Public for purposes of creating a viz.
I extracted the results into JSON files which I loaded into Tableau Public for purposes of creating a viz.
The viz is time series prediction of stock price for Bank of Montreal on NYSE (ticker: BMO).
Seasonality is observed with higher prices during fall/winter months and on Tuesdays within the week.
next...
next...
I moved onto applying SARIMA (Seasonal Autoregressive Integrated Moving Average) and this was not smooth.
I moved onto applying SARIMA (Seasonal Autoregressive Integrated Moving Average) and this was not smooth.
The resulting graph didn't visibly demonstrate seasonality even though the diagnostics showed ok (Normal Q-Q, Correlogram, standardized residual, etc.).
The resulting graph didn't visibly demonstrate seasonality even though the diagnostics showed ok (Normal Q-Q, Correlogram, standardized residual, etc.).
This is one ugly forecast as exhibited by the large grey blimp...I definitely did something wrong here
next next...
next next...
Given stock prices had dramatically dropped starting March 2020 (COVID pandemic), I deliberated whether to impute or alter the data. As a shortcut I decided to chop up the data from that date onward to see if the results would be better...they were not.
Given stock prices had dramatically dropped starting March 2020 (COVID pandemic), I deliberated whether to impute or alter the data. As a shortcut I decided to chop up the data from that date onward to see if the results would be better...they were not.
At this point I stopped.
At this point I stopped.
I realized I would need to learn how to better tune the model and handle the outliers.
I realized I would need to learn how to better tune the model and handle the outliers.
Finally...
Finally...
Seasonality in time series can be found in other industries such as retail, construction, economy, etc. In future anytime I come across data indexed in time order I'm sure my thoughts will be to instinctually consider applying time series modeling.
Seasonality in time series can be found in other industries such as retail, construction, economy, etc. In future anytime I come across data indexed in time order I'm sure my thoughts will be to instinctually consider applying time series modeling.
As with all projects I've worked on, there was a wish list of related things to try and investigate in the future:
As with all projects I've worked on, there was a wish list of related things to try and investigate in the future:
- Use TabPy (Python library for Tableau) to leverage machine learning in Tableau, however I believe this requires paid Tableau server licensing.
- Asset correlation in context of overall portfolio mix and diversification. Taking one's portfolio of investments to see how assets correlate with each other e.g. if not correlated then won't move in tandem with market down movements, which could mitigate risk in portfolio.
- Taking the above idea a step further, applying this to mutual funds along with time series to understand seasonality. Based on the portfolio makeup of the fund, be able to predict at next rebalancing what instruments will be changed and compare the result for accuracy.
- More viz and story telling in Tableau and/or Power BI
- Deeper understanding of the calculations and interpretations behind time series e.g. autocorrelation factor, multiplicative seasonality, uncertainty, etc.
Ackowledgements
Kudos to Pushpendra Sharma for inspiring me to try time series and guiding me through some basics!
We have been teammates through many projects in our York University's certificate in Big Data Analytics. Really smart and overall great guy to work with!