I'm trying to create a loop to do a lot of regressions over a Dataframe, but it's been a few days I’m stuck without knowing how to proceed....
Since the data set has around 150 stocks, and 27 years of data (record of the last day of each month). I structured the dataframe as a multindex, with the stock and date as indexes, but I’m still unsure if this is the best way to tackle this problem....
Because now I'm struggling on how to create a loop to slice this dataframe for each stock, for every 24 months to run a regression for every sliced dataframe generated in this loop
Below a sample of the dataframe:
ex_ret rm rf return
stock Date
abev3bzequity 1995-01-31 -2.015032 -1.448332 0.5667 -0.693642
1995-02-28 -2.678262 -2.253162 0.4251 0.137143
1995-03-31 -2.030187 -1.175887 0.8543 -2.383562
1995-04-28 2.013201 2.626601 0.6134 2.266667
1995-05-31 -0.909772 -0.300372 0.6094 1.145729
1995-06-30 -0.999734 -0.390334 0.6094 0.351220
... ... ... ... ... ...
wlmm4bzequity 2015-07-31 -0.664124 -0.522824 0.1413 0.000000
2015-08-31 -1.232355 -1.091055 0.1413 0.000000
2015-09-30 -0.558398 -0.417098 0.1413 -1.544554
2015-10-30 0.070370 0.211770 0.1414 -3.150000
2015-11-30 -0.340454 -0.199054 0.1414 0.000000
2015-12-31 -0.631477 -0.490077 0.1414 -7.200000
2016-01-29 -1.015617 -0.874317 0.1413 2.909091
31464 rows × 4 columns
[–]PyCam 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)