I am going to show you how to do stock price forecasting in a quick and reliable and significantly accurate way, so today we are going to dive into PayPal Inc stock. I am going to take five years of data[2016-2020] and show you how we are going forecast it so without further delay let us jump on it.
Log residual will help us navigate where PayPal stock price will continue its fluctuations over the next months if only if the systematic risk is stable. Anything can happen in the stock market in near future, Mr. Market mood is never predicable, however our job is to read market and Mr. Market is there to serve us, and not become its slave
Install and load those packages and pull data from Yahoo Finance. Identify the class you are working with, what type of data are we pulling? The class will tell us quickly that it is
When we have XTS data set that we are working with XTS object, that means we have the data column and index filed which contain dates in it. It is a little bit different than data frame data set. For this analysis purpose I am going only to analyze adjusted prices. You are free to work with (OHLC), open, high, low, and close or even only with volume.
##  "xts" "zoo"
Next step is to look at ACF an PACF.
ACF is an (complete) auto-correlation function which gives us values of auto-correlation of any series with its lagged values. We plot these values along with the confidence band and tada! We have an ACF plot. In simple terms, it describes how well the present value of the series is related with its past values. A time series can have components like trend, seasonality, cyclic and residual. ACF considers all these components while finding correlations hence it’s a ‘complete auto-correlation plot’.
PACF is a partial auto-correlation function. Basically, instead of finding correlations of present with lags like ACF, it finds correlation of the residuals (which remains after removing the effects which are already explained by the earlier lag(s)) with the next lag value hence ‘partial’ and not ‘complete’ as we remove already found variations before we find the next correlation. So, if there is any hidden information in the residual which can be modeled by the next lag, we might get a good correlation and we will keep that next lag as a feature while modeling. Remember while modeling we do not want to keep too many features which are correlated as that can create multicollinearity issues. Hence we need to retain only the relevant features.
Hlavac, Marek. 2018. stargazer: Well-Formatted Regression and Summary Statistics Tables (version 5.2.2). https://CRAN.R-project.org/package=stargazer.
Hyndman, Rob, George Athanasopoulos, Christoph Bergmeir, Gabriel Caceres, Leanne Chhay, Mitchell O’Hara-Wild, Fotios Petropoulos, Slava Razbash, Earo Wang, and Farah Yasmeen. 2020. forecast: Forecasting Functions for Time Series and Linear Models (version 8.12). https://CRAN.R-project.org/package=forecast.
Kleiber, Christian, and Achim Zeileis. 2020. AER: Applied Econometrics with R (version 1.2-9). https://CRAN.R-project.org/package=AER.
Pfaff, Bernhard. 2016. urca: Unit Root and Cointegration Tests for Time Series Data (version 1.3-0). https://CRAN.R-project.org/package=urca.
Ryan, Jeffrey A., and Joshua M. Ulrich. 2020. quantmod: Quantitative Financial Modelling Framework (version 0.4.17). https://CRAN.R-project.org/package=quantmod.
Wickham, Hadley, and Jennifer Bryan. 2019. readxl: Read Excel Files (version 1.3.1). https://CRAN.R-project.org/package=readxl.
Wickham, Hadley, and Dana Seidel. 2020. scales: Scale Functions for Visualization (version 1.1.1). https://CRAN.R-project.org/package=scales.
Zeileis, Achim. 2019. dynlm: Dynamic Linear Regression (version 0.3-6). https://CRAN.R-project.org/package=dynlm.
STOCK ANALYSIS IN R