AI量化知识树

公募基金仓位模拟与优化

由ypyu创建,最终由small_q 被浏览 215 用户

基金仓位的爬取

首先通过爬虫爬取公募基金公布的仓位,我们以招商基金的沪深300指数增强基金为例(代码004190)获取该基金的2018年二季度公布的个股持仓比例,代码实现如下:

    import re
    import requests
    import json
    df1=pd.DataFrame()
    url = "http://fundf10.eastmoney.com/FundArchivesDatas.aspx?type=jjcc&code=004190&topline=10&year=&month=6&rt=0.6632225928306066"
    response = requests.request("GET", url)
    data = response.text
    ins_para = re.compile(">([0-9]{6})<")
    ins_list = ins_para.findall(data)
    instrument=[str(s)+'.SHA'  if s[0]=='6' else str(s)+'.SZA' for s in ins_list]
    percent_para = re.compile("<td class='tor'>([0-9]*.[0-9]*)%</td><td class='tor'>[0-9]*.[0-9]*</td><td class='tor'>[0-9]*.[0-9]*</td>")
    percent_list = percent_para.findall(data)
    percent=[float(s)/100 for s in percent_list]

基金绩效模拟

随后我们假设季度轮仓来模拟公募基金的业绩,在2018年3月31日按照爬取的个股持仓比例买入并持有到公告日6月30日,通过回测得到的模拟绩效如下图所示:

AI仓位优化

我们使用模板策略的因子,设置训练集为2010年至2015年,通过训练的模型预测每日基金持仓的股票排序,并进行定期轮换,得到优化调仓后的收益曲线如下图所示:

结果分析

基金模拟的业绩为-5.31%,与行情软件查询的2018年3月31日~6月30日期间的绩效基本一致。 此外可以看到通过AI在给定股票范围内进行定期调仓优化得到的模拟业绩为-2.88%,具有一定的增强能力。

策略如下:

https://i.bigquant.com/user/chad/lab/share/招商基金%2F招商基金指数增强.ipynb

标签

Python