Recently, I am doing my dissertation that covers asset pricing theory. The empirical test of Fama 3 factors model is an important part of this dissertation. Please let me review the fama model.

Fama 3 factors model is $r-R_f=α+β_m(K_m−R_f)+\beta_s⋅SMB+\beta_v⋅HML+e$

where $R_f$ is risk free return, ($K_m−R_f$) is premium return and $K_m$ is market return, SMB is the "Small Minus Big" market capitalization risk factor. HML is is the "High Minus Low" value premium risk factor.

Please let mt detail my question. I have over 500 stocks and their monthly return ,monthly market value and monthly book-to-market ratio (call it b/m). The time interval is from 01.2010 to 12.2015, then because the data is monthly so I have 60 periods. Those data is in one excel document.

its methodology and what I want to do is:

  • For all stocks at each period, compute the mean for market value.
  • Divide them into two groups (say big and small size) by comparing each stock with mean. If stock's market value greater than mean, put them into big size group. If small than mean, put them into small size group. Thus, for each period we have two groups, big and small group in terms of market value.
  • For each period, we compare all the stocks' b/m within each group, then furtherly divide them into 3 groups , named high b/m (top 30%) group, medium b/m (middle hierarchy from 30% to 70%) group and low b/m (bottom 30%) group. Namely, for each period, we finally divide 6 groups. They are S/L, S/M, S/H and B/L, B/M, B/H. For example, S/L group contains all stocks that are small market value and low b/m ratio simultaneously.

These 6 groups are just 6 portfolio. So for each period, we have 6 different portfolios.

So far this is my first stage. Then I have second stage:

  1. After we get 6 different portfolios at each period, we need to compute weighted average return for all stocks at each period.
  2. We need to compute the SMB and HML for each period.


Where S/L,S/M....B/L is the summation return of each group. Like S/L is the summation of each stock's return.

Finally, we got time series data, then can regress this series data, and figure out α and 3 $\beta$.

So, basically those are want I want to do.

Now I compute those manually although I use excel, this is really a huge amount of workload, so tired to do this. I am still in step 1 at first stage. Is anyone interesting in telling me how to achieve dividing stocks into portfolios by compute, and compute those data by compute?

People usually just download the data from French's website. But my goal is to check Fama model in Asian stock market, like Shanghai and Hong Kong. All answers welcome, really really crazy and tired to do this manually.

Anyway, thanks everyone in advanced.

  • $\begingroup$ I'm recently doing a similar project as yours. it is extremely helpful to read your ideas. I have a question based on your research data collecting. Do you mind if I ask how did you download all of your stock's historical data? further, get their monthly return ,monthly market value and monthly book-to-market ratio (call it b/m)? $\endgroup$
    – Mary
    Apr 4, 2020 at 17:20

2 Answers 2


First of all, it is not conceivable to do all that work by hand! You are crazy to have just thought it!

Second, if you want to repeat your work with different datasets, I suggest you to use R, since, once you have written a script, you can use it all the times you want. But, there's a 'but': you cannot think we are going to write some code for you (you should write our names on your dissertation as co-authors). You can ask here about theoretical problems you encounter, or you can post the section of your code that is not working and we would be happy to help you. In every kind of research you will have to conduct, you are going to analyze data, and the best way to do this is using softwares like R (I'm telling you that, sooner or later, you will have to learn to code some (even small) scripts). Once you begin, you will use it for everithing.

Given this, you can find plenty of YouTube tutorials, pdf guides, examples of scripts and communities (such as stack exchange ones) on the web ready to help you on your path to the dark side of statistical and econometrical analyses with any software you want (R, gretl, Stata, Eviews, or even more programming oriented as MATLAB or Python).

Your analysis seems quite simple (in the sense that you do not need strange packages or functions to compute your calculations) and you will discover by yourself how useful, powerful and not that difficult to learn R is.

  • $\begingroup$ Thank you Simmy, you are right. I just began in learning R two days ago. But so far I don't know the key words for a script that I can achieve that work, I am really vague what should I learn about R. You have any suggestions for some codes that I can google and learn for, or any detailed suggestions I can do for R. $\endgroup$ May 28, 2016 at 14:18
  • $\begingroup$ well. Before starting, read a good tutorial about R (I found one for you: cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf . Consult this page for more help: en.wikibooks.org/wiki/R_Programming ). Don't skip the tutorial step, otherwise you will do not understand how to apply the hints and suggestions from the online communities or web pages. After you read the tutorial, go ahead: First question to ask yourself (about your research): "is R able to read data from an excel file?" (again, I give you the answer: yes. next coment to how: ... $\endgroup$
    – simmy
    May 29, 2016 at 18:30
  • $\begingroup$ stackoverflow.com/questions/6099243/… ). Well, you have a lot of data on R now. Second question: "how can R compute the mean of something?" find the answer googling (for example) "mean in R". "wow, just using the function mean(...), but how can I repeat a mean automatically for every period I have?" now you remember about the cycles you learned during the R tutorial. And so on. I'm not kidding you, this what you should do. You can learn only by trial and error. $\endgroup$
    – simmy
    May 29, 2016 at 18:37
  • 1
    $\begingroup$ @Zabbkaosckey, also check out the swirl package. It is great for those that are new to R. $\endgroup$ Jun 1, 2016 at 1:04
  • 1
    $\begingroup$ Hi simmy and Joseph, I have download the data from other place. Although I dont solve this problem directly, now I am going very well in learning R, and have made big progress. Anyway, thank both of you. $\endgroup$ Jun 25, 2016 at 12:22

I've posted on my website R code that replicates the Fama-French factors (plus momentum) from scratch. It assumes you have access to WRDS but if you have your own data, you can begin using the code where ever you see fit. In your case, you'd want to start in the Construct Fama-French Factors section of my Main_Fama_French file and also look at the Form_CharSizePorts2 function in the Support_Functions file.

  • 3
    $\begingroup$ I don't really mind linking to your own website but could you please make your answer self-contained? $\endgroup$
    – Bob Jansen
    Mar 16, 2017 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.