As a common topic in factor investing, I wish to implement the well-known Fama-French regressions on several stocks (+2000 IDs).
In a deep sense, factor regressions tell how the right hand (returns) variable is formed, from expectations of the left hand variable (factors). Since these factors are common across all the securities, it is inefficient to duplicate the factors for each stock at t.
My question is about efficiency and data structure. I have seen many tutorials explaining Fama-French regressions for a given stock return, but so far the regressions on several stocks (or portfolios) remain unclear for me. Maybe I am just missing something.
Let me illustrate my question. I created the following DataFrame.
In this table you can see, that the three factors (Mkt-Rf, SMB, and HML) are constant at given time across all ids. As opposed to the stock-level returns, which depend on the id and t. Since I have a broad universe, I believe there is a faster way to implement the regressions instead of copying the factors each time, creating lots of duplicates.
I am using Python or Stata to run the regressions. Doing simple OLS regressions take a lot of time. Maybe should I use two different datasets? But how.
Any "best" practice or advice would be great.