Fama and french 3 factors in R
786 views
May 16, 2024
In this video we explain how to construct Fama and French 3 Factors i.e. the market factor, size factor (SMB) and value factor (HML). Download the code file https://payhip.com/b/n3uNs Website: thedatahall.com As an Amazon Associate, I earn from qualifying purchases.
View Video Transcript
0:00
Welcome to the Data Hall YouTube channel
0:02
In this video, we are going to talk about how do we construct the Fama and French three-factor models
0:09
So we are going to talk about there are three factors in Fama and French model, that is the market premium factor, the Smb and the HML
0:19
In our previous video, we discussed how to construct these factors in Stata
0:23
And we also talked about the theoretical aspect of these videos, these factors
0:29
And in this video we are going to talk about how do we construct these factors in R
0:33
So we have over here the outline that we are going to cover. We will first load the library
0:39
These are different sections within our R script. So we define the date range, right
0:48
So here's the date range that we have. Do remember that we have given extensive comments before each line explaining what that specific code would do
0:59
similarly, then we would have preparing stock info data. Again, we do have extensive discussion on what file do you need to download from the CRSP and
1:11
Compostad data because this specific script is designed for CRSP and Compostad data but because we are explaining each concept as we move forward you can customize this R script for any market that you want to do
1:31
But we would also provide the dummy files. These dummy files would help you understand this R script
1:38
But these dummy files would not contain the original CRSP or computer data because of the copyright issues
1:45
We would just provide the dummy random data that we have generated
1:49
But the name of the fields, the name of the files would be exactly the same as we would have in the CRSP and CompuStat
1:57
As I was explaining, we explain each line of code and then we define what are these variables within CompuStat and what different values of these variable would mean CompuStat
2:10
right. So we have done this extensive commenting within this R script. Then we would prepare the
2:20
delisting information because there are stocks that would be delisted and we would have to adjust
2:26
stock return for delisting stocks. We would prepare the monthly stock return file, then adjust
2:33
our returns to the delisted stock returns, calculate the excess return, prepare the Compute Straton
2:40
file and link the CRSP and CompuStat that are using the CompuStat CRSP Compustad Merch file Merge table then we are going to create the size sorting use the market cap for size
2:58
sorting then calculate the book to market ratio we are going to calculate we are going to
3:04
construct the size and value portfolios calculate the portfolio return and lastly what
3:08
we are going to do is we are going to compare the factors that we have constructed with
3:16
the ones that are there on the Kenneth Farmer website and we are going to see how close
3:25
how much correlated are factors are the factors that we have constructed to the ones that are
3:32
available on the Kenneth Farmer website. So what I'm going to do is I'm going to pause this video
3:38
because this script would take a couple of minutes to execute around four to five minutes
3:44
So what I'm going to do is I'm going to pause this video
3:49
If you want to download this R script along with the dummy data, you can check the link given in the description
3:56
And once this file had been executed, I would resume the video
4:01
So we have created the SMV and HML factor So we now have these two variables in our dataset One is called My SMB and this is the one that I have created And then we have this SMB variable this SMB column
4:19
This is the data that had came from the Kenneth Farmer website
4:25
We also have my HML and HML. This is the one that I have created and this is the one that I have downloaded from the
4:31
Kenneth Farmer website. So what I'm going to do is I'm going to execute
4:36
And let's see how close we are. So our R square for SMB is 98%
4:44
So that means it explains 98% of variation within the SMB that we have downloaded from the Kenneth Farmer website using R SMB
4:58
And the coefficient is 9.99. Similarly, we can look at the correlation that would also be within the 99.99 range
5:10
For HML, we have 95% R square and the coefficient is 0.96
5:20
So that is pretty close to the one that we have downloaded from the Kenneth Farmer website
5:26
Now, I hope this video was useful. Do subscribe to this channel and do hit the bell icon
5:32
Thank you
#Computer Science
#Engineering & Technology
#Investing
#Programming