论文原文‘The regression is estimated for each firm on a rolling annual basis using historical monthly returns data from the CRSP database.We require at least 24 months of historical data and use up to 60 months of data in the estimation. Expected returns are computed using the estimated factor loadings and realized factor returns 1 year hence.’
- clear
- input str3 sic3 long permno int year byte month double(ret rm_rf r__rf)
- "399" 10000 1986 2 -.257143 .0713 .05508100000000001
- "399" 10000 1986 3 .365385 .0488 .041192000000000006
- "399" 10000 1986 4 -.098592 -.0131 .010939999999999995
- "399" 10000 1986 5 -.222656 .0462 .03129399999999998
- "399" 10000 1986 6 -.005025 .0103 .0028870000000000007
- "399" 10000 1986 7 -.080808 -.0645 -.07832800000000001
- "399" 10000 1986 8 -.615385 .0607 .018668999999999998
- "399" 10000 1986 9 -.057143 -.086 -.063571
- "399" 10000 1986 10 -.242424 .0466 .019176999999999996
- "399" 10000 1986 11 .06 .0117 -.010163000000000002
- "399" 10000 1986 12 -.377358 -.0327 -.039509
- "399" 10000 1987 1 -.212121 .1247 .11336499999999997
- "399" 10000 1987 2 0 .0439 .07031199999999997
- "399" 10000 1987 3 -.384615 .0164 .031582999999999986
- "399" 10000 1987 4 -.0625 -.0211 -.02210700000000001
- "399" 10000 1987 5 -.066667 .0011 -.003201
- "399" 10000 1987 6 . .0394 .016686999999999994
- "131" 10005 1986 2 -.333333 .0713 .05508099999999969
- "131" 10005 1986 3 .125 .0488 .041192000000000215
- "131" 10005 1986 4 .055556 -.0131 .010940000000000037
- "131" 10005 1986 5 0 .0462 .031294000000000044
- "131" 10005 1986 6 -.526316 .0103 .0028869999999999833
- "131" 10005 1986 7 -.555556 -.0645 -.07832800000000023
- "131" 10005 1986 8 .25 .0607 .018668999999999988
- "131" 10005 1986 9 .4 -.086 -.06357099999999982
- "131" 10005 1986 10 0 .0466 .01917699999999995
- "131" 10005 1986 11 -.142857 .0117 -.010162999999999978
- "131" 10005 1986 12 0 -.0327 -.03950899999999987
- "131" 10005 1987 1 .666667 .1247 .1133649999999998
- "131" 10005 1987 2 .1 .0439 .07031199999999994
- "131" 10005 1987 3 0 .0164 .03158300000000001
- "131" 10005 1987 4 0 -.0211 -.022107000000000047
- "131" 10005 1987 5 .454545 .0011 -.003201
- "131" 10005 1987 6 -.125 .0394 .016686999999999952
- "131" 10005 1987 7 .714286 .0385 .030522999999999793
- "131" 10005 1987 8 -.375 .0352 .009843999999999922
- "131" 10005 1987 9 -.266667 -.0259 -.020376000000000002
- "131" 10005 1987 10 -.181818 -.2324 -.2782479999999991
- "131" 10005 1987 11 0 -.0777 -.05435000000000002
- "131" 10005 1987 12 0 .0681 .022165
- "131" 10005 1988 1 .111111 .0421 .07449199999999978
- "131" 10005 1988 2 0 .0475 .055664999999999784
- "131" 10005 1988 3 0 -.0227 .03128999999999983
- "131" 10005 1988 4 -.2 .0056 .00941599999999995
- "131" 10005 1988 5 -.125 -.0029 -.022770999999999996
- "131" 10005 1988 6 0 .0479 .04276799999999986
- "131" 10005 1988 7 .285714 -.0125 -.004803000000000002
- "131" 10005 1988 8 0 -.0331 -.030900999999999942
- "131" 10005 1988 9 -.333333 .033 .010751000000000056
- "131" 10005 1988 10 0 .0115 -.01758100000000001
- "131" 10005 1988 11 0 -.0229 -.04218399999999993
- "131" 10005 1988 12 0 .0149 .012572
- "131" 10005 1989 1 0 .061 .05662400000000019
- "131" 10005 1989 2 0 -.0225 -.003112000000000007
- "131" 10005 1989 3 0 .0157 .011360000000000068
- "131" 10005 1989 4 -.166667 .0433 .022388999999999937
- "131" 10005 1989 5 0 .0335 .01715399999999993
- "131" 10005 1989 6 0 -.0135 -.014843999999999979
- "131" 10005 1989 7 0 .072 .024017000000000066
- "131" 10005 1989 8 -.2 .0144 .011225999999999924
- "131" 10005 1989 9 -.25 -.0076 -.0009680000000000044
- "131" 10005 1989 10 0 -.0367 -.05673600000000004
- "131" 10005 1989 11 .333333 .0103 -.012704999999999985
- "131" 10005 1989 12 0 .0116 -.01847500000000002
- "131" 10005 1990 1 0 -.0785 -.052107999999999766
- "131" 10005 1990 2 -.25 .0111 .009733999999999956
- "131" 10005 1990 3 0 .0183 .014915000000000001
- "131" 10005 1990 4 0 -.0336 -.03501599999999988
- "131" 10005 1990 5 0 .0842 .038873000000000005
- "131" 10005 1990 6 0 -.0109 -.0009410000000000061
- "131" 10005 1990 7 0 -.019 -.03253100000000005
- "131" 10005 1990 8 0 -.1015 -.11552000000000022
- "131" 10005 1990 9 .666667 -.0612 -.08646799999999985
- "131" 10005 1990 10 -.4 -.0192 -.06395499999999987
- "131" 10005 1990 11 0 .0635 .02976799999999989
- "131" 10005 1990 12 0 .0246 -.010526000000000008
- "131" 10005 1991 1 .666667 .0469 .07897499999999999
- "131" 10005 1991 2 0 .0719 .12909799999999952
- "131" 10005 1991 3 0 .0265 .07389300000000028
- "131" 10005 1991 4 0 -.0028 .02665700000000002
- "131" 10005 1991 5 0 .0365 .026667999999999897
- "131" 10005 1991 6 .6 -.0494 -.03597300000000006
- "131" 10005 1991 7 . .0424 .029280000000000077
- "374" 10006 1960 1 .005155 -.0698 -.042502000000000005
- "374" 10006 1960 2 .046154 .0117 .005578
- "374" 10006 1960 3 -.059553 -.0163 -.028376000000000002
- "374" 10006 1960 4 -.081794 -.0171 -.02163
- "374" 10006 1960 5 .048851 .0312 .022846000000000005
- "374" 10006 1960 6 .027778 .0208 .019208999999999997
- "374" 10006 1960 7 -.013514 -.0237 -.020898
- "374" 10006 1960 8 -.021918 .0301 .036248
- "374" 10006 1960 9 -.142045 -.0599 -.061124000000000005
- "374" 10006 1960 10 -.013245 -.0071 -.02543
- "374" 10006 1960 11 .003356 .0469 .04519399999999999
- "374" 10006 1960 12 .034014 .0471 .035895
- "374" 10006 1961 1 .322368 .062 .080148
- "374" 10006 1961 2 .014925 .0357 .058730000000000004
- "374" 10006 1961 3 .086849 .0289 .04788799999999999
- "374" 10006 1961 4 .022831 .0029 .0077870000000000005
- "374" 10006 1961 5 .078125 .024 .039771999999999995
- end
gpt生成了示例代码,但是好像不行,仅作参考。
- gen date1 = ym(year, month)
- format date1 %tm
- sort permno date1
- gen expected_return = .
- gen idiosyncratic_return = .
- gen window_length = .
- * 定义窗口
- local min_window = 24
- local max_window = 60
- bysort permno: gen id = _n // 为了便于引用行数
- foreach permno in permno {
- local num_obs = _N
- forvalues i = `max_window' / `num_obs' {
- if `i' > `max_window' continue
- local start = max(`i' - `max_window' + 1, 1)
- local end = `i'
- // 检查窗口长度是否满足最小要求
- if `end' - `start' + 1 >= `min_window' {
- // 进行回归
- quietly reg ret r__rf rm_rf [in `start'/`end']
-
- // 提取系数
- local alpha = _b[_cons]
- local betaM = _b[rm_rf]
- local betaIND = _b[r__rf]
- // 预测未来的回报
- local future_date = date1[`end'] + 12
- // 确保未来数据存在
- if !missing(rm_rf[`future_date']) {
- local expected_return = `alpha' + `betaM' * rm_rf[`future_date'] + `betaIND' * r__rf[`future_date']
-
- // 计算特质回报
- local idiosyncratic_return = r__rf[`future_date'] - `expected_return'
-
- // 存储结果
- replace expected_return = `expected_return' in `future_date'
- replace idiosyncratic_return = `idiosyncratic_return' in `future_date'
- replace window_length = `end' - `start' + 1 in `future_date'
- }
- }
- }
- }


雷达卡


京公网安备 11010802022788号







