siat 3.1.1__py3-none-any.whl → 3.1.2__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/fund_china.py CHANGED
@@ -481,7 +481,7 @@ if __name__=='__main__':
481
481
  fund_type='债券型'
482
482
  printout=True
483
483
 
484
- def pof_list_china(fund_type='全部类型',printout=True):
484
+ def pof_list_china(rank=10,fund_type='全部类型',printout=True):
485
485
  """
486
486
  功能:抓取公募基金列表,按照基金类型列表,按照基金名称拼音排序
487
487
  """
@@ -517,6 +517,7 @@ def pof_list_china(fund_type='全部类型',printout=True):
517
517
  df2=df[df['基金类型'].apply(lambda x: fund_type in x)]
518
518
  else:
519
519
  df2=df
520
+
520
521
  df3=df2[['基金简称','基金代码','基金类型']]
521
522
  df3.reset_index(drop=True,inplace=True)
522
523
 
@@ -526,13 +527,9 @@ def pof_list_china(fund_type='全部类型',printout=True):
526
527
  if fund_type != '全部类型':
527
528
  print(texttranslate("共找到")+str(num)+texttranslate("支基金, 类型为")+fund_type)
528
529
  return df3
529
- """
530
- print("\n",texttranslate("======= 中国公募基金种类概况 ======="))
531
- print(texttranslate("公募基金总数:"),"{:,}".format(num))
532
- print(texttranslate("其中包括:"))
533
- """
534
- titletxt="中国公募基金的种类与分布概况"
535
- footnote1="【注】公募基金总数:"+str("{:,}".format(num))+'\n'
530
+
531
+ titletxt="中国公募基金的类型与分布(前"+str(rank)+"名)"
532
+ footnote1="共有"+str(len(typelist))+"种类型,"+str("{:,}".format(num))+'支基金\n'
536
533
 
537
534
  maxlen=0
538
535
  for t in typelist:
@@ -541,8 +538,10 @@ def pof_list_china(fund_type='全部类型',printout=True):
541
538
  maxlen=maxlen+1
542
539
 
543
540
  #排序
544
- dfg=pd.DataFrame(df.groupby("基金类型").size())
545
- dfg.sort_values(by=[0], ascending=False, inplace=True)
541
+ dfg0=pd.DataFrame(df.groupby("基金类型").size())
542
+ dfg0.sort_values(by=[0], ascending=False, inplace=True)
543
+ dfg=dfg0.head(rank)
544
+
546
545
  typelist2=list(dfg.index)
547
546
  try:
548
547
  typelist2.remove('')
@@ -556,11 +555,11 @@ def pof_list_china(fund_type='全部类型',printout=True):
556
555
  collist=list(dfg)
557
556
  dfg['序号']=dfg.index+1
558
557
  dfg=dfg[['序号']+collist]
559
-
558
+
559
+ footnote2="表中类型的数量占比为"+str(round(dfg['基金数量'].sum()/num*100,2))+"%\n"
560
560
  import datetime; todaydt = datetime.date.today()
561
- #print(texttranslate("数据来源:东方财富/天天基金,"),today)
562
- footnote2="数据来源:东方财富/天天基金,"+str(todaydt)
563
- footnote=footnote1+footnote2
561
+ footnote9="数据来源:东方财富/天天基金,"+str(todaydt)
562
+ footnote=footnote1+footnote2+footnote9
564
563
 
565
564
  df_display_CSS(dfg,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=3, \
566
565
  first_col_align='center',second_col_align='left', \
@@ -1292,12 +1291,12 @@ if __name__=='__main__':
1292
1291
 
1293
1292
  #==============================================================================
1294
1293
 
1295
- def fund_summary_china():
1294
+ def fund_summary_china(rank=10):
1296
1295
  """
1297
1296
  功能:中国基金投资机构概况
1298
1297
  爬虫来源地址:https://zhuanlan.zhihu.com/p/97487003
1299
1298
  """
1300
- print("Searching for fund investment institutions in China ...")
1299
+ print("Searching for investment fund institutions in China ...")
1301
1300
  import akshare as ak
1302
1301
 
1303
1302
  #会员机构综合查询:
@@ -1309,7 +1308,7 @@ def fund_summary_china():
1309
1308
  try:
1310
1309
  amac_df = ak.amac_member_info()
1311
1310
  except:
1312
- print(" #Error(): data source tentatively inaccessible, try later")
1311
+ print(" #Error(fund_summary_china): data source tentatively inaccessible, try later")
1313
1312
  return None
1314
1313
 
1315
1314
  """
@@ -1318,114 +1317,50 @@ def fund_summary_china():
1318
1317
  '证券公司私募基金子公司','证券公司资管子公司','境外机构']
1319
1318
  """
1320
1319
  typelist=list(set(list(amac_df["机构类型"])))
1321
- """
1322
- maxlen=0
1323
- for t in typelist:
1324
- #tlen=strlen(t)
1325
- tlen=hzlen(t)
1326
- if tlen > maxlen: maxlen=tlen
1327
- maxlen=maxlen+1
1328
- """
1329
1320
 
1330
1321
  import pandas as pd
1331
- pd.set_option('display.max_columns',1000) # 设置最大显示列数的多少
1332
- pd.set_option('display.width',1000) # 设置宽度,就是说不换行,比较好看数据
1333
- pd.set_option('display.max_rows',500) # 设置行数的多少
1334
- pd.set_option('display.colheader_justify','left')
1335
- """
1336
- print(texttranslate("\n===== 中国基金投资机构概况 ====="))
1337
- print(texttranslate("机构(会员)数量:"),end='')
1338
- num=len(list(set(list(amac_df["机构(会员)名称"]))))
1339
- print("{:,}".format(num))
1340
-
1341
- print(texttranslate("其中包括:"))
1342
- """
1343
- titletxt="中国基金投资机构概况"
1344
- num=len(list(set(list(amac_df["机构(会员)名称"]))))
1345
- footnote1="机构(会员)数量:"+str(num)
1346
-
1347
- amac_sum_df=pd.DataFrame(columns=['机构类型','数量','占比%'])
1322
+ titletxt="中国基金机构类型与分布(前"+str(rank)+"名)"
1323
+
1324
+ amac_sum_df=pd.DataFrame(columns=['机构类型','机构数量','数量占比%'])
1325
+ totalnum=0
1348
1326
  for t in typelist:
1349
1327
  df_sub=amac_df[amac_df['机构类型']==t]
1350
1328
  n=len(list(set(list(df_sub['机构(会员)名称']))))
1351
- pct=round(n/num*100,2)
1329
+ if n==0: continue
1330
+ totalnum=totalnum+n
1352
1331
 
1353
- s=pd.Series({'机构类型':t,'数量':n,'占比%':pct})
1332
+ s=pd.Series({'机构类型':t,'机构数量':n})
1354
1333
  try:
1355
1334
  amac_sum_df=amac_sum_df.append(s,ignore_index=True)
1356
1335
  except:
1357
1336
  amac_sum_df=amac_sum_df._append(s,ignore_index=True)
1358
- """
1359
- tlen=hzlen(t)
1360
- prefix=' '*4+t+'.'*(maxlen-tlen)+':'
1361
- print(prefix,"{:,}".format(n),"\b,",round(n/num*100,2),'\b%')
1362
- """
1363
- #print('{t:<{len}}\t'.format(t=t,len=maxlen-len(t.encode('GBK'))+len(t)),"{:,}".format(n),"\b,",round(n/num*100,2),'\b%')
1364
- #print('{t:<{len}}\t'.format(t=t,len=maxlen-len(t.encode('GBK'))+len(t)),str(n).rjust(6,' '),"\t",(str(round(n/num*100,2))+'%').rjust(6,' '))
1365
1337
 
1366
- amac_sum_df.sort_values(by=['数量'],ascending=False,inplace=True)
1338
+ amac_sum_df['数量占比%']=amac_sum_df['机构数量'].apply(lambda x: round(x/totalnum*100,2))
1339
+
1340
+ amac_sum_df.sort_values(by=['机构数量'],ascending=False,inplace=True)
1367
1341
  amac_sum_df.reset_index(drop=True,inplace=True)
1368
- amac_sum_df.index=amac_sum_df.index + 1
1369
- """
1370
- from IPython.display import display
1371
- display(amac_sum_df.head(10))
1372
- """
1373
- """
1374
- pandas2prettytable(amac_sum_df.head(10),titletxt='',firstColSpecial=True,leftColAlign='l',otherColAlign='c',tabborder=False)
1375
- """
1376
- """
1377
- alignlist=['left','left']+['center']*(len(list(amac_sum_df.head(10)))-3)+['right']
1378
- try:
1379
- print(amac_sum_df.head(10).to_markdown(index=True,tablefmt='plain',colalign=alignlist))
1380
- except:
1381
- #解决汉字编码gbk出错问题
1382
- print_df=amac_sum_df.head(10).to_markdown(index=True,tablefmt='plain',colalign=alignlist)
1383
- print_df2=print_df.encode("utf-8",errors="strict")
1384
- print(print_df2)
1342
+ amac_sum_df.index=amac_sum_df.index + 1
1343
+
1344
+ collist=list(amac_sum_df)
1345
+ amac_sum_df['序号']=amac_sum_df.index
1346
+ amac_sum_df=amac_sum_df[['序号']+collist]
1347
+
1348
+ df10=amac_sum_df.head(rank)
1349
+
1350
+ footnote1="共有"+str(len(typelist))+'个类型,'
1351
+ footnote2=str(totalnum)+'家机构;'
1352
+ footnote3="表中类型数量占比"+str(round(df10['机构数量'].sum()/totalnum*100,2))+'%\n'
1385
1353
 
1386
- import datetime; today = datetime.date.today()
1387
- source=texttranslate("\n数据来源:中国证券投资基金业协会")
1388
- footnote=source+', '+str(today)
1389
- print(footnote)
1390
- """
1391
1354
  import datetime; todaydt = datetime.date.today()
1392
- footnote2="数据来源:中国证券投资基金业协会,"+str(todaydt)
1393
- footnote=footnote1+'\n'+footnote2
1394
- df10=amac_sum_df.head(10)
1355
+ footnote9="数据来源:中国证券投资基金业协会,"+str(todaydt)
1356
+ footnote=footnote1+footnote2+footnote3+footnote9
1395
1357
 
1396
1358
  df_display_CSS(df10,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=2, \
1397
- first_col_align='left',second_col_align='right', \
1359
+ first_col_align='center',second_col_align='left', \
1398
1360
  last_col_align='right',other_col_align='right', \
1399
1361
  titile_font_size='16px',heading_font_size='15px', \
1400
1362
  data_font_size='15px')
1401
1363
 
1402
- """
1403
- print(texttranslate("\n===== 中国基金投资机构会员代表概况 ====="))
1404
- print(texttranslate("会员代表人数:"),end='')
1405
- num=len(list(set(list(amac_df["会员代表"]))))
1406
- print("{:,}".format(num))
1407
-
1408
- print(texttranslate("其中工作在:"))
1409
- amac_mbr_df=pd.DataFrame(columns=['机构类型','数量','占比%'])
1410
- for t in typelist:
1411
- df_sub=amac_df[amac_df['机构类型']==t]
1412
- n=len(list(set(list(df_sub['会员代表']))))
1413
- pct=round(n/num*100,2)
1414
-
1415
- s=pd.Series({'机构类型':t,'数量':n,'占比%':pct})
1416
- try:
1417
- amac_mbr_df=amac_sum_df.append(s,ignore_index=True)
1418
- except:
1419
- amac_mbr_df=amac_mbr_df._append(s,ignore_index=True)
1420
-
1421
- amac_mbr_df.sort_values(by=['数量'],ascending=False,inplace=True)
1422
- amac_mbr_df.reset_index(drop=True,inplace=True)
1423
- amac_mbr_df.index=amac_mbr_df.index + 1
1424
-
1425
- pandas2prettytable(amac_mbr_df.head(10),titletxt='',firstColSpecial=True,leftColAlign='l',otherColAlign='c',tabborder=False)
1426
- print(footnote)
1427
- """
1428
-
1429
1364
  return amac_df
1430
1365
 
1431
1366
 
@@ -1789,7 +1724,7 @@ def pef_product_china(rank=20,facecolor='papayawhip',DEBUG=False):
1789
1724
  dfprint=dfprint[['序号']+collist]
1790
1725
 
1791
1726
  pctsum=round(subttl10['数量占比‰'].sum(),2)
1792
- footnote1="找到产品"+str("{:,}".format(totalnum))+"个,上述产品合计占比"+str(pctsum)+'%'+'\n'
1727
+ footnote1="找到产品"+str("{:,}".format(totalnum))+"个,上述产品合计占比"+str(pctsum)+''+'\n'
1793
1728
  footnote=footnote1+footnote9
1794
1729
 
1795
1730
  df_display_CSS(dfprint,titletxt=titletxt,footnote=footnote,facecolor=facecolor,decimals=2, \
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: siat
3
- Version: 3.1.1
3
+ Version: 3.1.2
4
4
  Summary: Securities Investment Analysis Tools (siat)
5
5
  Home-page: https://pypi.org/project/siat/
6
6
  Author: Prof. WANG Dehong, International Business School, Beijing Foreign Studies University
@@ -52,7 +52,7 @@ siat/financials_test.py,sha256=HJ3CPo_Xckz2wXi3AEP6ZNWCF1Duc1pLi0Y10USiImc,23829
52
52
  siat/fred_test.py,sha256=KF50ssSbsfpa_kT6iuomD0vG4eXztAcOasZxg1OGX5w,1201
53
53
  siat/fund.py,sha256=wMDORsCBV8ZXfgwbtq-0bu3qqWY66dHnbqgllW0gWCo,24637
54
54
  siat/fund_china.pickle,sha256=QI3IjV46EeJ5ryO3xocmByc-6b_6_nDxgcXDhBHzop0,2380915
55
- siat/fund_china.py,sha256=e-Ngpm34Kby8CFkso3M6KA4MWOPSi-M9FxS8Nv7Yr5M,90910
55
+ siat/fund_china.py,sha256=RK2A111np2U8Jfi9S7Yt_yYa_iuxEy0mhTg24i3O4VU,87982
56
56
  siat/fund_china_test.py,sha256=-Bh6m0J0GPpIbYXx-H2vpzJoNFI6pE2C2jVPa8DazgE,6649
57
57
  siat/fund_test.py,sha256=V4ADb8Gsp8gyeFTwcgRsJBpnUih_O-Q2V1ILc5oKjK8,1116
58
58
  siat/future_china.py,sha256=F-HsIf2Op8Z22RzTjet1g8COzldgnMjFNSXsAkeGyWo,17595
@@ -132,7 +132,7 @@ siat/valuation.py,sha256=NKfeZMdDJOW42oLVHob6eSVBXUqlN1OCnnzwyGAst8c,48855
132
132
  siat/valuation_china.py,sha256=Tde2LzPDQy3Z7xOQQDw4ckQMPdROp_z0-GjFE6Z5_lI,67639
133
133
  siat/valuation_market_china_test.py,sha256=gbJ0ioauuo4koTPH6WKUkqcXiQPafnbhU5eKJ6lpdLA,1571
134
134
  siat/var_model_validation.py,sha256=f-oDewg7bPzyNanz_Y_jLH68NowAA3gXFehW_weKGG0,14898
135
- siat-3.1.1.dist-info/METADATA,sha256=9fUOM1J5SJKvPEnZpip7QZ4nd_W7tCtWaK6kSPCphNQ,1447
136
- siat-3.1.1.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
137
- siat-3.1.1.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
138
- siat-3.1.1.dist-info/RECORD,,
135
+ siat-3.1.2.dist-info/METADATA,sha256=22Vwc49Bl5YYuI9AR9Mgb8nqq7L8FwIvnFut8X854z8,1447
136
+ siat-3.1.2.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
137
+ siat-3.1.2.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
138
+ siat-3.1.2.dist-info/RECORD,,
File without changes