/
HotSpot.py
125 lines (107 loc) · 2.64 KB
/
HotSpot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 05 15:03:08 2016
@author: Taplo
每日热点股票的信息收集
包括:
1)高转送
2)业绩预披露靠前的
3)限售股解禁
"""
import tushare as ts
import datetime as dt
import multiprocessing
#高转送股票信息
def HighShares(t=50):
df = ts.profit_data()
if len(df)<2:
return [u"高转送股票信息:",u"无!"]
else:
df=df.sort_values('shares',ascending=False)
return [u"高转送股票信息:",df[:t]]
#业绩预披露靠前
def ProfitExp():
year=dt.date.today().year
month=dt.date.today().month
if month>9:
season=4
elif month>6:
season=3
elif month>3:
season=2
else:
season=1
if season==1:
year=year-1
season=4
else:
season=season-1
dp=ts.forecast_data(year,season)
dp=dp.sort_values('range',ascending=False)
return [u"\n近期预披露靠前的结果:",dp[:30]]
'''#上期预披露结果
if season==1:
year=year-1
season=4
else:
season=season-1
dp=ts.forecast_data(year,season)
dp=dp.sort_values('range',ascending=False)
print u"\n上期预披露靠前的结果:"
print dp[:20]
'''
#限售股解禁
def XsgJj():
df=ts.xsg_data()
df['ratio']=df['ratio'].astype(float)
df=df.sort_values('ratio',ascending=False)
return [u"限售股解禁:",df[df.ratio>10]]
#每日龙虎榜列表
def EveryDayTop():
day=dt.date.today()
while ts.is_holiday(str(day)):
day=day-dt.timedelta(days=1)
df=ts.top_list(str(day))
return [u"%s日龙虎榜列表:(%s条)"%(str(day+dt.timedelta(days=1)),len(df)),df]
#个股上榜统计
def TopTotal():
df=ts.cap_tops()
df=df.sort_values('count',ascending=False)
return [u"个股上榜统计:",df[:20]]
#机构席位追踪
def ChairTotal():
df=ts.inst_tops()
df=df.sort_values('bcount',ascending=False)
return [u"机构席位追踪:",df[:20]]
#机构成交明细
def ChairDetail():
df=ts.inst_detail()
df=df.sort_values('bamount',ascending=False)
return [u"机构成交明细:",df[:50]]
if __name__ == '__main__':
function_list=[HighShares,ProfitExp,EveryDayTop,TopTotal,ChairTotal,ChairDetail,XsgJj]
count=multiprocessing.cpu_count()
if count>2:
count=count-1
pool = multiprocessing.Pool(count)
result=[]
for func in function_list:
result.append(pool.apply_async(func, ()))
pool.close()
pool.join()
print "Sub-process(es) done."
for res in result:
t=res.get()
print t[0]
print t[1]
'''
#输出到文件
filename=".\\"+str(dt.date.today())+".txt"
f=open(filename,'w')
for res in result:
t=res.get()
f.write(t[0].encode("GBK")+"\n")
for s in t[1]:
f.writelines(s)
f.close()
'''