FamaMacBeth在Python中的最新位置

在做Fama三因子回归的时候试图从Pandas下面调用FamaMacBeth,运行会提示不能从Pandas当中调用,原因是从Pandas 0.20版本之后fama_macbeth已经被转移了。

from pandas import fama_macbeth
ImportError: cannot import name 'fama_macbeth' from 'pandas'

将目前0.24.2版本的pandas中的全本内置函数输出:

import numpy as np
import pandas
import math
for i in range(math.ceil(len(dir(pandas))/10)):
    print(dir(pandas)[i*10:(i+1)*10-1])

输出结果中可以看到fama_macbeth已经不在列。

['Categorical', 'CategoricalDtype', 'CategoricalIndex', 'DataFrame', 'DateOffset', 'DatetimeIndex', 'DatetimeTZDtype', 'ExcelFile', 'ExcelWriter']
['Grouper', 'HDFStore', 'Index', 'IndexSlice', 'Int16Dtype', 'Int32Dtype', 'Int64Dtype', 'Int64Index', 'Int8Dtype']
['IntervalDtype', 'IntervalIndex', 'MultiIndex', 'NaT', 'Panel', 'Period', 'PeriodDtype', 'PeriodIndex', 'RangeIndex']
['SparseArray', 'SparseDataFrame', 'SparseDtype', 'SparseSeries', 'TimeGrouper', 'Timedelta', 'TimedeltaIndex', 'Timestamp', 'UInt16Dtype']
['UInt64Dtype', 'UInt64Index', 'UInt8Dtype', '__builtins__', '__cached__', '__doc__', '__docformat__', '__file__', '__git_version__']
['__name__', '__package__', '__path__', '__spec__', '__version__', '_hashtable', '_lib', '_libs', '_np_version_under1p13']
['_np_version_under1p15', '_np_version_under1p16', '_np_version_under1p17', '_tslib', '_version', 'api', 'array', 'arrays', 'bdate_range']
['concat', 'core', 'crosstab', 'cut', 'date_range', 'datetime', 'describe_option', 'errors', 'eval']
['get_dummies', 'get_option', 'infer_freq', 'interval_range', 'io', 'isna', 'isnull', 'lreshape', 'melt']
['merge_asof', 'merge_ordered', 'notna', 'notnull', 'np', 'offsets', 'option_context', 'options', 'pandas']
['pivot', 'pivot_table', 'plotting', 'qcut', 'read_clipboard', 'read_csv', 'read_excel', 'read_feather', 'read_fwf']
['read_hdf', 'read_html', 'read_json', 'read_msgpack', 'read_parquet', 'read_pickle', 'read_sas', 'read_sql', 'read_sql_query']
['read_stata', 'read_table', 'reset_option', 'set_eng_float_format', 'set_option', 'show_versions', 'test', 'testing', 'timedelta_range']
['to_msgpack', 'to_numeric', 'to_pickle', 'to_timedelta', 'tseries', 'unique', 'util', 'value_counts', 'wide_to_long']

Statsmodels

网上查询之后说FamaMacBeth被转移到了Statsmodels当中,但是运行之后发现依然找不到。

from statsmodels import fama_macbeth
ImportError: cannot import name 'fama_macbeth' from 'statsmodels' 
from statsmodels import FamaMacBeth
ImportError: cannot import name 'FamaMacBeth' from 'statsmodels'

同样将当前0.9.0版本的statsmodel内置函数全部输出:

['CacheWriteWarning', 'ConvergenceWarning', 'InvalidTestWarning', 'IterationLimitWarning', 'LooseVersion', 'PytestTester', '__builtins__', '__cached__', '__doc__']
['__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'compat', 'datasets']
['os', 'print_function', 'simplefilter', 'sys', 'test', 'tools', 'version']

linearmodels

最后,在linearmodels中找到了FamaMacBeth。

from linearmodels import FamaMacBeth
model=FamaMacBeth(y,x)
results=model.fit(cov_type="kernel",kernel="Parzen")

附上参考链接:https://bashtage.github.io/linearmodels/panel/models.html#linearmodels.panel.model.FamaMacBeth

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值