Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update-pandas for vresion 2.2.2 #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sunshe35
Copy link

@sunshe35 sunshe35 commented Jun 11, 2024

更新匹配pandas最新版2.2.2
主要内容如下:

  • 默认情况下,要指定group_keys=False,否则结果会多一个group level。但是部分场景又需要设置group_keys=True,所以对所有groupby都设置了group_keys参数,将来pandas升级到3.0也能适用。
grouby(group,group_keys=False).apply(func)
  • df.iteritems()已经弃用,变更为df.items()
  • get_forward_returns_columns()方法中,改进了 (年化)加权平均/标准差 计算逻辑,原来嵌套3层apply,现在只需要一层。
  • 月度类型由M变成 ME
  • pd.Int64Index([1, 2], name='group')已经弃用,变更为 pd.Index([1, 2],name='group', dtype='int64')
  • gitignore新增test?.py test?.ipynb 忽略文件,方便写测试代码。
  • 其他小细节。

@sunshe35
Copy link
Author

sunshe35 commented Jun 11, 2024

通过我的修改,使用pandas最新版2.2.2,官方demo可以成功运行。

# 载入函数库
import pandas as pd
import jqfactor_analyzer as ja

# 获取 jqdatasdk 授权,输入用户名、密码,申请地址:http://t.cn/EINDOxE
# 聚宽官网,使用方法参见:http://t.cn/EINcS4j
import jqdatasdk
jqdatasdk.auth('', '')

# 获取5日平均换手率因子2018-01-01到2018-12-31之间的数据(示例用从库中直接调取)
# 聚宽因子库数据获取方法在下方
from jqfactor_analyzer.sample import VOL5
factor_data = VOL5.iloc[:30,:30]


# 对因子进行分析
far = ja.analyze_factor(
    factor_data,  # factor_data 为因子值的 pandas.DataFrame
    quantiles=10,
    periods=(1, 10),
    industry='jq_l1',
    weight_method='avg',
    max_loss=0.1
)

print(far.ic)


# 生成统计图表
far.create_full_tear_sheet(
    demeaned=False, group_adjust=False, by_group=False,
    turnover_periods=None, avgretplot=(5, 15), std_bar=False
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant