将Fama-French因子转换为季度而非月度收益的方式

huangapple go评论99阅读模式
英文:

Way of turning Fama-French factors into quarterly in stead of monthly returns

问题

我正在尝试创建季度的Fama French因子。我使用getFamaFrenchFactors包下载了月度因子数据,但我不知道如何将它们转换为季度数据点。

我尝试过使用cumsum对它们进行累加,但在最后创建了非常大的因子。以下是我的代码:

  1. import getFamaFrenchFactors as gff
  2. df_ff3_monthly = gff.famaFrench3Factor(frequency='m')
  3. df_ff3_monthly['date_ff_factors'] = pd.to_datetime(df_ff3_monthly['date_ff_factors'])
  4. df_ff3_monthly = df_ff3_monthly[df_ff3_monthly['date_ff_factors'] > '2020-12-31']
  5. df_ff3_monthly.set_index('date_ff_factors', inplace=True)
  6. df_ff3_quarterly = df_ff3_monthly.resample('Q').sum().cumsum()
  7. df_ff3_quarterly
英文:

I am trying to create quarterly Fama French factors. I used the getFamaFrenchFactors package to download the factors monthly, but I have no idea how I can turn them into quarterly data points.

I tried to cumsum them, but it created very large factors at the end. This is my code:

  1. import getFamaFrenchFactors as gff
  2. df_ff3_monthly = gff.famaFrench3Factor(frequency='m')
  3. df_ff3_monthly['date_ff_factors'] = pd.to_datetime(df_ff3_monthly['date_ff_factors'])
  4. df_ff3_monthly = df_ff3_monthly[df_ff3_monthly['date_ff_factors'] > '31-12-2020']
  5. df_ff3_monthly.set_index('date_ff_factors', inplace=True)
  6. df_ff3_quarterly = df_ff3_monthly.resample('Q').sum().cumsum()
  7. df_ff3_quarterly

答案1

得分: 1

你可以计算累积收益率,然后转换为季度数据:

  1. df_quarterly = df_ff3_monthly.add(1).cumprod().resample("Q").last().pct_change()
  2. #Out[]:
  3. # Mkt-RF SMB HML RF
  4. #date_ff_factors
  5. #2021-03-31 NaN NaN NaN NaN
  6. #2021-06-30 0.081282 -0.018005 -0.022328 0.000000
  7. #2021-09-30 -0.003373 -0.037145 0.030646 0.000000
  8. #2021-12-31 0.082518 -0.052192 0.022916 0.000100
  9. #2022-03-31 -0.056030 -0.053894 0.141307 0.000100
  10. #2022-06-30 -0.173744 -0.011717 0.081960 0.001000
  11. #2022-09-30 -0.044194 0.033851 -0.037546 0.004607
  12. #2022-12-31 0.055603 -0.039705 0.109870 0.008524
  13. #2023-03-31 0.065063 0.003491 -0.133761 0.010537
  14. #2023-06-30 0.006100 -0.033400 -0.000300 0.003500
英文:

You can calculate the cumulative returns, then back to quarterly:

  1. df_quarterly = df_ff3_monthly.add(1).cumprod().resample("Q").last().pct_change()
  2. #Out[]:
  3. # Mkt-RF SMB HML RF
  4. #date_ff_factors
  5. #2021-03-31 NaN NaN NaN NaN
  6. #2021-06-30 0.081282 -0.018005 -0.022328 0.000000
  7. #2021-09-30 -0.003373 -0.037145 0.030646 0.000000
  8. #2021-12-31 0.082518 -0.052192 0.022916 0.000100
  9. #2022-03-31 -0.056030 -0.053894 0.141307 0.000100
  10. #2022-06-30 -0.173744 -0.011717 0.081960 0.001000
  11. #2022-09-30 -0.044194 0.033851 -0.037546 0.004607
  12. #2022-12-31 0.055603 -0.039705 0.109870 0.008524
  13. #2023-03-31 0.065063 0.003491 -0.133761 0.010537
  14. #2023-06-30 0.006100 -0.033400 -0.000300 0.003500

huangapple
  • 本文由 发表于 2023年6月15日 03:58:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76477139.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定