Week 3 Time Series
docx
keyboard_arrow_up
School
University of South Florida *
*We aren’t endorsed by this school
Course
101
Subject
Statistics
Date
Jan 9, 2024
Type
docx
Pages
26
Uploaded by ssaintclair
Google Cloud – Time Series Modeling: What is a time series?
Introduction
What is a Time Series
Time Series Concepts
Time Series Modeling
Lab Objectives
What is a Time Series
What are some of the basic concepts in Time Series
How do we analyze Time Series data to predict future values from past values
Agenda
Concepts in Time Series
Time series terminology
AR – Auto regressive
MA – Moving Average
Putting it all together
ARIMA Model
No one can predict the future. However, there's a way to predict the future in certain data sets with greater accuracy; time series data. In this lesson, we will learn what is the time series and understand the basic concepts of time series modeling. We will also try to learn some basic terminology and then use some time-
tested, no pun intended, techniques to predict the future. We will first try to answer the question: What is a time series and why is it important
in finance? We will then discuss how to analyze a time series data set. What are the different terms used in time series analysis including ARIMA and how we can use it to make predictions? In this lesson, our goals are to understand what is a time series and what are some of the basic concepts in time series that we need to know about? Concepts in Time Series
What is a Time Series?
A time series is a series of data points indexed in time order.
Most commonly, a time series is a sequence of snapshots of a process taken at successive equally spaced points in time.
Thus, it is a sequence of discrete-time data.
Then we will learn about how to analyze time series data and build a model to predict a future value from past values. First, let's understand what a time series is. A time series is a series of data points indexed in time order. Most commonly a time series is a sequence of snapshots of a process taken at successive equally spaced points in time. Thus, it is a sequence of discrete time data. Examples of time
series are heights of ocean tides, counts of sunspots, and the daily closing value of the Dow Jones Industrial Average. Now, let's look at what the basic terminology that we use in analyzing time series data are. What is Stationary data?
“Stationary” means that the statistical structure of the series is independent of time.
First, we need to understand the concept known as stationarity. In time series data such as the chart to the right of us, US GDP data over the last 200 years. We see that it's summary statistics such as mean and variance change over time. This is because US GDP has expanded over time and an average in one 10-year period is not the same average a century later. We call such data non-stationary. So what is stationary data then? Any data such that these statistical structure of the series is independent of time is known to be stationary. In simple terms, it implies that its mean and standard deviation don't change over time. How do we know data is Stationary?
Plots
Summary Statistics
Statistical Tests
How can we find whether time series is stationary? One way to do that is simply by looking at the plot. As you can see in the chart here, it is non-stationary, meaning that it has a definite trend. Secondly, you can measure summary statistics such as average and standard deviation at various points of time in the data and check for obvious or significant differences. Third, you can look and do some statistical tests to check if the expectations of stationarity are met or have been violated. How to convert a Trendy data to “Stationary” data?
One way to Convert Trendy Data to Stationary Data is to Difference it or De-Mean It!
Suppose your data is trendy like the US GDP
chart on the screen, how do you make it stationary? Statistical time series methods and even modern machine learning methods benefit from a clearer signal in the data, which we obtained when we stationarize a time series. One way to
make non-stationary time series data stationary is by identifying and removing trends and removing seasonal effects.
An easy way to do it is to difference one time period from another. That is, we take the difference between two data points and plot it like we see on screen to the right. How does it look? It still looks like it has some trend or even higher averages over time. Let's try differencing it one more time. After differencing it once more, it appears to be stationary. If you want to confirm that the mean and variance of this series is not dependent on time, you can do a statistical test known as the augmented Dickey-Fuller test.
How to convert Trendy data to “Stationary” data?
After differencing it twice, this data now appears to be “stationary”.
You can double-check it with an Augmented Dickey-Fuller test*
Without going into details about how the test works, we will give you a hint on how to read the test output. If the test statistic of the test is greater than
a certain p-value, let's say 0.05, then the given time series is stationary. If you need more details, check out the two links on this slide.
Q; With the US GDP we saw that the data had an upward trend. We
took the first difference but were not able to eliminate the trend. Why do you think the data required a second differencing?
A: The data had an exponential component (increasing slope). This is very common with data where growth is compounded each year such as GDP and stock prices. Exponentially growing prices require a second differencing.
Next, let's look at why stationarity is important in a time series model. There are two reasons. Let's say we want to build a model in which averaging is used. What mean and standard deviation of your data will you use? If your data is non-
stationary, then you will choose the mean from the beginning or the middle or the end, they're all different. Hence, stationarity allows you to build a stable model that uses stable parameters that don't change over time. Why is Stationarity important in Time Series Modeling?
Stationarity allows preserving model stability, i.e. a model whose parameters and structure are stable over time.
Stationarity matters, because it provides a framework in which averaging (used in AR and MA processes), can be properly used to describe the time series behavior.
What are the other properties of time series data?
Most time series contain one or more of the following components:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
o
Trend
o
Seasonal
o
Cyclical
o
Irregular (or Residual)
In the air passenger traffic chart that we see to the right, we notice that there are some interesting components in time series data. The first component is called trend. A trend is a long-run increase or decrease in a time series. You can see that the chart on screen has a slight upward trend. Second, when data is affected by the time of the year, it is set to be seasonal. In this case, we can see that almost every year the chart tended to peak during the middle of the year and decrease slightly afterwards. This is most pronounced in retail sales such as snow shovels or lawnmowers. Snow shovels tend to sell well in fall and winter and then decline afterward. Third, is a cyclical component. A cyclical component is measured over a long time horizon, typically one year or longer. For example, sales at fast food chains may rise during recessions when consumers are more cost-conscious and then fall during recoveries This is tied to the business cycle. Finally, an irregular component. Irregular effects are the impacts of random events such as crashes, earthquakes, or sudden changes in the weather. By their very nature, these
effects are completely unpredictable. How do we change stock prices to be more stationary?
Stock prices are typically trending (up or down). But in any case, they have changing mean over time.
Hence we must difference stock prices to get daily, monthly or annual returns
to make them “stationary”
Putting it all together, we can see that
a time series is an amalgam of all these components. The definition of stationarity implies that the mean and
variance of a process remains stationary, that is they should not change over time. However, looking at a stock chart, we can tell that it is not stationary. Stock prices are typically trending up or down. But in this case, they have a rising average price over time. So how do we make it
stationary? One way to do that would
be the difference the stock prices to get daily, monthly, or annual returns, that should make them stationary as you can see on the bottom right.
Q: What is the difference between seasonality and cyclicality?
A: Seasonality refers to cycles that repeat on an annual basis. Cyclicality refers to cycles that can be longer than a year. Seasonality is common with goods or services
that are in greater demand at a particular time of year such as air conditioners or space heaters. Cyclicality refers to data that responds to longer term changes such as the business cycle.
AR – AUTOREGRESSIVE
Next, we are going to learn about how to analyze time series data. One way to do that is to exploit an inherent property of almost all time series data. That is, at any point in time, a data point is slightly or highly dependent on the previous value or values. Let's see what that means next. Now, let us look at autocorrelation which is an important property of almost all time series data. Time Series Terminology: Auto Correlation (AR)
A correlation of a variable with itself at different time periods in the past is known as
“Autocorrelation.”
How can we identify what value of lag we should use?
Unlike data that we use in linear regression, time series data occur at different times. One may wonder for time series has some relationship to previous versions of
itself. Correlation is a great way to measure this relationship. Before we run a linear regression, we can tell if two variables are related. We do this by calculating the correlation coefficient between them.
In linear regression, the observations are paired so there is just one way to compute the classical correlation coefficient. This correlation is known as the Pearson correlation coefficient named after the statistician Karl Pearson. The same idea applies to time series, a series can correlate with itself. You may have seen the movie called The Truman Show starring Jim Carrey. In this movie, he is the star of an
around-the-clock reality television show but he doesn't know it. In one classic scene, he sits in his car and observes all the events that occur around him. He notices that after several minutes, all the activities repeat themselves. The same cars drive, the same people biking, the same people talking. This is an example of a
time series correlating with itself. How does this work with a set of training data? Let's do the following experiment. Suppose we have the return of apple for six months. We would have about a 125 data points. We will form two series from
these. We form the first series by excluding the last five points, we'll call this X. We formed the second series by excluding the first five points, we'll call this Y. That is, we make X by taking the first 120 data points. We make Y by taking the last 120 data points. We call this lagging. For computing the five-day autocorrelation, we must exclude the first five points of one series. Remember, to correlate, we always have to have the same number of points. When we calculate a five-day autocorrelation using 125 days of data, we have 125 minus 5 or 120 total pairs. We then proceed to compute the correlation just to see these were entirely different series. We may wonder though, why not try an eight-
day autocorrelation? Here, we form our X by taking the first 117 points, we form our
Y by taking the last 117 points, then we correlate these. We come to realize that there are many different autocorrelations we can calculate. We can calculate the one-day autocorrelation, two-day auto, and three-day and so on, all the way up to a number of days that slightly smaller than the number of training points you have. Practically speaking, let's calculate the autocorrelation of daily SPY returns from lag 0 to lag 10. This is real data. You can see from the graph that there is a correlation of about 30 percent for a seven-day lag. We can even say that the series has a zero correlation. Why would we do that? We would emphasize that the correlation of a series with itself is one. We can then draw a plot of this autocorrelations. This is known as the ACF chart as you can see on the slide. In the last slide, we discussed autocorrelation. Correlation has no direction. When we say the correlation between X and Y, it is the same as the correlation between Y and X. Regression is however different. When we run a regression, there is a specific direction. Why regress on X? This differs from the regression of X on Y. Time Series Terminology: Auto Regression (AR)
An AR process is where autoregression occurs. Our goal is to find the “correct” time lag that best captures the “order” of such an AR process. This is not a one-step procedure but is an Iterative process.
In regression, direction matters. In ARIMA modeling, we will start by using an order of lag to regress. We can gain insight from our autocorrelation plot. We can get a sense of lag that if we get a sense of the autocorrelation, an AR process is where auto regression occurs. Our goal is to find the correct time lag that best captures the order of such an AR process. This is not a one-step procedure but it's an iterative process. It's not very clear, isn't it? Auto Regressive (AR) process
Here is how an AR process with a time period lag of 1 looks like.
Let's look at a specific example. Here's a sample time
series with the time period of lag 1 to the right of the
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
screen. We don't know what lag means yet, but the next step will make that clear. The variable here on the y-axis is what we are trying to model. The x-axis as usual is a time period which is what we will expect in a time series. Here, we show you six charts of the same chart previously. The first chart on the top left shows you each value of Y shown plotted against the value of Y one period previously. Similarly, the second chart shows Y against the Y values two periods prior and so on. Notice how tightly packed Y is to Y values one time period ago on the top left corner. Auto Correlation with lags
This tight correlation starts to slowly disperse as we move along the right and down to the lower bottom. In the final chart at the bottom right, we see that there is a lot of dispersion. This means that the first chart shows a high correlation of Y to Y values one period prior and that later periods don't have such a high correlation. This means that this time series was generated by an auto regressive process of lag 1. Wow, that wasn't so hard, wasn't it? Let's look at some more examples. Understanding Lags
Here are two more examples. The chart on the left represents a time series with lag equals 1 and the chart on the right represents one with lag equals 2. Notice that you
can't tell much from looking at the charts themselves. But you have to do something similar to what we did earlier that is correlation to Y values of lag 1, lag 2, etc., in order to know what the lag in the chart is going to be. Knowing the lag tells us that we can use prior values to predict future values. What else can we use to predict future values?
Q: Please choose the pair that correctly completes this statement:
Autocorrelation can be shown visually with a ________ and also by the ___________.
Autocorrelation can be shown visually with a
scatter plot
and also by the
correlation.
Yes, when you look at a scatter plot of the original data versus lagged data, the data points will be in a tightly packed trend if there is a high correlation between data and its lagged values.
MA – Moving Average
Now, let's look at the next way. We can predict future values of y as the average of the past few observed data points. Let's dive into it some more.
Understanding an MA process
Moving Average (MA) models do not take the previous y values as inputs, but rather take the previous error terms. How do we get error terms if we don’t predict?
We will attempt to predict the next y value based on a moving average (MA) –
that’s how we get error terms: how wrong our moving average was compared
to the actual value. But there can be more than one error term since there can be many moving averages…
How can we identify what number of Error terms we should use?
Here is another way to look at a time series, moving average models. These models do not take the previous y values as inputs, but rather take the previous error terms. But how do we get error terms if we don't predict? Good question, we will attempt to predict y values based on a moving average, MA. That's how we get error terms, how wrong are moving average was compared to the actual value. But there can be more than one error term, but how can we identify what number of error term should we use?
Here are two examples, the chart on the left represents a time series with one error term and the chart on the right represents one with two error terms. Notice that there is no noticeable difference from looking at the blue lines in the chart themselves, but look closely and you will see that the green dotted lines look different. This is where the difference is noticeable since as more y values are created by the MA process the error terms become more impactful and changes the latter parts of the chart. This is what makes a moving average model different.
Now, let's look at putting it all together into one model or what we call the ARMA model. How does a combined model look like?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
As we have seen previously, autoregressive AR models are those that use data from
previous time points to predict the next time point. These are very similar to previous regression models except as input, we will take some previous outcome. We must select some value p for the amount of lag v believed to be useful
predicting future values. Moving average or MA models as opposed to autoregressive or AR models do not take the previous outputs or values as inputs, but instead take the previous error terms. We will attempt to predict the next value based on the overall average and how incorrect our previous predictions were. We must select some value q for the number of previous error terms we must consider. This is how we combine them
to form what we call an ARMA model to predict future values.
Q: Both AR and MA models use previous data to predict the next value of our variable. How are they different?
A: MA uses lagged values of the error terms and AR uses lagged values of the data itself. In this way we are using not only the lagged values of the data but also lagged values of unexpected changes or errors.
The Complete ARIMA Model
Now there's one more trick we can add to the ARMA model to make it more accurate in its predictions, that's called an ARIMA model with an extra I in the middle. What does it signify?
ARIMA Model
Let’s go one step further and try to add another term to the ARMA model – it’s called ARIMA.
What does the “I” stand for?
“I” stands for Integrated: we are combining AR and MA techniques into a single integrated model: ARIMA.
“I” helps to “stationarize” the data.
The I stands for integrated, we are combining ARMA techniques into a single integrated model, hence, it is called ARIMA. What is the I needed for? Remember the step in the beginning where we had to stationarize the data before modeling? The I helps with that, let's see more about I next.
ARIMA Model
In an ARIMA model, there will be three parameters that will be needed.
In an ARIMA model, there will be three parameters that will be needed. The p parameter indicates how many prior periods we are taking into consideration for explained autocorrelation. The q parameter indicates how many prior time periods we are considering for observing sudden trend changes. The additional d parameter
signifies the difference d where we are now predicting the difference between one prior period and the new period rather than predicting the new periods value itself. So this is important because it helps us d trend or data and approach stationarity. Remember,
d =1 may cause stationarity for a data set, which is not stationary before we build a
model, while d= 2 may capture exponential movements in our time series, but it's not frequently used.
What would a typical ARIMA Model look like?
There are three questions to address in the ARIMA model. The first item is the I, how
many differences if any are needed to make the data stationary? Let's assume the data is already stationary. The second term is the AR term, how many lags do we include for autoregression part of the equation in this case one? The third item is the MA term, how many lags do we include in the moving average part of the equation in this case two? We take d differences, we take p lags of AR, we take q lags of MA and putting them together, our model is ARIMA pdq. We see that d is typically 0 but could be 1. We also realized that p can be 0 or 1 or 2 or higher. We also realize that q can be 0 or 1 or 2 or higher. That's more than a dozen combinations.
Evaluating our ARIMA Model
In addition, there are a few key tactics we can explore:
o
Plotting our residuals
If we do not observe a pattern in our residual error terms, we can stop iterating
o
Ljung-Box Test
We can mathematically test the above assumption using the Ljung-Box test
This is how we can get a variety of models from a single time series. We can add many more variations to the above by including the following seasonality or SARIMA, AR, FIMA or SARIMAX and you can add your own variations here. It should
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
be clear by now that selecting model parameters for an ARIMA model is an iterative exercise, hence evaluating each model with is unique set of pdq parameters is key. Choosing useful pdq values and adding seasonal effects is almost entirely a context driven endeavor. In addition, there are a few key tactics we can explore. One, plotting our residuals, as you can see in the model on the left and the chart on the right. If we do not observe a pattern in our residual error terms we can stop iterating. In this instance, the model indeed seems good since the residuals on the right don't have a clear pattern. Second, Ljung-Box Test, we can mathematically test the above assumption using the Ljung-Box Test.
Q: An ARIMA (1,2,3) model includes:
A: One lagged data value, three lagged lagged error terms and is differenced twice.
ARIMA compared to linear regression
Agenda
How does ARIMA compare to linear regression?
How you can get a variety of models from just a single series?
How to choose ARIMA parameters for your trading model?
Learning Objectives
Understand how ARIMA differs from linear regression
Learn how to apply a variety of models to just a single series
Understand how to choose the parameters and features of your ARIMA trading model
Concepts in Time Series
What is Stationary data?
“Stationary” means that the statistical structure of the series is independent of time.
In this section will look at how a financial time series is modeled statistically. Our focus will be on autoregressive integrated moving average models, or ARIMA models. These models describe how each
successive observation in a series is related to previous observations, which is quite different from aggression, where you're relating a dependent variable two independent variables or factors. First, we will look at how ARIMA models are used to
forecast time series, and how this method compares to linear regression. In this section, you will learn how ARIMA differs
from linear regression, and how you can apply a variety of models to a single data series. You will also learn how to choose parameters and features for your ARIMA model, and what the consequences of those choices are. Earlier we introduced stationarity. Let's review, a time series is a
random process. It can be summarized by a measure of central tendency, typically we use the mean. It can be summarized by a measure of how uncertain we are about the location of that center,
typically we use the standard deviation. The mean and the standard deviation summarize data very nicely. For example, if data is normally distributed, then the mean and standard deviation summarize everything there is to know about the data. Problem we have with financial data is that the mean may change over time, or the standard deviation may change over time. Either of these violations means one thing, the series is not stationary. For example, this graph is upward trending and has an increasing mean, this is not stationary. Previously you learn that you could take the first difference of a series, and this new different series may be stationary. Let's begin by distinguishing ARIMA from linear regression. Before
this course, you've likely done several types of linear regression.
In linear regression you regress a response variable on one or more dependent variables. For example, you might have done a regression in your statistics class where you looked at children's heights and weights. One observation contains one child's height and weight. Note that the order of the observations is not important, in the end you get a coefficient for each dependent variable. In the height versus weight example, you get one slope coefficient which is the rate of increase of height per unit weight, plus an intercept term.
ARIMA vs Linear Regression
Big Picture
Regression: Model y~x
Model y based on the distribution of x
ARIMA: y~previous values of y
Model y based on previous values of y
Let's compare that to ARIMA. Recall that ARMA is an acronym for autoregressive integrated moving average. Let's break down the first part. The autoregressive term or AR tells you that this is indeed a regression, but the A means auto, the series has regressed on itself. Is that cheating? No, because the observations occur over time. You would like to know if, by using past observations, you can somehow predict what the future values will be. We could not do this for a linear regression because the observations do not have any time sequence associated with them. You can think of them all occurring at the same time, but you can do this for a time series model by allowing some number of lags of a variable to help you predict what the next value will be. For example, if you run an AR 1 model, then you will use the one lagged or immediately prior value to predict the next. The MA part tells you there is a moving average component as you saw in a previous section. These are the unobserved errors terms.
ARIMA vs Linear Regression
What do they have in common?
Require stationarity
Linear
Correlation between response & dependent variables
Methods to estimate coefficients
Statistical tests to assess the quality
Let's talk about what both models have in common. First, both models require the data to be stationary. In linear regression you have to use stationery variables, if the variables are non-
stationary then you violate the assumptions of the linear regression model. You would need to look
for related variables that preserve the stationarity condition. In ARIMA modeling, you also have to use stationery variables. If the variables are non-stationary, then you have to take differences until the data is stationary. Now you see why stationarity is so important. Second, both models are linear as opposed to having exponents or non-linear terms.
This makes the results more intuitive, and the estimation easier computationally. Third, both models want a high correlation between the response variable and the dependent variable. Consider the first
case of simple linear regression. This is where you have only one dependent variable, you can compute the correlation coefficient between the response and the predictor variables. In multiple linear regression, you want to compute the correlation of each pair, where a pair consists of the response variable, and each dependent variable. In ARIMA models you use the autocorrelation graph to detect where there are high correlations. Forth, both use similar methods of estimating the coefficients. The slope and the Intercept constitute the coefficients. Finally, both use similar statistical
test to evaluate the quality of fit.
ARIMA vs Linear Regression
What do they do differently?
There is no natural ordering to the observations in linear regression
Linear regression uses two different variables
Linear regression emphasizes one variable depends on the other.
There is sequential ordering to the observations in time series
ARIMA uses the same variable, with lagged values of the response
ARIMA does not need to make this choice
Now let's move on to what the models do differently first. First, there is no natural ordering to the observations in the linear regression. This data may be observational in nature, or experimental in nature, but they are not time series. In ARIMA models the variables we use or time series, associated with each data point is an observation time. These times have a natural ordering. They may be evenly spaced out such as every day or every month, or they may be unevenly spaced such as every time a trade occurs. At some parts of the trading day there is a lot more trading volume than other parts, so the data frequency varies. Note that some people mistakenly put time series and linear regressions, they should really be running time series models instead. There are other time series models besides ARIMA. Second, linear regression uses two different variables, one for the response and one for the predictor. ARIMA models can use a single variable. Remember this is a time series, so out of one variable comes dozens of others. Simply by lagging the time series one time point, two time points, three time points, or so. Third, linear regression prioritises the variables. One of the variables serves as the dependent variable, we call this the response variable, or we simply call it y. It depends on an independent variable we call this variable the predictor variable, or we simply call it x. If we are controlling an experiment, then
clear the order is apparent. However, if we have economic or financial data, we are not running a controlled experiment, either variable can serve as the response. ARIMA models subvert this issue
entirely, because we simply model how the past values of the series helped to predict its future values.
How can you get a variety of models from just a single series?
Let's turn to how you can get a variety of models from just a single time series.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
There are three parameters, their inputs to the ARIMA model. The first item is the I, how many differences, if any are needed to make the data stationary? We see that D is typically one but it could
be zero, in which case the I would disappear and you would have an ARMA model. We take D differences. The second item is the AR, how many lags do we include the auto-regressive part of the
model? P can be 0 or 1 or 2 or higher, we take P lags with AR.
The third item is the MA, how many lags do we include in the moving average part of the model? Q can also be 0 or 1 or 2 or higher, you take Q lags of MA. Our model is ARIMA pdq, by using different combinations of p, d and q you can get a variety of models from a single time series.
The chart on the left represents a time series with one error term. So Q equals 1, and the chart on the right represents one with two error terms or Q equals 2. Notice that there's no discernible difference from looking at the blue lines and the chart themselves, but look closely and you'll see that
the green dotted lines look different. This is where the difference is noticeable since as more y values are created by the ma process. The error terms become more impactful and changes the later part of the chart. This is what makes a moving average model different.
How to choose ARIMA parameters for your trading model
Time Series Terminology: Auto Correlation (ARIMA)
Choose:
o
The data
The most difficult step
Often have too much data rather than too little
Need to choose the frequency of data that you need for your model
o
D
If d=0, you are working with levels
Prices
Yields
If d=1, you are working with differences
Returns and log returns
Yield changes
o
P and q
These have to be integers!
…but you can choose to set them to zero
o
The form of ARIMA
Variations
Fractional estimation
Seasonality
o
The estimation method
Maximum Likelihood
Method of moments
Non-parametric methods
Simulation
o
The best model
May run multiple form of model with different estimation parameters
May use different software
Choose model with best quality of fit
Let's turn to how you choose your ARIMA parameters when designing a trading model. When you run a ARIMA models you have six key decisions to make, choose the Data: d, p, and q, type of ARIMA model, estimation method and finally choose the best model overall. First, you must decide how much data to use. Through experience I've often found that this is the most difficult step in the entire process. When you use financial data you're likely to have too much data rather than too little data. You may collect trade data at a daily frequency, may even find trade data at intraday frequencies, like every hour or every minute, and you may even find data that is based on quotes, that is bid prices, bid sizes, ask prices, ask sizes. Remember that all of these have associated observation times. Second, you must decide which value of d to use, when d is zero you use the data as is, when d is one you take the first differences. For example, suppose you work with equity prices, if you decide to work with prices then d is equal to zero, if you work with log returns then you effectively choose d to be equal to one. Once you have the form of the data, the analysis takes different paths. Suppose instead you work with bond yields, if you decide to work with yields then d is equal to zero, if you work with yield changes then you effectively choose d to be one. The general term for prices or yields is levels, the general term for returns or yield changes is differences. If you use levels you will get one set of results, if you use differences you will get a different set of results. Neither model may be incorrect, however, you may be more justified in using one model than the other. Third, you must select the values of p and q. Recall that p is the number of AR lags and Q is the number of MA lags. These values have to be integers but remember you can also choose them to be zero. Fourth, you choose the type of ARIMA model. When you dig deeper you will find that there are several varieties. Most likely you are running this on software, you will find a number of ARIMA models, some do fractional estimation, some adds seasonality. Fifth, you choose the method of estimation. Unlike the parameters in the linear regression models, the parameters in ARIMA models are more difficult to estimate. The method of estimation is key, you might use maximum likelihood, quasi maximum likelihood, generalized method of
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
moments, non-parametric methods and estimation, and even estimation by simulation. Often you may think the software does this for you, but you really have to identify what the software uses as default. If you don't explicitly choose an estimation method, the software will do so, but that is still a choice you make. Based on your choices you now have a set of estimated parameters coefficients. You're six choices determine these values. You may certainly run more than one model, and so choose among candidate models based on some model criteria. Once you have selected the best model, then refer to the values the software has provided. These values will be your tools for making predictions. All of your decision-making leads you to a set of weights. If you had a positive value for p, then you get values for the weighting of the lagged observations. These are the coefficients of the AR terms. If you had a positive value for q, you get the weightings of the lagged unobserved or error terms. So the sixth and final choice you make is easy to state, you choose the values of the parameters.
Time Series Terminology: Auto Correlation
Choose:
The data
o
Most important
o
Tradeoff between timeliness and relevance
o
How to divide for training and testing
o
Relevance to prediction goal
D, P, and Q
o
Software generally guides this choice
o
Can run the model on levels and differences
The form of ARIMA
o
Traditional model may oversimplify the analysis
o
A more complex model may overcomplicate the analysis
The estimation method
o
Maximum Likelihood
o
Method of moments
o
Non-parametric methods
o
Simulation
The best model
o
May run multiple form of model with different estimation parameters
o
May use different software
o
Choose model with best quality of fit
We countered a half a dozen choices. Some of these six choices involves sub choices. But let's focus on how much discretion you have in making these decisions. The first
choice in some ways is the most important. You can think of the choice of data to use as a combination of art and science. To be sure there are statistical criteria you can use like cross-validation that can tell you how best to curve a data set into a training group and a testing group.
Will you have great discretion into how you curve the data history. Should you use the last six months of data or should you find a time period that is more similar to now which hasn't occurred for a number of years? Which back testing criteria can
you use to decide how to divide the data into training and testing? Should you penalize the errors in testing much greater than the errors in training? Should you include data on days that are not representative of the overall population? For example before major holidays, financial markets tend to close early or should you include these as half days? None of these choices are wrong but you will discover that some choices work much better than others. Why? Because you find the data you selected to be more relevant to what you are trying to predict. When you make the second and third decisions you are deciding on the best values of P, D and Q. Fortunately, there are automated systems that can guide you to what
is optimal. So you will find that this choice is more of a science. You may even decide to run a model on levels and a model on differences. You will find that choice
of ARIMA form is another tough decision that is part art and part science. Here's what my experience and expertise in selecting the specific form of ARIMA is. A traditional ARIMA model may oversimplify the problem. On the other hand, a more complicated seasonality model may over-complicate the problem. The fifth decision is the choice of estimation method. I usually defer to software. Most time Siri software has an accurate and robust implementation of these optimization methods. You may not realize which optimization to use. This happens because often software are running ARIMA models uses suitable defaults. If you dig deeper you will find options to choose different estimation models. Also you have the ability to tweak the models. Yet there is still some art involved because you may have to decide which methods tend to work best on which problems. Also you may notice a problem with starting values. Typically, these optimization methods need guesses or starting values. The optimizer then starts at those points and searches the space to minimize the discrepancies. Many algorithms have a common weakness. If they start at a certain point they may get trapped into a local minimum. This gives a solution but it is not the best one. In fact it may be far from the optimal one. Therefore, when you choose a method of estimation you have to choose how to run the model. You may need to run it with many different starting values. You can then see if these lead to the same final results.
Often they will not. But you can certainly use the next decision to resolve that problem. The sixth decision is mostly science. You may run multiple forms the model
with different estimation methods and even different software. In the end each model gives you a quality score.We discussed these in the previous section. You simply choose the model with the optimal value. Recall that you may have more than one way to evaluate the quality of fit. In cases where one metric favors one model and a different metric favors a different model, then you have discretion.
Sensitivity of Trading Strategy
Sensitivity of Trading Strategy
What is the mean?
o
Each of your 6 model decisions can affect the mean
o
Choice of data can shift mean up or down
How far does it typically deviate from the mean and how long does it take to get back?
o
Long-term average, standard deviation and current value tell ou where you are in relative terms and also…
o
Expected time to revert to mean
What is the impact of your choice of p and q?
o
P and q give the form of the model
o
High p means market has high memory
o
Low p means the past has a low impact on the future
How much explanatory power is in the model?
o
If p and q are zero your model is a random walk!
o
If your model is best fit by AR91) then there is structure
o
Trading strategy is sensitive to model estimates which depend on your choices.
Let's think about all the different decisions you can make in running ARIMA models. If you make a slightly different decision, you can get different results. In the
end, these differences affect your forecast. This forecast affect your trading. How? When you run ARIMA models, you are modeling a mean-reverting series. Recall that you need a stationary series to create a model. Stationary series have a constant mean. ARIMA is a way of describing how you can expect past-observed and unobserved values to depart from the mean, but eventually they return. ARIMA represents a series with noise but one that returns to its long-term average. You made six key decisions, each of the decisions can affect that average. Suppose you work with equity prices. Suppose you choose your data exclusively from bull markets. If your choice of data excluded periods of bearish markets, then perhaps your mean is too high. You can choose the p and the q. This gives you the form of the model. You estimated the slopes and intercept accordingly. This gives you the value of the estimates. You can see that using the values of the coefficients. You can determine the long-term average, you can also determine how far the series typically deviates from the mean.
You can observe the current value so the model can tell you where you are in relative terms between the average and the expected deviation. This is good news. This tells you how long you can expect to wait to get back to the mean. This helps you trade. This can determine how long you should hold a trade. This can help
you set realistic profit objectives. This can help you set stop losses. You chose a p and a q. This gives you the form of the model. You estimated the slopes and intercept accordingly. This gives the value of the estimates.
Let's think about the values of the AR coefficients. Recall that these AR coefficients are less than one. A high value for the AR coefficient is 80 percent. This high coefficient tells you that the market has a long-lasting memory. If the first AR term had a coefficient of 80 percent, then its value is highly influential in determining the next value. This could indicate significant market impact. Suppose you trade a small
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
cap stock. You run an AR model on the returns and you get a high coefficient. This says that the market has a memory, the past influence is what comes next. Suppose you use trade in extremely liquid exchange-traded fund. You run an AR(1) model on the returns, you get a low coefficient. This says that the market is more resilient. The past doesn't influence what comes next. This could indicate very
little market impact.
The AR coefficients in particular are easy to interpret. They tell you how important the past is and waiting what comes next. Finally, the results of the model also tell you how much explanatory power there is in the model itself. What is your model best fit is in ARIMA(0,0)? Then you have a random walk. This tells you that the market is efficient. But what if your model is best fit by an AR(1)?Then there's structure. However your choices of data; p, d, q, and ARIMA form, estimation method and software affects the outcomes. Some combinations of these choices may show ARIMA(0,0) is better, others may show AR(1) is better. These two models result in two different trading strategies. Very different. We now see why trading is sensitive to model estimates. You make modeling choices throughout the process. These decisions affect parameter values. Parameter values describe the ebb and flow of the series, where it is expected to be, how far it deviates, and how long it takes to return. These averages, volatilities, and expected reversion time affect your trading. Different decisions create different perspectives about how you should trade, therein lies the sensitivity.
Time Series Practice Quiz
1.
Why is stationarity important in time series modeling?
a.
Preservation of model stability. A time series must be stationary in order to model it with itself (mean reversion) or with another time time
series (co-integration).
2.
Most time series contain one or more of the following components: trend, seasonal, cyclical, residual.
a.
True. A time series can include any of three systematic components, level, trend and seasonality, and one non-systematic component, noise
or residual variation.
i.
Level: the average value in the series
ii.
Trend: the increasing or decreasing value in the series
iii.
Seasonality: the repeating short-term cycle in the series
iv.
Residual Noise: the random variation in the series
3.
An Auto Regressive (AR) process involves finding which of the following?
a.
Time lag. An AR(p) auto regressive process is one in which the current value is based on a preceding value, p lags before. In an AR(1) process,
the current value of a process is a function of its value immediately prior.
4.
Moving Average models involve finding which of the following?
a.
Error terms. Moving average MA models uses past forecast error terms in a regression-like model.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
5.
You have an ARIMA model with a parameter p=1. What does this say about the model?
a.
Each term in the model is correlated ot one output prior. An ARIMA (p,d,q) is an auto regressive integrated moving average process in which the current output value is based on a preceding output value, p lags before. In an ARIMA (1,d,q) model the current value of a process is
a function of its value one time period prior.
Lab Intro: Forecasting Stock Prices Using ARIMA
In this lab, you will be creating a time series model. The goal is to predict stock prices of Apple, five days into the future using past values. The objectives in the lab are to teach you about the following. One, how to import data from GCS. Two, how to iteratively set up the parameters of a time series model. Three, how to forecast using that model. Four, how to evaluate the results.
Building an ARIMA Model for a Financial Dataset
Overview
In this lab, you will build an ARIMA model for AAPL stock closing prices using the statsmodels library in Python.
Objectives
In this lab, you learn to perform the following tasks:
Pull data from Google Cloud Storage into a Pandas dataframe
Learn how to prepare raw stock closing data for an ARIMA model
Apply the Dickey-Fuller test
Build an ARIMA model using the statsmodels library
Setup and requirements
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
1.
Sign in to Qwiklabs using an incognito window
.
2.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have
to start at the beginning.
3.
When ready, click Start lab
.
4.
Note your lab credentials (
Username
and Password
). You will use them to sign in to the Google Cloud Console.
5.
Click Open Google Console
.
6.
Click Use another account
and copy/paste credentials for this
lab into the prompts.
If you use other credentials, you'll receive errors or incur charges
.
7.
Accept the terms and skip the recovery resource page.
Note:
Do not click End Lab
unless you have finished the lab or want to restart it. This clears your work and removes the project.
Task 1. Launch AI Platform Notebooks
To launch AI Platform Notebooks:
1.
Click on the Navigation Menu
. Navigate to AI Platform
, then to Notebooks
.
2.
On the Notebook instances page, click New Notebook
.
3.
Select TensorFlow Enterprise
and choose the latest version of TensorFlow Enterprise 2.6 (with LTS) > Without GPUs
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
4.
In the pop-up, confirm the name of the deep learning VM, and then move to the bottom of the window and click Create
.
The new VM will take 2-3 minutes to start.
5.
Click Open JupyterLab
. A JupyterLab window opens in a new tab.
Task 2. Clone Course Repo within your AI Platform Notebooks Instance
To clone the training-data-analyst notebook in your JupyterLab instance:
1.
In JupyterLab, to open a new terminal, click the Terminal
icon.
2.
At the command-line prompt, run the following command:
git clone https://github.com/GoogleCloudPlatform/training-data-analyst
Copied!
content_copy
3.
To confirm that you have cloned the repository, double-click on the training-data-analyst directory and ensure that you can see its contents.
The files for all the Jupyter notebook-based labs throughout this course are available in this directory.
Task 3. ARIMA model for AAPL closing price
1.
In the notebook interface, navigate to training-data-analyst > courses > ai-for-finance > solution
and open arima_model.ipynb
.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
2.
Ensure you're using the Python 3 kernel by selecting Python 3
from the upper right corner of the notebook.
3.
In the notebook interface, click on Edit > Clear All Outputs
(click on Edit, then in the drop-down menu, select Clear All Outputs).
4.
Now read the narrative and execute each cell in turn.
End your lab
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Documents
Recommended textbooks for you

Glencoe Algebra 1, Student Edition, 9780079039897...
Algebra
ISBN:9780079039897
Author:Carter
Publisher:McGraw Hill

Linear Algebra: A Modern Introduction
Algebra
ISBN:9781285463247
Author:David Poole
Publisher:Cengage Learning

Recommended textbooks for you
- Glencoe Algebra 1, Student Edition, 9780079039897...AlgebraISBN:9780079039897Author:CarterPublisher:McGraw HillLinear Algebra: A Modern IntroductionAlgebraISBN:9781285463247Author:David PoolePublisher:Cengage Learning

Glencoe Algebra 1, Student Edition, 9780079039897...
Algebra
ISBN:9780079039897
Author:Carter
Publisher:McGraw Hill

Linear Algebra: A Modern Introduction
Algebra
ISBN:9781285463247
Author:David Poole
Publisher:Cengage Learning
