One of the most popular applications of Time series analysis isn't finance, although this is not the
only application of Time series, it's one that I know a lot of you are thinking about now.
Unfortunately, a lot, of course, is out there.
Simply take the price of a stock and treat that like any other time series seems completely reasonable.
What's the difference between a one time series and another?
Well, in this course you're going to learn that there's actually a huge difference.
None of this is obvious at first, but I hope that throughout this course you will build your skill
to a level necessary to understand what I'm saying.
You might start this course with a naive perspective, but by the end of this course, this perspective
will mature.
If your logic right now is Lithium's plus stock price prediction equals profit, then I would consider
you as someone who falls into this naive category.
Now, don't consider this to be a bad thing, but a good thing.
You are going to get the most out of this course.
So this lecture is a Financial Times series primer.
There are certain operations and definitions you simply have to know about when you're dealing with
stock price data.
Now, although I've taught financial engineering elsewhere very in depth, you can think of this lecture
as like a summary of those concepts.
OK, so clearly the stock price over time is an example of a time series, it's continuous, valued,
and it can be thought of as discrete time.
For example, when you download stock price data from Yahoo!
Finance, you might get daily data or hourly data in regularly spaced intervals.
In more advanced courses.
You can think of stock prices as continuous time, although, as mentioned, that would be a separate
course.
Now, in practice, what we are interested in is not the stock price, but rather the stock return.
Let's think about the intuition behind this.
We learned earlier that when we talk about forecasting metrics, it's nice when they are a scale invariant.
If your guess for the price of a one million dollar house is off by one thousand.
That's not so bad.
But if your guess for the price of a five dollar coffee is off by five dollars, that's a pretty bad
yes.
So it's more natural to think in terms of percentages.
The percent change tells us how much money we've made or lost on a stock that we own.
We call this the stock return.
The equation is very simple.
And of course, you've seen this before.
It's the final price minus the initial price divided by the initial price.
Now, in practice, because we index our prices by time measured in periodic intervals, it's common
to consider the return for each of those periods also index by time.
So we say our privacy is equal to T minus T minus one, divided by T minus one.
Note that this is also equal to T, divided by T minus one, minus one.
And also note that we sometimes call this the net return, although I usually won't make this distinction.
So here's one modern reason why understanding returns is important, you see very often people considering
investment into crypto currencies, they think Bitcoin is expensive because one Bitcoin costs fifty
thousand dollars.
On the other hand, some random cryptocurrency only cost a few cents.
So they think that this random cryptocurrency is a good investment because it's quote unquote cheap.
Of course, this fact is irrelevant.
If you have one thousand dollars to spend, then you'll buy one fiftieth of a Bitcoin.
Or if you buy random coin, then you'll buy 10000 random coins, assuming each one costs 10 cents.
But owning ten thousand random coins doesn't give you more value than owning one fiftieth of a Bitcoin.
If random coin goes down to five cents, you've lost 50 percent of your wealth and the value of your
investment is now just five hundred dollars.
If Bitcoin goes up to one hundred thousand, then you double your wealth and the value of your investment
is now two thousand dollars.
So, as Albert Einstein said, everything is relative.
Now, you recall that a common time series transformation is to take the log of the data.
In fact, this is central to financial analysis.
The log of the price is simply called the log price.
Note that we typically use lowercase letters for the log variable in uppercase letters for the original.
Now, before we get to log returns, we're going to define another kind of return called the gross return.
The gross return is simply one plus the return from before.
So why is this useful?
Well, it's a convenient way to see how much our wealth has multiplied.
So, for example, if I invested one hundred dollars and I got back one hundred twenty dollars, then
my gross return is one point two.
In other words, my wealth was multiplied by one point two.
If I invested one hundred dollars and I lost twenty dollars, then I now have eighty dollars in my gross
return is zero point eight.
In other words, my wealth was multiplied by zero point eight.
So a gross return, less than one is a loss and a gross return.
Greater than one is a gain.
The log return is simply the log of the gross return.
So why do we take the log of the gross return and not the log of the net return?
Well, let's see why this is the most natural thing to do.
We can start by noticing that the net return can be negative.
If you lose twenty dollars on a one hundred dollar investment, then your net return is minus 20 percent.
And of course, you can't take the log of minus 20 percent.
Furthermore, you'll recognize that the log return corresponds to the log transformation where we had
one before taking the log.
So this provides some intuition behind why we had one and not some other random number.
Finally, notice how the log return is simply the difference in log prices.
This is very convenient, since in computers, adding and subtracting is much more efficient and numerically
stable than multiplying and dividing.
In fact, the first difference is a very important operation in Time series analysis.
We'll see it applied again and again in this course.
So it's kind of a happy coincidence that these financial concepts, such as taking the log and taking
differences, happened to also be critical operations in TIME series analysis.
OK, so in the next part of this lecture, we are going to take a quick look at what financial data
actually looks like.
The most common format for stock price data is open, high, low, close adjusted, close in volume.
Note again, how time goes along.
The rows and different attributes go along the columns.
So what are these attributes?
Well, recall that each row of data corresponds to a period in time.
For example, one day or one hour, the open price is the price.
At the beginning of the period, the closed price is the price.
At the end of the period, the high price is the maximum price for the period and the low price is the
minimum price for the period.
Volume is the number of trades that occurred during the period.
So if you've ever looked at a candlestick chart, you'll recognize these quantities.
These charts basically give you a picture of what happened in the market for that period.
We use the color red when the closed price is less than the open price and green when the closed price
is greater than the open price.
So what is adjusted, close adjusted closes a special column that accounts for stock splits and dividends
in the close price.
Note that the closed price is typically what is used for analysis, which is why there's no adjusted
open or adjusted low.
So basically, dividends are amounts that are paid in cash into your cash account.
This is money you earn, but it effectively makes the stock price less.
So the return you compute from the closed price is less if you do not account for the dividend payment.
The net return, which takes into account dividend payments, is shown here.
But note that we will not use this in the course since it just adds coding work without any benefit,
we would have to spend extra effort in finding the dividend payments, which typically do not come with
these data sets.
You could potentially compute them on your own, but again, that takes work.
Note that this equation makes sense because again, DFT, the dividend is money that you actually earn.
Now, some resources out there suggest using the adjusted clothes when computing the return, which
gives you an approximation to the true return.
I'll leave it for you as an exercise to check whether or not they are equal in practice.
If you're building a trading bot, it would be my preference to use the true values and actually accumulate
the dividends instead of using the adjusted clothes.
So the final component of the just the close is the stock split.
Now, I mentioned this for informational purposes, but note that it's not actually needed in our analysis
because all stock prices in our API will already be adjusted for stock splits.
Basically, the reason for stock splits is this.
Imagine that a share of a stock is one hundred thousand dollars.
This is too large for many people to afford and it's not possible to buy fractional shares.
So to ameliorate this problem, the stock will be split, for example, two for one split or a three
for one split.
This will result in the stock price going down by a factor of two for a two for one split or three for
a three for one split.
If you already own shares of the stock, you'll now own two or three times more so that the value of
what you own is the same.
So, as mentioned in this course, we will focus on the non adjusted close price, if you want to do
an exact analysis, you're always welcome to download dividend data separately using whatever API you
normally use.
The reason we want to use the noninterest to close prices, as you recall, the other columns are not
adjusted.
So if you want to do a multi-dimensional analysis, this is not possible using the adjusted close since
it's not on the same scale as the open, high and low values.