siat 3.4.27__py3-none-any.whl → 3.4.37__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- siat/common.py +6 -5
- siat/grafix.py +2 -1
- siat/sector_china.py +246 -59
- {siat-3.4.27.dist-info → siat-3.4.37.dist-info}/METADATA +1 -1
- {siat-3.4.27.dist-info → siat-3.4.37.dist-info}/RECORD +8 -8
- {siat-3.4.27.dist-info → siat-3.4.37.dist-info}/WHEEL +1 -1
- {siat-3.4.27.dist-info → siat-3.4.37.dist-info}/LICENSE +0 -0
- {siat-3.4.27.dist-info → siat-3.4.37.dist-info}/top_level.txt +0 -0
siat/common.py
CHANGED
@@ -2461,7 +2461,7 @@ if __name__=='__main__':
|
|
2461
2461
|
alist=['NIO','LI','XPEV','TSLA']
|
2462
2462
|
print_list(alist)
|
2463
2463
|
|
2464
|
-
def print_list(alist,leading_blanks=1):
|
2464
|
+
def print_list(alist,leading_blanks=1,end='\n'):
|
2465
2465
|
"""
|
2466
2466
|
功能:打印一个字符串列表,不带引号,节省空间
|
2467
2467
|
"""
|
@@ -2469,7 +2469,7 @@ def print_list(alist,leading_blanks=1):
|
|
2469
2469
|
|
2470
2470
|
for i in alist:
|
2471
2471
|
print(i,end=' ')
|
2472
|
-
print('
|
2472
|
+
print(end,end='')
|
2473
2473
|
|
2474
2474
|
return
|
2475
2475
|
|
@@ -3799,8 +3799,9 @@ def df_display_CSS(df,titletxt='',footnote='',facecolor='papayawhip',decimals=2,
|
|
3799
3799
|
from IPython.display import display
|
3800
3800
|
display(style6)
|
3801
3801
|
|
3802
|
-
|
3803
|
-
|
3802
|
+
if not footnote=='':
|
3803
|
+
print(footnote)
|
3804
|
+
#print('') #空一行
|
3804
3805
|
|
3805
3806
|
return
|
3806
3807
|
|
@@ -3811,7 +3812,7 @@ if __name__=='__main__':
|
|
3811
3812
|
def upgrade_siat(module_list=['siat','akshare','pandas','pandas_datareader', \
|
3812
3813
|
'yfinance','yahooquery','urllib3','tabulate','twine', \
|
3813
3814
|
'mplfinance','openpyxl','pip','bottleneck','ipywidgets'], \
|
3814
|
-
pipcmd="pip install --upgrade",alternative=""):
|
3815
|
+
pipcmd="python -m pip install --upgrade --user",alternative=""):
|
3815
3816
|
"""
|
3816
3817
|
功能:一次性升级siat及其相关插件
|
3817
3818
|
|
siat/grafix.py
CHANGED
@@ -128,7 +128,8 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
|
|
128
128
|
mark_top,mark_bottom:是否标记最高最低点
|
129
129
|
输出:折线图
|
130
130
|
返回值:无
|
131
|
-
|
131
|
+
注意1:需要日期类型作为df索引
|
132
|
+
注意2:date_freq不为False时,必须设置date_range=True,否则无法完成日期设置!
|
132
133
|
"""
|
133
134
|
|
134
135
|
#空值判断
|
siat/sector_china.py
CHANGED
@@ -151,13 +151,24 @@ def sector_list_china(indicator="新浪行业"):
|
|
151
151
|
#==============================================================================
|
152
152
|
if __name__=='__main__':
|
153
153
|
sector_name="房地产"
|
154
|
+
sector_name="房"
|
155
|
+
sector_name="煤炭"
|
156
|
+
sector_name="华为"
|
157
|
+
|
158
|
+
indicator='新浪行业'
|
154
159
|
indicator="启明星行业"
|
155
160
|
indicator="地域"
|
156
161
|
indicator="行业"
|
157
162
|
|
158
|
-
sector_name="煤炭"
|
159
163
|
sector_code_china(sector_name)
|
160
164
|
|
165
|
+
def sector_code_sina(sector_name):
|
166
|
+
"""
|
167
|
+
功能:套壳sector_code_china
|
168
|
+
"""
|
169
|
+
sector_code_china(sector_name)
|
170
|
+
return
|
171
|
+
|
161
172
|
def sector_code_china(sector_name):
|
162
173
|
"""
|
163
174
|
功能:查找行业、板块名称对应的板块代码
|
@@ -175,26 +186,46 @@ def sector_code_china(sector_name):
|
|
175
186
|
dfi['label']=dfi['label'].apply(lambda x: x.strip())
|
176
187
|
|
177
188
|
try:
|
178
|
-
sector_code=list(dfi[dfi['板块']==sector_name]['label'])[0]
|
189
|
+
#sector_code=list(dfi[dfi['板块']==sector_name]['label'])[0]
|
190
|
+
dfi['match']=dfi['板块'].apply(lambda x: 1 if sector_name in x else 0)
|
191
|
+
found=found+dfi['match'].sum()
|
192
|
+
|
193
|
+
sector_code=list(dfi[dfi['match']==1]['label'])
|
194
|
+
sector_name1=list(dfi[dfi['match']==1]['板块'])
|
195
|
+
|
179
196
|
#记录找到的板块分类
|
180
197
|
indicator=i
|
181
|
-
#记录找到的板块概述
|
182
|
-
dff=dfi[dfi['板块']==sector_name]
|
183
198
|
|
184
|
-
if found > 0: print(" ")
|
199
|
+
#if found > 0: print(" ")
|
185
200
|
if indicator == "行业": indicator = "证监会行业"
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
201
|
+
if indicator == "概念": indicator = "新浪概念"
|
202
|
+
|
203
|
+
if len(sector_code)>0:
|
204
|
+
"""
|
205
|
+
print("行业/板块名称:",sector_name1)
|
206
|
+
#print_list(sector_name1,leading_blanks=1)
|
207
|
+
|
208
|
+
print("行业/板块代码:",sector_code,end='')
|
209
|
+
#print_list(sector_code,leading_blanks=1)
|
210
|
+
|
211
|
+
print("("+indicator+"分类)\n")
|
212
|
+
"""
|
213
|
+
print("行业/板块名称:",end='')
|
214
|
+
print_list(sector_name1,leading_blanks=1)
|
215
|
+
|
216
|
+
print("行业/板块代码:",end='')
|
217
|
+
print_list(sector_code,leading_blanks=1,end='')
|
218
|
+
print("("+indicator+"分类)\n")
|
219
|
+
|
220
|
+
|
190
221
|
except:
|
191
222
|
# 无意义,仅为调试
|
192
|
-
|
223
|
+
pass
|
193
224
|
continue
|
194
225
|
|
195
226
|
#未找到板块代码
|
196
227
|
if found==0:
|
197
|
-
print("
|
228
|
+
print("*** Sorry, no sector name found for",sector_name)
|
198
229
|
return
|
199
230
|
|
200
231
|
return
|
@@ -220,6 +251,13 @@ if __name__=='__main__':
|
|
220
251
|
indicator="行业"
|
221
252
|
num=10
|
222
253
|
|
254
|
+
def sector_rank_sina(indicator="涨跌幅",category="新浪行业",rank=5):
|
255
|
+
"""
|
256
|
+
功能:套壳sector_rank_china
|
257
|
+
"""
|
258
|
+
df=sector_rank_china(comp=indicator,indicator=category,num=rank)
|
259
|
+
return df
|
260
|
+
|
223
261
|
def sector_rank_china(comp="涨跌幅",indicator="新浪行业",num=10):
|
224
262
|
"""
|
225
263
|
功能:按照比较指标降序排列
|
@@ -233,14 +271,14 @@ def sector_rank_china(comp="涨跌幅",indicator="新浪行业",num=10):
|
|
233
271
|
#complist=["涨跌幅","成交量","平均价格","公司家数"]
|
234
272
|
complist=["涨跌幅","平均价格","公司家数"]
|
235
273
|
if comp not in complist:
|
236
|
-
print("#
|
237
|
-
print("Supported measurements:",complist)
|
274
|
+
print(" #Warning(sector_rank_china): unsupported measurement",comp)
|
275
|
+
print(" Supported measurements:",complist)
|
238
276
|
return None
|
239
277
|
|
240
278
|
indicatorlist=["新浪行业","概念","地域","启明星行业","行业"]
|
241
279
|
if indicator not in indicatorlist:
|
242
|
-
print("#
|
243
|
-
print("Supported sectoring method:",indicatorlist)
|
280
|
+
print(" #Warning(sector_list_china): unsupported sectoring method",indicator)
|
281
|
+
print(" Supported sectoring method:",indicatorlist)
|
244
282
|
return None
|
245
283
|
|
246
284
|
import akshare as ak
|
@@ -252,9 +290,9 @@ def sector_rank_china(comp="涨跌幅",indicator="新浪行业",num=10):
|
|
252
290
|
df['label']=df['label'].apply(lambda x: x.strip())
|
253
291
|
|
254
292
|
except:
|
255
|
-
print("#
|
256
|
-
print("Possible reason: data source is self-updating.")
|
257
|
-
print("Solution: have a breath of fresh air and try later.")
|
293
|
+
print(" #Warning(sector_rank_china): data source tentatively unavailable for",indicator)
|
294
|
+
print(" Possible reason: data source is self-updating.")
|
295
|
+
print(" Solution: have a breath of fresh air and try later.")
|
258
296
|
return None
|
259
297
|
|
260
298
|
df.dropna(inplace=True)
|
@@ -322,12 +360,18 @@ def sector_rank_china(comp="涨跌幅",indicator="新浪行业",num=10):
|
|
322
360
|
|
323
361
|
#处理空记录
|
324
362
|
if len(df3) == 0:
|
325
|
-
print("#
|
326
|
-
print("Possible reason: data source is self-updating.")
|
327
|
-
print("Solution: have a breath of fresh air and try later.")
|
363
|
+
print(" #Warning(sector_rank_china):data source tentatively unavailable for",comp,indicator)
|
364
|
+
print(" Possible reason: data source is self-updating.")
|
365
|
+
print(" Solution: have a breath of fresh air and try later.")
|
328
366
|
return
|
329
367
|
|
330
368
|
df3.index=df3.index + 1
|
369
|
+
|
370
|
+
df3_collist=list(df3)
|
371
|
+
df3['序号']=df3.index
|
372
|
+
df3=df3[['序号']+df3_collist]
|
373
|
+
|
374
|
+
"""
|
331
375
|
print("\n===== 中国股票市场:板块"+comp+"排行榜(按照"+indtag+"分类) =====")
|
332
376
|
if num > 0:
|
333
377
|
print(df3.head(num))
|
@@ -339,6 +383,23 @@ def sector_rank_china(comp="涨跌幅",indicator="新浪行业",num=10):
|
|
339
383
|
footnote1="*注:代表个股是指板块中涨幅最高或跌幅最低的股票"
|
340
384
|
print(footnote1)
|
341
385
|
print(" 板块数:",len(df),"\b, 数据来源:新浪财经,",today,"\b(信息为上个交易日)")
|
386
|
+
"""
|
387
|
+
if num > 0:
|
388
|
+
df4=df3.head(num)
|
389
|
+
else:
|
390
|
+
df4=df3.tail(-num)
|
391
|
+
|
392
|
+
titletxt="中国股票市场:板块"+comp+"排行榜(按照"+indtag+"分类)"
|
393
|
+
import datetime; stoday = datetime.date.today()
|
394
|
+
footnote1="注:代表个股是指板块中涨幅最高或跌幅最低的股票\n"
|
395
|
+
footnote2="板块总数"+str(len(df))+",数据来源:新浪财经,"+str(stoday)+"(截至昨日)"
|
396
|
+
footnote=footnote1+footnote2
|
397
|
+
|
398
|
+
df_display_CSS(df4,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=2, \
|
399
|
+
first_col_align='center',second_col_align='left', \
|
400
|
+
last_col_align='left',other_col_align='right', \
|
401
|
+
titile_font_size='16px',heading_font_size='15px', \
|
402
|
+
data_font_size='15px')
|
342
403
|
|
343
404
|
return df3
|
344
405
|
|
@@ -349,6 +410,14 @@ if __name__=='__main__':
|
|
349
410
|
|
350
411
|
num=10
|
351
412
|
|
413
|
+
def sector_detail_sina(sector="new_dlhy",indicator="涨跌幅",rank=5):
|
414
|
+
"""
|
415
|
+
功能:套壳sector_detail_china
|
416
|
+
"""
|
417
|
+
df=sector_detail_china(sector=sector,comp=indicator,num=rank)
|
418
|
+
return df
|
419
|
+
|
420
|
+
|
352
421
|
def sector_detail_china(sector="new_dlhy",comp="涨跌幅",num=10):
|
353
422
|
"""
|
354
423
|
功能:按照板块内部股票的比较指标降序排列
|
@@ -458,6 +527,11 @@ def sector_detail_china(sector="new_dlhy",comp="涨跌幅",num=10):
|
|
458
527
|
pd.set_option('display.unicode.east_asian_width', True)
|
459
528
|
|
460
529
|
df3.index=df3.index + 1
|
530
|
+
|
531
|
+
df3_collist=list(df3)
|
532
|
+
df3['序号']=df3.index
|
533
|
+
df3=df3[['序号']+df3_collist]
|
534
|
+
"""
|
461
535
|
print("\n=== 中国股票市场:"+sector_name+"板块,成份股排行榜(按照"+comp+") ===\n")
|
462
536
|
if num > 0:
|
463
537
|
print(df3.head(num))
|
@@ -469,7 +543,29 @@ def sector_detail_china(sector="new_dlhy",comp="涨跌幅",num=10):
|
|
469
543
|
footnote1="\n 注:市值的单位是亿元人民币, "
|
470
544
|
print(footnote1+"板块内成份股个数:",len(df))
|
471
545
|
print(" 数据来源:新浪财经,",today,"\b(信息为上个交易日)")
|
472
|
-
|
546
|
+
"""
|
547
|
+
if num > 0:
|
548
|
+
df4=df3.head(num)
|
549
|
+
else:
|
550
|
+
df4=df3.tail(-num)
|
551
|
+
|
552
|
+
titletxt="中国股票市场:"+sector_name+"板块,成份股排行榜(基于"+comp+")"
|
553
|
+
|
554
|
+
import datetime; stoday = datetime.date.today()
|
555
|
+
if "流通市值" in df3_collist:
|
556
|
+
footnote1="市值单位:亿元,板块成份股:"+str(len(df))+'\n'
|
557
|
+
footnote2="数据来源:新浪财经,"+str(stoday)+"(截至昨日)"
|
558
|
+
else:
|
559
|
+
footnote1="板块成份股:"+str(len(df))+','
|
560
|
+
footnote2="数据来源:新浪财经,"+str(stoday)+"(截至昨日)"
|
561
|
+
footnote=footnote1+footnote2
|
562
|
+
|
563
|
+
df_display_CSS(df4,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=2, \
|
564
|
+
first_col_align='center',second_col_align='left', \
|
565
|
+
last_col_align='right',other_col_align='right', \
|
566
|
+
titile_font_size='16px',heading_font_size='15px', \
|
567
|
+
data_font_size='15px')
|
568
|
+
|
473
569
|
return df2
|
474
570
|
|
475
571
|
#==============================================================================
|
@@ -480,6 +576,19 @@ if __name__=='__main__':
|
|
480
576
|
sector="new_dlhy"
|
481
577
|
sector="yysw"
|
482
578
|
sector="xyz"
|
579
|
+
|
580
|
+
ticker='000661.SZ'; sector="gn_swym"
|
581
|
+
|
582
|
+
def sector_position_sina(ticker,sector="new_dlhy",return_result=False):
|
583
|
+
"""
|
584
|
+
功能:套壳sector_position_china
|
585
|
+
"""
|
586
|
+
df=sector_position_china(ticker=ticker,sector=sector)
|
587
|
+
|
588
|
+
if return_result:
|
589
|
+
return df
|
590
|
+
else:
|
591
|
+
return
|
483
592
|
|
484
593
|
def sector_position_china(ticker,sector="new_dlhy"):
|
485
594
|
"""
|
@@ -512,19 +621,21 @@ def sector_position_china(ticker,sector="new_dlhy"):
|
|
512
621
|
break
|
513
622
|
except:
|
514
623
|
continue
|
624
|
+
|
515
625
|
#未找到板块代码
|
516
626
|
if sector_name == '':
|
517
|
-
print(" #
|
627
|
+
print(" #Warning(sector_position_china): unsupported sector code",sector)
|
518
628
|
return None
|
519
629
|
|
520
630
|
#板块成份股
|
521
631
|
try:
|
522
|
-
|
632
|
+
#注意:启明星行业分类没有成份股明细
|
523
633
|
df = ak.stock_sector_detail(sector=sector)
|
524
634
|
except:
|
525
|
-
print(" #
|
526
|
-
|
527
|
-
|
635
|
+
print(" #Warning(sector_position_china): sector detail not available for",sector,'by',indicator)
|
636
|
+
if indicator !="启明星行业":
|
637
|
+
print(" Possible reason: data source is self-updating.")
|
638
|
+
print(" Solution: have a breath of fresh air and try later.")
|
528
639
|
return None
|
529
640
|
|
530
641
|
#清洗原始数据: #可能同时含有数值和字符串,强制转换成数值
|
@@ -539,28 +650,40 @@ def sector_position_china(ticker,sector="new_dlhy"):
|
|
539
650
|
#检查股票代码是否存在
|
540
651
|
sdf=df[df['code']==ticker1]
|
541
652
|
if len(sdf) == 0:
|
542
|
-
print(" #
|
543
|
-
print("
|
653
|
+
print(" #Warning(sector_position_china): retrieving",ticker,"failed in sector",sector,sector_name)
|
654
|
+
print(" Solution: make sure stock code correct, try later if network is slow")
|
544
655
|
return None
|
545
656
|
sname=list(sdf['name'])[0]
|
546
657
|
|
547
658
|
#确定比较范围
|
548
659
|
complist=['changepercent','turnoverratio','settlement','per','pb','nmc','mktcap']
|
660
|
+
vminlist=['settlement','per','pb','nmc','mktcap'] #板块最小值若为零需要标记的列
|
549
661
|
compnames=['涨跌幅%','换手率%','收盘价(元)','市盈率','市净率','流通市值(亿元)','总市值(亿元)']
|
550
|
-
compdf=pd.DataFrame(columns=['指标名称','指标数值','
|
662
|
+
compdf=pd.DataFrame(columns=['指标名称','指标数值','板块排名','板块分位数%','板块中位数','板块最小值','板块最大值'])
|
663
|
+
|
664
|
+
from scipy.stats import percentileofscore
|
665
|
+
|
551
666
|
for c in complist:
|
552
667
|
v=list(sdf[c])[0]
|
553
|
-
vlist=list(set(list(df[c])))
|
554
|
-
vlist
|
668
|
+
#vlist=list(set(list(df[c])))
|
669
|
+
vlist=list(df[c])
|
670
|
+
vlist.sort() #升序
|
555
671
|
vmin=round(min(vlist),2)
|
672
|
+
if vmin==0.00 and c in vminlist:
|
673
|
+
vmin='--'
|
674
|
+
|
556
675
|
vmax=round(max(vlist),2)
|
557
676
|
vmedian=round(np.median(vlist),2)
|
558
677
|
|
559
678
|
pos=vlist.index(v)
|
560
|
-
pct=round((pos+1)/len(vlist)*100,2)
|
679
|
+
#pct=round((pos+1)/len(vlist)*100,2)
|
680
|
+
#sector_rank=str(len(vlist)-pos)+'/'+str(len(vlist))
|
681
|
+
sector_rank=str(len(vlist)-pos)
|
682
|
+
|
683
|
+
pct=percentileofscore(vlist,v)
|
561
684
|
|
562
685
|
s=pd.Series({'指标名称':compnames[complist.index(c)], \
|
563
|
-
'指标数值':v,'
|
686
|
+
'指标数值':v,'板块排名':sector_rank,'板块分位数%':pct,'板块中位数':vmedian, \
|
564
687
|
'板块最小值':vmin,'板块最大值':vmax})
|
565
688
|
try:
|
566
689
|
compdf=compdf.append(s,ignore_index=True)
|
@@ -568,7 +691,7 @@ def sector_position_china(ticker,sector="new_dlhy"):
|
|
568
691
|
compdf=compdf._append(s,ignore_index=True)
|
569
692
|
|
570
693
|
compdf.reset_index(drop=True,inplace=True)
|
571
|
-
|
694
|
+
"""
|
572
695
|
print("\n======= 股票在所属行业/板块的位置分析 =======")
|
573
696
|
print("股票: "+sname+" ("+ticker+")")
|
574
697
|
print("所属行业/板块:"+sector_name+" ("+sector+", "+indicator+"分类)")
|
@@ -586,7 +709,23 @@ def sector_position_china(ticker,sector="new_dlhy"):
|
|
586
709
|
today = datetime.date.today()
|
587
710
|
print('') #空一行
|
588
711
|
print("注:板块内成份股个数:",len(df),"\b, 数据来源:新浪财经,",today,"\b(信息为上个交易日)")
|
589
|
-
|
712
|
+
"""
|
713
|
+
if indicator=="行业": indicator="证监会行业"
|
714
|
+
|
715
|
+
titletxt="\n上市公司地位分析:"+sname+","+sector_name+"行业/板块("+indicator+"分类)"
|
716
|
+
import datetime; stoday = datetime.date.today()
|
717
|
+
footnote1=""
|
718
|
+
footnote2="成分股总数:"+str(len(df))+",数据来源:新浪财经,"+str(stoday)+"(截至昨日)"
|
719
|
+
footnote=footnote1+footnote2
|
720
|
+
|
721
|
+
#print("") #空一行
|
722
|
+
df_display_CSS(compdf,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=2, \
|
723
|
+
first_col_align='left',second_col_align='right', \
|
724
|
+
last_col_align='right',other_col_align='right', \
|
725
|
+
titile_font_size='16px',heading_font_size='15px', \
|
726
|
+
data_font_size='15px')
|
727
|
+
|
728
|
+
|
590
729
|
return df,compdf
|
591
730
|
|
592
731
|
|
@@ -810,7 +949,7 @@ if __name__=='__main__':
|
|
810
949
|
|
811
950
|
print_industry_component_sw(iname,numberPerLine=5,colalign='right')
|
812
951
|
|
813
|
-
def print_industry_component_sw(iname,numberPerLine=5,colalign='left'):
|
952
|
+
def print_industry_component_sw(iname,numberPerLine=5,colalign='left',return_result=False):
|
814
953
|
"""
|
815
954
|
打印申万行业的成分股,名称(代码)
|
816
955
|
"""
|
@@ -833,12 +972,15 @@ def print_industry_component_sw(iname,numberPerLine=5,colalign='left'):
|
|
833
972
|
import datetime as dt; stoday=dt.date.today()
|
834
973
|
ilist=list(cdf['name_code'])
|
835
974
|
|
836
|
-
titletxt=
|
975
|
+
titletxt=iname+"("+icode+")行业/板块成分股:计"+str(len(ilist))+'只,按行业指数权重降序排列,'+str(stoday)
|
837
976
|
print("\n"+titletxt,end='')
|
838
977
|
#表格
|
839
978
|
printInLine_md(ilist,numberPerLine=numberPerLine,colalign=colalign)
|
840
979
|
|
841
|
-
|
980
|
+
if return_result:
|
981
|
+
return ilist
|
982
|
+
else:
|
983
|
+
return
|
842
984
|
|
843
985
|
#==============================================================================
|
844
986
|
if __name__=='__main__':
|
@@ -859,8 +1001,10 @@ def print_industry_component_sw2(icode,numberPerLine=5,colalign='left'):
|
|
859
1001
|
|
860
1002
|
clist,cdf=industry_stock_sw(icode,top=1000)
|
861
1003
|
if cdf is None:
|
862
|
-
print(" Error(print_industry_component_sw2):
|
863
|
-
print("
|
1004
|
+
print(" #Error(print_industry_component_sw2): failed to retrieve industry for",icode)
|
1005
|
+
print(" Solution: make sure the industry code correct")
|
1006
|
+
print(" If the code is correct, upgrade akshare, restart jupyter and try again")
|
1007
|
+
|
864
1008
|
return
|
865
1009
|
|
866
1010
|
#cdf['icode']=cdf['证券代码'].apply(lambda x: x+'.SS' if x[:1] in ['6'] else (x+'.SZ' if x[:1] in ['0','3'] else x+'.BJ' ))
|
@@ -1167,7 +1311,7 @@ if __name__=='__main__':
|
|
1167
1311
|
period="day"
|
1168
1312
|
industry_list='all'
|
1169
1313
|
|
1170
|
-
def get_industry_sw(itype='1',period="day",industry_list='all',max_sleep=
|
1314
|
+
def get_industry_sw(itype='1',period="day",industry_list='all',max_sleep=15):
|
1171
1315
|
"""
|
1172
1316
|
功能:遍历某类申万指数,下载数据
|
1173
1317
|
itype: F表征指数,n=1/2/3行业指数,S风格指数,B大类风格,C金创类
|
@@ -1211,7 +1355,7 @@ def get_industry_sw(itype='1',period="day",industry_list='all',max_sleep=8):
|
|
1211
1355
|
total=len(ilist)
|
1212
1356
|
fail_list=[]
|
1213
1357
|
for i in ilist:
|
1214
|
-
print_progress_percent2(i,ilist,steps=5,leading_blanks=4)
|
1358
|
+
#print_progress_percent2(i,ilist,steps=5,leading_blanks=4)
|
1215
1359
|
#print(" Retrieving information for industry",i)
|
1216
1360
|
|
1217
1361
|
#抓取指数价格
|
@@ -1243,6 +1387,7 @@ def get_industry_sw(itype='1',period="day",industry_list='all',max_sleep=8):
|
|
1243
1387
|
current=ilist.index(i)
|
1244
1388
|
#print_progress_percent(current,total,steps=steps,leading_blanks=2)
|
1245
1389
|
|
1390
|
+
print_progress_percent2(i,ilist,steps=steps,leading_blanks=4)
|
1246
1391
|
#生成随机数睡眠,试图防止被反爬虫,不知是否管用!
|
1247
1392
|
random_int=random.randint(1,max_sleep)
|
1248
1393
|
time.sleep(random_int)
|
@@ -1276,7 +1421,7 @@ if __name__=='__main__':
|
|
1276
1421
|
industry_list=['850831.SW','801785.SW','801737.SW','801194.SW',
|
1277
1422
|
'801784.SW','801783.SW','801782.SW']
|
1278
1423
|
|
1279
|
-
def get_industry_sw2(industry_list,period="day",max_sleep=
|
1424
|
+
def get_industry_sw2(industry_list,period="day",max_sleep=15):
|
1280
1425
|
"""
|
1281
1426
|
功能:遍历指定的申万指数列表,下载数据
|
1282
1427
|
period="day"; choice of {"day", "week", "month"}
|
@@ -2112,8 +2257,8 @@ def industry_stock_sw(industry='801270.SW',top=5,printout=False):
|
|
2112
2257
|
try:
|
2113
2258
|
cdf = ak.index_component_sw(industry)
|
2114
2259
|
except:
|
2115
|
-
print(" #Warning(industry_stock_sw):
|
2116
|
-
print("
|
2260
|
+
print(" #Warning(industry_stock_sw): failed to retrieve component info for",industry)
|
2261
|
+
print(" Solution: upgrade akshare, restart jupyter and try again")
|
2117
2262
|
return None,None
|
2118
2263
|
|
2119
2264
|
# 删除'证券名称'为None的行
|
@@ -2834,6 +2979,7 @@ if __name__ =="__main__":
|
|
2834
2979
|
|
2835
2980
|
|
2836
2981
|
def industry_scan_china(sw_level='F', \
|
2982
|
+
indicator='Exp Ret%', \
|
2837
2983
|
start='MRY',end='default', \
|
2838
2984
|
RF=0, \
|
2839
2985
|
printout='smart', \
|
@@ -2847,7 +2993,7 @@ def industry_scan_china(sw_level='F', \
|
|
2847
2993
|
筛选方式printout:smart--收益前10名与后10名(默认),winner--仅限收益为正的行业,
|
2848
2994
|
loser--仅限收益为负的行业,50--收益前50名,-10--收益后10名,all--所有行业
|
2849
2995
|
"""
|
2850
|
-
indicator='Exp Ret%'
|
2996
|
+
#indicator='Exp Ret%'
|
2851
2997
|
|
2852
2998
|
print(" Collecting industry info, it may take very long time ... ...")
|
2853
2999
|
|
@@ -3003,7 +3149,7 @@ def industry_scan_china(sw_level='F', \
|
|
3003
3149
|
if printout=='all':
|
3004
3150
|
printout_txt='所有指数'
|
3005
3151
|
elif printout=='smart':
|
3006
|
-
printout_txt='
|
3152
|
+
printout_txt='前/后十个行业'
|
3007
3153
|
if len(df2) <=20:
|
3008
3154
|
printout_txt='所有指数'
|
3009
3155
|
elif printout=='winner':
|
@@ -3024,7 +3170,8 @@ def industry_scan_china(sw_level='F', \
|
|
3024
3170
|
printout_txt='未知筛选方式'
|
3025
3171
|
|
3026
3172
|
#titletxt="申万行业业绩排行榜:"+sw_level_txt+',共'+str(len(df_prt))+"个指数符合条件"
|
3027
|
-
titletxt="行业业绩排行榜:"+sw_level_txt+',筛选方式:'+printout_txt
|
3173
|
+
#titletxt="行业业绩排行榜:"+sw_level_txt+','+ectranslate(indicator)+',筛选方式:'+printout_txt
|
3174
|
+
titletxt="中国股市板块表现排行榜:"+sw_level_txt+','+printout_txt
|
3028
3175
|
#print("\n***",titletxt,'\n')
|
3029
3176
|
"""
|
3030
3177
|
alignlist=['center']+['left']*(len(list(df_prt))-1)
|
@@ -3032,7 +3179,7 @@ def industry_scan_china(sw_level='F', \
|
|
3032
3179
|
"""
|
3033
3180
|
#print("\n *** 数据来源:综合申万宏源/东方财富/新浪财经,",todaydt,"\b;分析期间:",fromdate+'至'+todate)
|
3034
3181
|
#footnote1="筛选方式:all-所有,smart-收益最高最低各10个,winner-收益为正,loser-收益为负"
|
3035
|
-
footnote2="
|
3182
|
+
footnote2="数据来源:申万宏源,统计期间:"+str(fromdate)+'至'+str(todate)+"(截至昨日)。"+str(todaydt)+"制表"
|
3036
3183
|
#footnote=footnote1+'\n'+footnote2
|
3037
3184
|
footnote=footnote2
|
3038
3185
|
|
@@ -3040,10 +3187,25 @@ def industry_scan_china(sw_level='F', \
|
|
3040
3187
|
titile_font_size=font_size
|
3041
3188
|
heading_font_size=data_font_size=str(int(font_size.replace('px',''))-1)+'px'
|
3042
3189
|
|
3190
|
+
df_prt['序号']=df_prt.index
|
3191
|
+
if indicator=='Exp Ret%':
|
3192
|
+
df_prt=df_prt[['序号','行业名称','行业代码','投资收益率%','投资收益波动率%','投资收益损失风险%','夏普比率','索替诺比率']]
|
3193
|
+
elif indicator=='Exp Ret Volatility%':
|
3194
|
+
df_prt=df_prt[['序号','行业名称','行业代码','投资收益波动率%','投资收益率%','投资收益损失风险%','夏普比率','索替诺比率']]
|
3195
|
+
elif indicator=='Exp Ret LPSD%':
|
3196
|
+
df_prt=df_prt[['序号','行业名称','行业代码','投资收益损失风险%','投资收益波动率%','投资收益率%','夏普比率','索替诺比率']]
|
3197
|
+
elif indicator=='sharpe':
|
3198
|
+
df_prt=df_prt[['序号','行业名称','行业代码','夏普比率','索替诺比率','投资收益率%','投资收益波动率%','投资收益损失风险%']]
|
3199
|
+
elif indicator=='sortino':
|
3200
|
+
df_prt=df_prt[['序号','行业名称','行业代码','索替诺比率','夏普比率','投资收益率%','投资收益波动率%','投资收益损失风险%']]
|
3201
|
+
|
3202
|
+
|
3203
|
+
|
3043
3204
|
df_display_CSS(df_prt,titletxt=titletxt,footnote=footnote,facecolor=facecolor, \
|
3044
|
-
first_col_align='
|
3205
|
+
first_col_align='center',second_col_align='left', \
|
3206
|
+
last_col_align='center',other_col_align='center', \
|
3045
3207
|
titile_font_size=titile_font_size,heading_font_size=heading_font_size, \
|
3046
|
-
|
3208
|
+
data_font_size=data_font_size)
|
3047
3209
|
|
3048
3210
|
return df2
|
3049
3211
|
|
@@ -3531,7 +3693,7 @@ def get_stock_industry_sw(ticker):
|
|
3531
3693
|
|
3532
3694
|
return industry
|
3533
3695
|
else:
|
3534
|
-
return
|
3696
|
+
return ''
|
3535
3697
|
|
3536
3698
|
#==============================================================================
|
3537
3699
|
if __name__ == '__main__':
|
@@ -3548,24 +3710,49 @@ def stock_peers_sw(ticker):
|
|
3548
3710
|
try:
|
3549
3711
|
hangye=get_stock_industry_sw(ticker)
|
3550
3712
|
except:
|
3551
|
-
print(" #Warning(stock_peers_sw):
|
3713
|
+
print(" #Warning(stock_peers_sw): industry info not found for",ticker)
|
3552
3714
|
return
|
3553
3715
|
|
3716
|
+
if hangye=='':
|
3717
|
+
print(" #Warning(stock_peers_sw): found empty industry for",ticker)
|
3718
|
+
return
|
3719
|
+
|
3720
|
+
ilist=[]; hangye_final=''
|
3554
3721
|
#三级行业优先
|
3555
3722
|
hangye3=hangye+'Ⅲ'
|
3556
3723
|
try:
|
3557
|
-
print_industry_component_sw(iname=hangye3)
|
3724
|
+
ilist=print_industry_component_sw(iname=hangye3,return_result=True)
|
3725
|
+
hangye_final=hangye3
|
3558
3726
|
except:
|
3559
3727
|
#二级行业次优先
|
3560
3728
|
hangye2=hangye+'Ⅱ'
|
3561
3729
|
try:
|
3562
|
-
print_industry_component_sw(iname=hangye2)
|
3730
|
+
ilist=print_industry_component_sw(iname=hangye2,return_result=True)
|
3731
|
+
hangye_final=hangye2
|
3563
3732
|
except:
|
3564
3733
|
try:
|
3565
|
-
print_industry_component_sw(iname=hangye)
|
3734
|
+
ilist=print_industry_component_sw(iname=hangye,return_result=True)
|
3735
|
+
hangye_final=hangye
|
3566
3736
|
except:
|
3567
|
-
print("
|
3568
|
-
|
3737
|
+
print("\n #Warning(stock_peers_sw): failed to search peers for",ticker)
|
3738
|
+
print(" Possible solutions:")
|
3739
|
+
print(" Try first: upgrade akshare, restart Jupyter and try again")
|
3740
|
+
print(" If not working, uninstall anaconda and reinstall a newer version")
|
3741
|
+
|
3742
|
+
#查找股票在行业板块中的位置
|
3743
|
+
if not ilist=='':
|
3744
|
+
ticker6=ticker[:6]
|
3745
|
+
for i in ilist:
|
3746
|
+
if ticker6 in i:
|
3747
|
+
ticker_item=i
|
3748
|
+
ticker_pos=ilist.index(i)+1
|
3749
|
+
break
|
3750
|
+
|
3751
|
+
footnote0="注:"
|
3752
|
+
footnote1=ticker_item+"在申万行业"+hangye_final+"指数中的权重排名为"+str(ticker_pos)+'/'+str(len(ilist))
|
3753
|
+
footnote2="该指数的权重排名依据主要包括公司的市值规模、流动性以及市场代表性"
|
3754
|
+
footnote=footnote0+'\n'+footnote1+'\n'+footnote2
|
3755
|
+
print(footnote)
|
3569
3756
|
return
|
3570
3757
|
|
3571
3758
|
|
@@ -18,7 +18,7 @@ siat/capm_beta.py,sha256=cxXdRVBQBllhbfz1LeTJAIWvyRYhW54nhtNUXv4HwS0,29063
|
|
18
18
|
siat/capm_beta2.py,sha256=lUuCPVSxebkA2yye1PXu1V2Jd2UKEwD_kIA25DCIDTs,29750
|
19
19
|
siat/capm_beta_test.py,sha256=ImR0c5mc4hIl714XmHztdl7qg8v1E2lycKyiqnFj6qs,1745
|
20
20
|
siat/cmat_commons.py,sha256=Nj9Kf0alywaztVoMVeVVL_EZk5jRERJy8R8kBw88_Tg,38116
|
21
|
-
siat/common.py,sha256=
|
21
|
+
siat/common.py,sha256=OQ1Bh2hHVvdraOLBeUAhPC3Wlx38p7n2COknmtJALZQ,151771
|
22
22
|
siat/compare_cross.py,sha256=3iP9TH2h3w27F2ARZc7FjKcErYCzWRc-TPiymOyoVtw,24171
|
23
23
|
siat/compare_cross_test.py,sha256=xra5XYmQGEtfIZL2h-GssdH2hLdFIhG3eoCrkDrL3gY,3473
|
24
24
|
siat/concepts_iwencai.py,sha256=m1YEDtECRT6FqtzlKm91pt2I9d3Z_XoP59BtWdRdu8I,3061
|
@@ -60,7 +60,7 @@ siat/future_china.py,sha256=F-HsIf2Op8Z22RzTjet1g8COzldgnMjFNSXsAkeGyWo,17595
|
|
60
60
|
siat/future_china_test.py,sha256=BrSzmDVaOHki6rntOtosmRn-6dkfOBuLulJNqh7MOpc,1163
|
61
61
|
siat/global_index_test.py,sha256=hnFp3wqqzzL-kAP8mgxDZ54Bd5Ijf6ENi5YJlGBgcXw,2402
|
62
62
|
siat/google_authenticator.py,sha256=ZUbZR8OW0IAKDbcYtlqGqIpZdERpFor9NccFELxg9yI,1637
|
63
|
-
siat/grafix.py,sha256=
|
63
|
+
siat/grafix.py,sha256=HwtDRINvpfiWcrXsR5h6Ghvspitww5xRvP2eS4UfDFw,87465
|
64
64
|
siat/grafix_test.py,sha256=kXvcpLgQNO7wd30g_bWljLj5UH7bIVI0_dUtXbfiKR0,3150
|
65
65
|
siat/holding_risk.py,sha256=G3wpaewAKF9CwEqRpr4khyuDu9SU2EGyQUHdk7cmHOA,30693
|
66
66
|
siat/holding_risk_test.py,sha256=FRlw_9wFG98BYcg_cSj95HX5WZ1TvkGaOUdXD7-V86s,474
|
@@ -94,7 +94,7 @@ siat/risk_evaluation.py,sha256=I6B3gty-t--AkDCO0tKF-291YfpnF-IkXcFjqNKCt9I,76286
|
|
94
94
|
siat/risk_evaluation_test.py,sha256=YEXM96gKzTfwN4U61AS4Rr1tV7KgUvn4rRC6f3iMw9s,3731
|
95
95
|
siat/risk_free_rate.py,sha256=ZMr4cHikPvXvywr54gGqiI3Nvb69am6tq3zj2hwzANE,12384
|
96
96
|
siat/risk_free_rate_test.py,sha256=CpmhUf8aEAEZeNu4gvWP2Mz2dLoIgBX5bI41vfUBEr8,4285
|
97
|
-
siat/sector_china.py,sha256=
|
97
|
+
siat/sector_china.py,sha256=SV1YVue8Z5U-fkCok1U3VCIqUvmULfCOw0ao9IqjfQE,140528
|
98
98
|
siat/sector_china_test.py,sha256=1wq7ef8Bb_L8F0h0W6FvyBrIcBTEbrTV7hljtpj49U4,5843
|
99
99
|
siat/security_price.py,sha256=2oHskgiw41KMGfqtnA0i2YjNNV6cYgtlUK0j3YeuXWs,29185
|
100
100
|
siat/security_price2.py,sha256=Y4suVC-4koUSI_n8kY0l0y4lo_CTcoeM_kwTHiIFzyM,26291
|
@@ -139,8 +139,8 @@ siat/valuation_china.py,sha256=EkZQaVkoBjM0c4MCNbaX-bMnlG0e3FXeaWczZDnkptU,67784
|
|
139
139
|
siat/valuation_market_china_test.py,sha256=gbJ0ioauuo4koTPH6WKUkqcXiQPafnbhU5eKJ6lpdLA,1571
|
140
140
|
siat/var_model_validation.py,sha256=R0caWnuZarrRg9939hxh3vJIIpIyPfvelYmzFNZtPbo,14910
|
141
141
|
siat/yf_name.py,sha256=9U_XfEeMlS3TrCrO3Bww21nuFgghbnO-cqDJMhQWqew,16193
|
142
|
-
siat-3.4.
|
143
|
-
siat-3.4.
|
144
|
-
siat-3.4.
|
145
|
-
siat-3.4.
|
146
|
-
siat-3.4.
|
142
|
+
siat-3.4.37.dist-info/LICENSE,sha256=NTEMMROY9_4U1szoKC3N2BLHcDd_o5uTgqdVH8tbApw,1071
|
143
|
+
siat-3.4.37.dist-info/METADATA,sha256=pLBbjRdg6Rh44OSiG0qTvjJkpPtp-3MraR6Yy77FPPk,8010
|
144
|
+
siat-3.4.37.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
145
|
+
siat-3.4.37.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
|
146
|
+
siat-3.4.37.dist-info/RECORD,,
|
File without changes
|
File without changes
|