Fama-Macbeth回归:EAP.fama_macbeth
Fama-Macbeth回归是实证资产定价中最为常用方法之一。它的主要用途是验证因子对资产收益率是否产生系统性影响。与投资组合分析不同的是,Fama-Macbeth回归可以在同时控制多个因子对资产收益率的影响下,考察特定因子对资产收益率产生系统性影响,具体体现在因子是否存在显著的风险溢价(risk premium)。
Fama-Macbeth回归分为两步:
1. 估计资产承担风险大小(beta值)。通过对资产收益率的时间序列分析,得到资产承担的风险水平。
2. 估计风险溢价时间序列以及统计检验。通过在每个时点的资产收益率对得到的beta值进行截面回归,得到因子在每个时刻的风险溢价。对每个时刻的风险溢价进行平均,并检验均值是否显著异于0。
本文根据Bail et al.的著作Empirical Asset Pricing编写相关程序,投资组合分析的模块是EAP.fama_macbeth,下面将对该模块进行详细介绍。本文的Package已发布于Github:
Github: GitHub - whyecofiliter/EAP: empirical asset pricing
fama_macbeth
This module is designed for Fama_Macbeth regression(1976).
Fama-Macbeth Regression follows two steps:
Specify the model and take cross-sectional regression.
Take the time-series average of regression coefficient
For more details, please read Empirical Asset Pricing: The Cross Section of Stock Returns. Bali, Engle, Murray, 2016.
class Fama_macbeth_regress():
Package Needed: numpy, statsmodels, scipy, prettytable.
def __init__(self, sample):
input :
sample : data for analysis. The structure of the sample :
The first column is dependent variable/ test portfolio return.
The second to the last-1 columns are independent variable/ factor loadings.
The last column is the time label.
def divide_by_time(self, sample):
This function group the sample by time.
input :
sample : The data for analysis in the __init__ function.
output :
groups_by_time : The sample grouped by time.
def cross_sectional_regress(self, add_constant=True):
This function conducts the first step of Fama-Macebth Regression Fama-Macbeth, that taking the cross-sectional regression for each period.
input :
add_constant : whether add intercept when take the cross-sectional regression
output :
parameters : The regression coefficient/factor risk premium, whose rows are the group coefficient and columns are regression variable.
tvalue : t value for the coefficient.
rsquare : The r-square.
adjrsq : The adjust r-square.
n : The sample quantity in each group.
def time_series_average(self, **kwargs):
This function conducts the second step of Fama-Macbeth regression, take the time series average of cross section regression.
def fit(self, **kwargs):
This function fits the model by running the time_series_average function.
Example
import numpy as np from fama_macbeth import Fama_macbeth_regress# construct sample year=np.ones((3000,1),dtype=int)*2020 for i in range(19):year=np.append(year,(2019-i)*np.ones((3000,1),dtype=int)) character=np.random.normal(0,1,(2,20*3000)) # print('Character:',character) ret=np.array([-0.5,-1]).dot(character)+np.random.normal(0,1,20*3000) sample=np.array([ret,character[0],character[1],year]).T # print('Sample:',sample) # print(sample.shape) model = Fama_macbeth_regress(sample) result = model.fit(add_constant=False) print(result) ========================================================================= para_average: [-0.501 -1.003] tvalue: [-111.857 -202.247] R: 0.5579113793318332 ADJ_R: 0.5576164569698131 sample number N: 3000.0
def summary_by_time(self):
This function summarize the cross-section regression result at each time.
Package needed: prettytable.
Example
# continue the previous code model.summary_by_time() ========================================================================== +--------+-----------------+----------+--------------+---------------+ | Year | Param | R Square | Adj R Square | Sample Number | +--------+-----------------+----------+--------------+---------------+ | 2001.0 | [-0.499 -0.990] | 0.53 | 0.53 | 3000 | | 2002.0 | [-0.524 -0.987] | 0.56 | 0.56 | 3000 | | 2003.0 | [-0.544 -1.015] | 0.58 | 0.58 | 3000 | | 2004.0 | [-0.474 -0.948] | 0.53 | 0.53 | 3000 | | 2005.0 | [-0.502 -1.007] | 0.57 | 0.57 | 3000 | | 2006.0 | [-0.497 -0.981] | 0.55 | 0.55 | 3000 | | 2007.0 | [-0.526 -1.020] | 0.57 | 0.57 | 3000 | | 2008.0 | [-0.476 -1.024] | 0.56 | 0.56 | 3000 | | 2009.0 | [-0.533 -1.011] | 0.57 | 0.57 | 3000 | | 2010.0 | [-0.493 -1.029] | 0.57 | 0.57 | 3000 | | 2011.0 | [-0.504 -0.975] | 0.55 | 0.55 | 3000 | | 2012.0 | [-0.508 -1.002] | 0.56 | 0.56 | 3000 | | 2013.0 | [-0.474 -1.015] | 0.56 | 0.56 | 3000 | | 2014.0 | [-0.503 -0.998] | 0.55 | 0.55 | 3000 | | 2015.0 | [-0.485 -1.034] | 0.55 | 0.55 | 3000 | | 2016.0 | [-0.514 -1.005] | 0.57 | 0.57 | 3000 | | 2017.0 | [-0.498 -1.016] | 0.58 | 0.58 | 3000 | | 2018.0 | [-0.475 -0.994] | 0.55 | 0.55 | 3000 | | 2019.0 | [-0.487 -0.974] | 0.54 | 0.54 | 3000 | | 2020.0 | [-0.511 -1.031] | 0.56 | 0.56 | 3000 | +--------+-----------------+----------+--------------+---------------+
def summary(self, charactername=None):
This function summarize the final result.
input :
charactername : The factors' name in the cross-section regression model.
Example
# continue the previous code model.summary() ================================================================================ +-----------------+---------------------+-----------+---------------+-----------+ | Param | Param Tvalue | Average R | Average adj R | Average n | +-----------------+---------------------+-----------+---------------+-----------+ | [-0.501 -1.003] | [-111.857 -202.247] | 0.558 | 0.558 | 3000.0 | +-----------------+---------------------+-----------+---------------+-----------+
Fama-Macbeth回归:EAP.fama_macbeth相关推荐
- python面板数据回归_Python中的Fama Macbeth回归(Pandas或Statsmodels)
编辑:新建库 已存在可通过以下命令安装的更新库:pip install finance-byu 新的库包括Fama Macbeth回归实现,速度得到了提高,并且更新了Regtable类.新的图书馆还包 ...
- 常见因子的Fama-Macbeth回归:EAP.fama_macbeth
本文根据Bail et al.的著作Empirical Asset Pricing编写相关程序,投资组合分析的模块是EAP.fama_macbeth,下面将对该模块进行详细介绍.本文的Package已 ...
- fama matlab源码_Matlab:计算Fama Macbeth方法的HAC(Newey West)标准误差
我正在尝试在Matlab中计算FAMA MacBeth斜率系数的Newey West t统计量.我应该在每个横截面回归中计算标准误差吗? for j=1:T .... Result=regstats2 ...
- 常见因子的Factor_mimicking_portfolio: EAP.fama_macbeth.Factor_mimicking_portfolio
实证资产定价(Empirical asset pricing)已经发布于Github. 包的具体用法(Documentation)博主将会陆续在CSDN中详细介绍. Github: GitHub - ...
- Fama-Macbeth回归图形化:EAP.fama_macbeth.Fama_macbeth_regress.plot()
实证资产定价(Empirical asset pricing)已经发布于Github和Pypi. 包的具体用法(Documentation)博主将会陆续在CSDN中详细介绍,也可以通过Pypi直接查看 ...
- 因子风险溢价——EAP.fama_macbeth.Factor_mimicking_portfolio
实证资产定价(Empirical asset pricing)已经发布于Github和Pypi. 包的具体用法(Documentation)博主将会陆续在CSDN中详细介绍,也可以通过Pypi直接查看 ...
- Factor_mimicking_portfolio(模仿因子的投资组合):EAP.fama_macbeth.Factor_mimicking_portfolio
实证资产定价(Empirical asset pricing)已经发布于Github. 包的具体用法(Documentation)博主将会陆续在CSDN中详细介绍. Github: GitHub - ...
- 另类数据:投资中的怪咖
指数基金一般是小白投资理财的首选,可是,你是否知道指数基金背后的构造逻辑呢? 都说投资时不懂不要投,相信当我们了解了其背后的构造逻辑后,能够更好地选择基金产品,也能更安心地赚钱! 本文就带大家来了解一 ...
- 使用python做FamaMacBeth回归
金融资产定价常常需要用到FamaMacBeth回归.我们用python写一个模板,可以直接将数据调成需要的格式,代入代码即可出结果.所要求的数据格式,可以从链接下载. https://download ...
最新文章
- reverse mapping checking getaddrinfo for bogon failed – POSSIBLE BREAK-IN ATTEMPT! 错误
- 对集合变量定义赋值_SpringBoot配置加载原理(自定义加载配置)
- OpenGL 坐标变换
- 幼儿园小班上计算机课 作业内容是手口一致,小班幼儿手口不能一致的点数怎么办...
- 牛客小白月赛9 A签到(乘法逆元)
- Oracle 实用技巧
- leetcode hot 3-4
- 蓝桥杯2021国赛太原理工大学获得14枚奖牌
- php原生判断,JavaScript
- 项目管理深入理解03--质量管理
- 【feign源码】流程分析
- 【免疫优化物流选址】基于MATLAB的免疫优化算法在物流配送中心选址中的应用仿真
- 【软件】一个好用的QQ截图工具(百度云免费下载链接)
- WPS vbe6ex.olb 不能加载
- 【LeetCode学习计划】《算法-入门-C++》第13天 位运算
- element 日期选择器el-date-picker 月份/日期范围控制
- 基于全景相机的深度学习综述
- mysql查询雇员地址和电话_数据库的查询(结合YGGL.sql)
- Windows - 关于网络唤醒设置的说明
- awk打印除某列之外的所有列
热门文章
- Open edX数据结构Mysql edxapp
- Mina State machine状态机讲解
- 管你 JDK 还是 Linux,我 Netty 稳坐钓鱼台
- Linux中 vi、删除和退出 简单操作
- LeetCode 254. Factor Combinations(因式分解)
- ‘access denied (“java.io.FilePermission“...... “IKAnalyzer.cfg.xml“ “read“(elasticsearch很容易踩到的坑)
- Graph Convolutional Neural Networks for Web-Scale Recommender Systems(用于Web级推荐系统的图形卷积神经网络)
- 有机能量棒行业调研报告 - 市场现状分析与发展前景预测
- 星星之火-39: 什么是LTE物理层“时频”资源以及与物理层信道帧结构、物理层信道的关系?
- 用python编程小程序制作_Python编写四人24小时值班表生成小程序【简单粗暴】