3.2 分析师推荐 • 分析师的金手指?
最后更新于:2022-04-01 21:52:26
# 3.2 分析师推荐 • 分析师的金手指?
> 在我们的观点中,分析师对股票的评级以及EPS的估计,更多的是对该之股票过去一段时间表现的总结,并没有明确的预测未来的能力。鉴于分析师估计的延迟特点,在我们的策略中我们将分析师估计作为反向指标使用。粗略的说,在固定的期限内,我们买入分析师调低预期的股票,卖出分析师调高预期的股票。
本策略的参数如下:
+ 起始日期: 2011年1月1日
+ 结束日期: 2015年3月19日
+ 股票池: 沪深300
+ 业绩基准: 沪深300
+ 起始资金: 100000元
+ 调仓周期: 3个月
本策略使用的主要数据API有:
这里我们使用了来自于第三方朝阳永续的数据API(需要在数据商城中购买)
+ `CGRDReportGGGet` 获取朝阳永续分析师一致评级
+ `CESTReportGGGet` 获取朝阳永续分析师一致预期
[朝阳永续分析师分析数据相关链接](https://api.wmcloud.com/docs/pages/viewpage.action?pageId=2392750)
```py
import pandas as pd
start = datetime(2011,1, 1) # 回测起始时间
end = datetime(2015, 3, 19) # 回测结束时间
benchmark = 'HS300' # 策略参考标准
universe = set_universe('HS300') # 股票池
#universe = ['600000.XSHG', '000001.XSHE']
capital_base = 100000 # 起始资金
commission = Commission(0.0,0.0)
longest_history = 1
def CGRDwithBatch(universe, batch, startDate, endDate):
res = pd.DataFrame()
totalLength = len(universe)
count = 0
while totalLength > batch:
tmp = DataAPI.GG.CGRDReportGGGet(secID = universe[count * batch : (count + 1) * batch], BeginPubDate = startDate, EndPubDate = endDate)
count += 1
totalLength -= batch
res = res.append(tmp)
tmp = DataAPI.GG.CGRDReportGGGet(secID = universe[(count * batch):], BeginPubDate = startDate, EndPubDate = endDate)
res = res.append(tmp)
return res
def CESTwithBatch(universe, batch, startDate, endDate):
res = pd.DataFrame()
totalLength = len(universe)
count = 0
while totalLength > batch:
tmp = DataAPI.GG.CESTReportGGGet(secID = universe[count * batch : (count + 1) * batch], BeginPubDate = startDate, EndPubDate = endDate)
count += 1
totalLength -= batch
res = res.append(tmp)
tmp = DataAPI.GG.CGRDReportGGGet(secID = universe[(count * batch):], BeginPubDate = startDate, EndPubDate = endDate)
res = res.append(tmp)
return res
def MktEqudwithBatch(universe, batch, startDate, endDate):
res = pd.DataFrame()
totalLength = len(universe)
count = 0
while totalLength > batch:
tmp = DataAPI.MktEqudGet(secID = universe[count * batch : (count + 1) * batch], beginDate = startDate, endDate = endDate)
count += 1
totalLength -= batch
res = res.append(tmp)
tmp = DataAPI.MktEqudGet(secID = universe[count * batch : (count + 1) * batch], beginDate = startDate, endDate = endDate)
res = res.append(tmp)
return res
def regressionTesting(universe, startDate, endDate):
import statsmodels.api as sm
res1 = CGRDwithBatch(universe, 50, startDate, endDate).sort('publishDate')
res2 = CESTwithBatch(universe, 50, startDate, endDate).sort('publishDate')
res1 = res1[res1.RatingType == 1]
res2 = res2[res2.PnetprofitType == 1]
# got expRating change
lastRating = res1.groupby('secID').last()
firstRating = res1.groupby('secID').first()
lastRating['previousRating'] = firstRating.Rating
lastRating['chg_exp'] = lastRating.Rating / firstRating.Rating - 1.0
lowerP = lastRating['chg_exp'].quantile(0.05)
highP = lastRating['chg_exp'].quantile(0.95)
lastRating = lastRating[(lastRating['chg_exp']>lowerP) & (lastRating['chg_exp']lowerP) & (lastEps['chg_eps']
';