Thank you for joining me again.
And as we go on into this chapter now, it's finally time to get into the practical bit of creating
this really nice simple introductory momentum strategy.
We've been over the bits already where we realized that the inputs log Cairns is a better way of inputting
a feeding data into our function because it is a normalized way sort of uniform.
Make all the data in a uniform manner, says better.
For comparison purposes, for the sake of accuracy.
And generally, that's how we do things in the world of statistics.
And then we choose the time period we can choose one day or we can improve that model later on and do
multiple different time periods.
It doesn't have to be only one.
Then we do the Boolean logic when we tell the algorithm, when should you enter or leave a position
based on where you think the trend is going to go?
So enough of me talking, let us just just get started.
So before actually getting into it, if you haven't installed that, why finance?
In order to get the Yahoo data to a pet store, why finance?
And then we would do our inputs, create right under and then to import our libraries the first thing
we would import?
Well, it would be what we just installed.
Do we import?
Why finance us?
Why f we are importing Nampai?
Because we will do a bit of some calculations and where we would need to work with integers.
So that would be important.
Nampai, S and P and also pandas.
Import pandas as p d because we need to structure the data that we're bringing in.
So we are bringing all of this finance data pricing data in and we put it into a nice data frame structure.
That's what we're using pandas for.
And the last thing we import much plot level the p y plot as poultry.
This last bit would be in the second half really of the and the practical where we do a plot to show
the comparison of the different time periods.
Because if you remember one or two of the up here, one of the things we will be adjusting, the length
of time that we're looking at and it can be one day, but that when we can even do the multiple times
so that my plot, the rabbit is that we want to plot the different times to do a comparison, then we
get straight into the time momentum strategy function.
OK, we already know that we are using that log returns as the time series, and then we were going
to indicate the time period that we are looking back on.
At first, we will be using one day and then the logic, which would let us know if we should take a
short position.
But what are we going to be retaining?
We are retaining the cumulative sum, and the reason for this is that the cumulative sum is something
that is used to monitor the small shifts in the process, more so to calculate this.
It uses the cumulative sum of deviations from a target so that we are entering these.
These are like the inputs to the strategy and it is retaining this cumulative sum.
And this cumulative sum is not a finite point that we need to get to know.
This is actually what we will be using.
OK, so remember that we are retaining at the end of the strategy when it finished, when we finish
run that we are doing that.
So it's how it would help us to understand small shifts.
OK?
It's a really short strategy, so it's wouldn't take too long the f time series momentum.
Strategy.
Their parameters that would be needed for inputs would be a tense period.
In this case, I mentioned it would be one day and the shorts would be defaulted to false.
So we would not wear defaulted to not take a short position.
And it would only be when we're triggered in it right conditions.
Only then would we be able to take a short position.
OK, so I'm just going to do some documentation here to remind you that I remind myself that this is
the one day look back strategy because afterwards we were going to do one with a multiple time period
look back.
So this is just for the one day look back.
If shorts position is equal to Britain's darts rolling period, which in this case is set to one dot
mean, which is why we needed to import Nampai, then we need to dot map.
We call the map method to map and this is what we will be mapping.
Lambda X colon minus one of X is less than or equal to zero else.
One.
If you're not familiar with the lambda expression, that would be that is explained in Python guideline
chapter, which is optional.
But you can take a look at the syntax and the structure of the argument so you can understand what that
is.
Else?
You make sure you indentations line up position.
You actually copy this entire thing and paste it, just make sure the indentations are OK.
So this remains the same retained start rolling period darkening the map, and the only thing that we
need to change would be just change the minus one to zero.
And that is the fine performance
equals two position shift.
One should shift one multiplied by returns, and we are retaining that performance, of course.
But this at the end of the shot, she gives us the performance, which is that accumulated some Oh great,
I have a typo, it's lambda lumber.
Make sure you did not do that because, you know, I was wondering why the color changed.
Just so just run each cell and just to explain what this means.
Rolling period, we won the returns and this is still this means they're rolling some for this period
of time.
So we want they're rolling some, but just won the time, but it can be four five days.
So they're rolling some for that period of time that we define here.
And we're finding the mean of that.
So again, we reiterate we are taking the returns data and calling that rolling method on both for this
period of time.
So it's it's on a window to the our rolling some has a window size and this window size is the period
when you think about your window size when it comes when it's in.
But Trends in time series your window is that period of time that you're doing your rolling average
on.
So we are looking at the returns from that rolling time period.
That window off one and then doing the mean on that.
OK.
So yeah, it's the same thing on this line.
OK, so in the next video, we would learn how to pull the historical market data.