So in this lecture, we will look at another example of how to use Varma in Python.
This time we're going to use a data set that is a bit more complicated to work with.
This data set falls into the field of econometrics, which is probably the most common application of
vector auto regression in this case.
The prevailing wisdom tells us that there should be some temporal correlation between different time
series.
So again, we'll start by updating stats models and then putting the same libraries we did before.
The next step is to download the data now, one kind of interesting thing about this data set is that
it's pretty common to see in classes on econometrics, but for some reason, statisticians never split
their data into train and test and never evaluate their models on out of sample data.
So they tend to generate forecasts in the future, which you cannot even check with the Give and Time
series.
I'm not sure why this is, but that tends to be how statisticians do things for us.
We will check our forecasts and get a true sense of how accurate our predictions really are.
OK, so the next step is to read in our data file using to read Excel.
Note that this is an Excel spreadsheet, not a ESV.
The next step is to call the FDA ahead to see what our data looks like.
OK, so we've got a bunch of time series, but it's not clear what anything is since this is not a class
about economics.
We're not going to really worry too much about the meaning behind this data.
But you're encouraged to study economics on your own if that's what interests you.
It really is a different topic.
So it won't be of much use.
At the same time, if you've taken my finance course, you should have some intuition for the data will
be using.
So that's helpful, but not necessary.
Also, notice that the date is not in a format we typically use.
In this case.
We have the year followed by the quarter with a colon in between.
Note that the second number is not in months.
It goes one, two, three, four and then back to one.
So these are quarter's.
The next step is to write a function to pass the date column as before, the goal is to use the appli
function, which will map this function onto each row.
So inside the function, we're going to start by splitting the data by the colon.
So this gives us the year in the quarter as strings.
Now, what we would like to do is convert the quarter into a month.
I encourage you to go through this equation on your own.
But basically we want a function that will map one to January two to April three to July and four to
October.
So one goes to one, two goes to four, three goes to seven and four goes to ten.
In other words, it's a linear equation.
The intuition here is that the output should go up by three and the offset is one since January is encoded
as one.
OK, so this equation will give us the month.
The next step is to put this into a string along with the year.
The final step is to convert this into a daytime object using the strip time function.
The next step is to call appli passing in the function we just made.
The next step is to call DFG head again to see that our new column has been created successfully.
OK, so you can see that we now have a dead column where the months go up by three as expected.
The next step is to set the date column as the index for the data frame will also drop these unnecessary
columns.
We don't need any more.
The next step is to set the frequency of our index, which is in quarter's.
The next step is to call the FDA had again to check the format of our data frame.
So you can see now that the old columns are gone and we have a new date index.
OK, so the next step is to look at our data for this example, we'll be looking at GDP and something
called the term spread.
I'll explain what term spread means very shortly.
But GDP stands for gross domestic product.
The technical definition is that it's the total market value of the goods and services produced within
a country within a specific time period.
In this case, three months.
Basically, it's a measure of a country's economic health.
So this column is stored as GDP C ninety six.
OK, so notice that this column has a very strong trend, in other words, it's non stationary.
So using what we learned about Arima, we know that we should difference this column before applying
any kind of model.
In practice, we're going to take the log difference, which is the same thing we do with stock prices.
So this should be unsurprising.
We'll call this GDP growth.
The next step is to compute the term spread.
Now, this one is a bit more complex.
To understand this, you should be familiar with fixed rate investments like Treasury bills or whatever
they have in your country.
So if you go to your bank's website and look up fixed rate investments you can buy, that would be the
equivalent of this.
OK, so what is spread?
The spread is the difference between a long term investment and a short term investment.
In this case, a 10 year investment and the three month investment.
So, again, if you go to your bank's website and look up the fixed rate investments, you should notice
this pattern.
The pattern is that short term investments usually have lower interest rates than long term investments.
This makes sense because you should be rewarded for giving up your money for longer periods of time.
Now, the difference between these two rates fluctuates over time.
So sometimes you'll see that the long term investment offers a much higher rate, but sometimes you'll
see that they are nearly the same.
Now, again, I don't want to get into economics, but this is important for people who care about things
like interest rates for us.
The interesting part is that these two time series may be related.
The next step will be to plot the term spread.
OK, so notice that it's not quite stationary, but there isn't any upward or downward trend, so we
might be justified in leaving this as is notice that there seems to be some cyclical pattern, although
it's not as strong as something like a sine wave.
So at this point, since we now have a good understanding of this data and we've seen what it looks
like, this is a good time to stop in the next lecture.
We'll continue with the usual steps of fitting the model, making the forecast and so forth.