siat 3.0.44__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
@@ -25,12 +25,12 @@ if __name__=='__main__':
25
25
  quarter1='2022Q4'
26
26
  quarter2='2023Q1'
27
27
 
28
- df=fund_stock_holding_compare_china(fund,quarter1,quarter2,top=10)
28
+ df=fund_stock_holding_compare_china(fund,quarter1,quarter2,rank=10)
29
29
 
30
30
  #比较两个季度之间的基金持仓变化
31
- def fund_stock_holding_compare_china(fund,quarter1,quarter2,top=10):
31
+ def fund_stock_holding_compare_china(fund,quarter1,quarter2,rank=10):
32
32
  """
33
- 功能:基金fund在两个季度quarter1和quarter2的持仓股票对比(股数和金额),前top名股票
33
+ 功能:基金fund在两个季度quarter1和quarter2的持仓股票对比(股数和金额),前rank名股票
34
34
  参数:
35
35
  fund,str,基金代码;
36
36
  quarter1,str,靠前的季度, 格式为 'YYYYQ1',例如: '2021Q2';
@@ -130,10 +130,10 @@ def fund_stock_holding_compare_china(fund,quarter1,quarter2,top=10):
130
130
  df_merge = df_merge[['股票代码', '股票名称', s1_share,s1_value, s1_ratio,s2_share,s2_value,s2_ratio, '持股数变化']]
131
131
 
132
132
  df_merge.reset_index(drop=True,inplace=True)
133
- if top>0:
134
- df=df_merge.head(top)
133
+ if rank>0:
134
+ df=df_merge.head(rank)
135
135
  else:
136
- df=df_merge.head(-top)
136
+ df=df_merge.head(-rank)
137
137
  """
138
138
  #持股数和持仓比例取整数
139
139
  df.fillna(0)
@@ -171,14 +171,14 @@ def fund_stock_holding_compare_china(fund,quarter1,quarter2,top=10):
171
171
  name=get_fund_name_china2(fund)
172
172
 
173
173
  order='前'
174
- if top <0:
174
+ if rank <0:
175
175
  order='后'
176
- top=-top
176
+ rank=-rank
177
177
 
178
178
  # 替换空值
179
179
  df.fillna('---')
180
180
 
181
- print("===== 中国基金持仓股票分析:"+name+','+s1+"对比"+s2,"(按后者持仓比例高低排列,"+order+str(top)+"名股票) =====\n")
181
+ print("===== 中国基金持仓股票分析:"+name+','+s1+"对比"+s2,"(按后者持仓比例高低排列,"+order+str(rank)+"名股票) =====\n")
182
182
  print(df.to_string(index=False))
183
183
  import datetime; today = datetime.date.today()
184
184
  print("\n*** 注:持股数为万股,持仓市值为万元,持仓比例为占基金资产净值比例%,包括A股与非A股")
@@ -329,9 +329,9 @@ def fund_stock_holding_rank_china(fund,year_num=2):
329
329
  #==============================================================================
330
330
  if __name__=='__main__':
331
331
  fund='180801'
332
- top=10
332
+ rank=10
333
333
 
334
- def reits_jsl_china(fund='',top=10):
334
+ def reits_jsl_china(fund='',rank=10):
335
335
  """
336
336
  功能:REITs基金信息概述和列表
337
337
  目前不能正常工作,因为集思录数据源现在需要会员登陆才能显示和下载信息
@@ -358,10 +358,10 @@ def reits_jsl_china(fund='',top=10):
358
358
  dfa=df[df['代码']==fund]
359
359
  # 未找到
360
360
  if len(dfa)==0:
361
- if top > 0:
362
- dfa=df.head(top)
361
+ if rank > 0:
362
+ dfa=df.head(rank)
363
363
  else:
364
- dfa=df.tail(-top)
364
+ dfa=df.tail(-rank)
365
365
  dfb=dfa[['代码','名称','昨收','规模(亿元)','到期日']]
366
366
 
367
367
  #设置打印对齐
@@ -372,10 +372,10 @@ def reits_jsl_china(fund='',top=10):
372
372
  pd.set_option('display.unicode.east_asian_width', True)
373
373
 
374
374
  order='前'
375
- if top <0:
375
+ if rank <0:
376
376
  order='后'
377
- top=-top
378
- print("\n===== 中国REITs基金列表(按最新价高低排列,"+order+str(top)+"名) =====\n")
377
+ rank=-rank
378
+ print("\n===== 中国REITs基金列表(按最新价高低排列,"+order+str(rank)+"名) =====\n")
379
379
  print(dfb)
380
380
 
381
381
  print("*** 数据来源:东方财富/集思录, 总计"+str(num)+"只REITs基金,",today)
@@ -399,14 +399,14 @@ def reits_jsl_china(fund='',top=10):
399
399
 
400
400
  #==============================================================================
401
401
  if __name__=='__main__':
402
- top=10
402
+ rank=10
403
403
 
404
- df=reits_list_china(top=10)
404
+ df=reits_list_china(rank=10)
405
405
 
406
- def reits_list_china(top=20):
406
+ def reits_list_china(rank=10,sort='最新价'):
407
407
  """
408
408
  功能:REITs基金信息概述和列表
409
- 目前不能正常工作,因为数据源集思录现在需要会员登陆才能显示信息
409
+ 目前能正常工作
410
410
  """
411
411
  import akshare as ak
412
412
  try:
@@ -414,11 +414,18 @@ def reits_list_china(top=20):
414
414
  except:
415
415
  print(" #Error(reits_profile_china): akshare does not work properly now")
416
416
  return None
417
+ df2.drop('序号', axis=1, inplace=True)
418
+
419
+ sortlist=list(df2)
420
+ if sort not in sortlist:
421
+ print(" #Error(reits_list_china):",sort,"is not supported")
422
+ print(" Supported sort method:",sortlist)
423
+ return None
417
424
 
418
425
  #df2.sort_values(by=['昨收'],ascending=False,inplace=True)
419
- df2.sort_values(by=['最新价'],ascending=False,inplace=True)
426
+ df2.sort_values(by=[sort],ascending=False,inplace=True)
420
427
  df2.reset_index(drop=True,inplace=True)
421
- df2['序号']=df2.index + 1
428
+ #df2['序号']=df2.index + 1
422
429
  num=len(df2)
423
430
 
424
431
  #设置打印对齐
@@ -428,22 +435,24 @@ def reits_list_china(top=20):
428
435
  pd.set_option('display.unicode.ambiguous_as_wide', True)
429
436
  pd.set_option('display.unicode.east_asian_width', True)
430
437
 
431
- if top > 0:
438
+ if rank > 0:
432
439
  order='前'
433
- dfb=df2.head(top)
440
+ dfb=df2.head(rank)
434
441
  else:
435
442
  order='后'
436
- top=-top
437
- dfb=df2.tail(top)
443
+ rank=-rank
444
+ dfb=df2.tail(rank)
438
445
 
439
446
  dfb.fillna("---",inplace=True)
440
447
  dfb['成交额']=dfb['成交额'].apply(lambda x: int(x))
441
448
 
442
- print("\n===== 中国REITs基金列表(按最新价高低排列,"+order+str(top)+"名) =====\n")
449
+ #print("\n===== 中国REITs基金列表(按最新价高低排列,"+order+str(rank)+"名) =====\n")
450
+ titletxt="中国REITs基金列表(按"+sort+"降序排列,"+order+str(rank)+"名)"
443
451
  """
444
452
  print(dfb.to_string(index=False))
445
453
  """
446
454
  #print('') #在标题与表格之间空一行
455
+ """
447
456
  alignlist=['right','center','left']+['right']*9
448
457
  try:
449
458
  print(dfb.to_markdown(index=False,tablefmt='plain',colalign=alignlist))
@@ -452,10 +461,16 @@ def reits_list_china(top=20):
452
461
  print_df=dfb.to_markdown(index=False,tablefmt='plain',colalign=alignlist)
453
462
  print_df2=print_df.encode("utf-8",errors="strict")
454
463
  print(print_df2)
455
-
456
- import datetime
457
- today = datetime.date.today()
458
- print("\n*** 数据来源:东方财富, 总计"+str(num)+"只REITs基金,",today)
464
+ """
465
+ import datetime; todaydt = datetime.date.today()
466
+ #print("\n*** 数据来源:东方财富, 总计"+str(num)+"只REITs基金,",today)
467
+ footnote="数据来源:东方财富, 总计"+str(num)+"只REITs基金,"+str(todaydt)
468
+
469
+ df_display_CSS(dfb,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=3, \
470
+ first_col_align='left',second_col_align='left', \
471
+ last_col_align='right',other_col_align='right', \
472
+ titile_font_size='16px',heading_font_size='15px', \
473
+ data_font_size='15px')
459
474
 
460
475
  return df2
461
476
 
@@ -466,7 +481,7 @@ if __name__=='__main__':
466
481
  fund_type='债券型'
467
482
  printout=True
468
483
 
469
- def pof_list_china(fund_type='全部类型',printout=True):
484
+ def pof_list_china(rank=10,fund_type='全部类型',printout=True):
470
485
  """
471
486
  功能:抓取公募基金列表,按照基金类型列表,按照基金名称拼音排序
472
487
  """
@@ -478,7 +493,9 @@ def pof_list_china(fund_type='全部类型',printout=True):
478
493
  df = ak.fund_name_em()
479
494
 
480
495
  df.sort_values(by=['拼音全称'],na_position='first',inplace=True)
481
- df.drop_duplicates(subset=['基金代码','基金类型'], keep='first',inplace=True)
496
+ df.drop_duplicates(subset=['基金代码','基金类型'], keep='first',inplace=True)
497
+ df=df[df['基金类型'] != '']
498
+ df['基金类型']=df['基金类型'].apply(lambda x: x.upper())
482
499
 
483
500
  #获取基金类型列表,并去掉重复项
484
501
  typelist=list(set(list(df['基金类型'])))
@@ -500,6 +517,7 @@ def pof_list_china(fund_type='全部类型',printout=True):
500
517
  df2=df[df['基金类型'].apply(lambda x: fund_type in x)]
501
518
  else:
502
519
  df2=df
520
+
503
521
  df3=df2[['基金简称','基金代码','基金类型']]
504
522
  df3.reset_index(drop=True,inplace=True)
505
523
 
@@ -510,10 +528,9 @@ def pof_list_china(fund_type='全部类型',printout=True):
510
528
  print(texttranslate("共找到")+str(num)+texttranslate("支基金, 类型为")+fund_type)
511
529
  return df3
512
530
 
513
- print("\n",texttranslate("======= 中国公募基金种类概况 ======="))
514
- print(texttranslate("公募基金总数:"),"{:,}".format(num))
515
- print(texttranslate("其中包括:"))
516
-
531
+ titletxt="中国公募基金的类型与分布(前"+str(rank)+"名)"
532
+ footnote1="共有"+str(len(typelist))+"种类型,"+str("{:,}".format(num))+'支基金\n'
533
+
517
534
  maxlen=0
518
535
  for t in typelist:
519
536
  tlen=hzlen(t)
@@ -521,26 +538,34 @@ def pof_list_china(fund_type='全部类型',printout=True):
521
538
  maxlen=maxlen+1
522
539
 
523
540
  #排序
524
- dfg=pd.DataFrame(df.groupby("基金类型").size())
525
- 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
+
526
545
  typelist2=list(dfg.index)
527
546
  try:
528
547
  typelist2.remove('')
529
548
  except:
530
549
  pass
531
550
 
532
- for t in typelist2:
533
- n=len(df[df['基金类型']==t])
534
- """
535
- tlen=strlen(t)
536
- prefix=' '*4+t+' '*(maxlen-tlen)+':'
537
- print(prefix,"{:,}".format(n),"\b,",round(n/num*100,2),'\b%')
538
- """
539
- print('{t:<{len}}\t'.format(t=t,len=maxlen-len(t.encode('GBK'))+len(t)+2),str(n).rjust(6,' '),"\t",(str(round(n/num*100,2))+'%').rjust(6,' '))
551
+ dfg.rename(columns={0:'基金数量'}, inplace=True)
552
+ dfg['数量占比']=dfg['基金数量'].apply(lambda x: str(round(x/num*100,3))+'%')
553
+ dfg.reset_index(inplace=True)
554
+
555
+ collist=list(dfg)
556
+ dfg['序号']=dfg.index+1
557
+ dfg=dfg[['序号']+collist]
540
558
 
541
- import datetime
542
- today = datetime.date.today()
543
- print(texttranslate("数据来源:东方财富/天天基金,"),today)
559
+ footnote2="表中类型的数量占比为"+str(round(dfg['基金数量'].sum()/num*100,2))+"%\n"
560
+ import datetime; todaydt = datetime.date.today()
561
+ footnote9="数据来源:东方财富/天天基金,"+str(todaydt)
562
+ footnote=footnote1+footnote2+footnote9
563
+
564
+ df_display_CSS(dfg,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=3, \
565
+ first_col_align='center',second_col_align='left', \
566
+ last_col_align='right',other_col_align='right', \
567
+ titile_font_size='16px',heading_font_size='15px', \
568
+ data_font_size='15px')
544
569
 
545
570
  return df3
546
571
 
@@ -569,13 +594,19 @@ def oef_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
569
594
  df1 = ak.fund_open_fund_daily_em()
570
595
  collist=list(df1)
571
596
  nvname1=collist[2]
572
- nvdate=nvname1[:10]
573
597
  nvname2=collist[3]
598
+ if df1[nvname1].isna().all() or df1[nvname1].eq(0).all() or df1[nvname1].eq('').all():
599
+ nvname1=collist[4]
600
+ nvname2=collist[5]
601
+ nvdate=nvname1[:10]
602
+
603
+ df1x=df1[df1[nvname1] != '']
604
+
574
605
  #修改列名
575
- df1.rename(columns={nvname1:'单位净值',nvname2:'累计净值'}, inplace=True)
606
+ df1x.rename(columns={nvname1:'单位净值',nvname2:'累计净值'}, inplace=True)
576
607
  #df1a=df1.drop(df1[df1['单位净值']==''].index)
577
608
  #df1b=df1a.drop(df1a[df1a['累计净值']==''].index)
578
- df1c=df1[['基金代码','基金简称','单位净值','累计净值','日增长率','申购状态','赎回状态','手续费']]
609
+ df1c=df1x[['基金代码','基金简称','单位净值','累计净值','日增长率','申购状态','赎回状态','手续费']]
579
610
 
580
611
 
581
612
  #获取所有公募基金类型信息
@@ -634,23 +665,27 @@ def oef_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
634
665
  df['单位净值']=df['单位净值'].apply(lambda x: round(x,2))
635
666
  df.sort_values(by=['单位净值'],ascending=False,inplace=True)
636
667
  dfprint=df[['基金简称','基金代码','基金类型','单位净值','申购状态','赎回状态']]
637
- print(texttranslate("\n===== 中国开放式基金排名:单位净值 ====="))
668
+ #print(texttranslate("\n===== 中国开放式基金排名:单位净值 ====="))
669
+ titletxt="中国开放式基金排名:单位净值"
638
670
 
639
671
  if info_type == '累计净值':
640
672
  df['累计净值']=df['累计净值'].apply(lambda x: round(x,2))
641
673
  df.sort_values(by=['累计净值'],ascending=False,inplace=True)
642
674
  dfprint=df[['基金简称','基金代码','基金类型','累计净值','申购状态','赎回状态']]
643
- print(texttranslate("\n===== 中国开放式基金排名:累计净值 ====="))
675
+ #print(texttranslate("\n===== 中国开放式基金排名:累计净值 ====="))
676
+ titletxt="中国开放式基金排名:累计净值"
644
677
 
645
678
  if info_type == '手续费':
646
679
  df.sort_values(by=['手续费'],ascending=False,inplace=True)
647
680
  dfprint=df[['基金简称','基金代码','基金类型','手续费','申购状态','赎回状态']]
648
- print(texttranslate("\n===== 中国开放式基金排名:手续费 ====="))
681
+ #print(texttranslate("\n===== 中国开放式基金排名:手续费 ====="))
682
+ titletxt="中国开放式基金排名:手续费"
649
683
 
650
684
  if info_type == '增长率':
651
685
  df.sort_values(by=['日增长率'],ascending=False,inplace=True)
652
686
  dfprint=df[['基金简称','基金代码','基金类型','日增长率','申购状态','赎回状态']]
653
- print(texttranslate("\n===== 中国开放式基金排名:增长率% ====="))
687
+ #print(texttranslate("\n===== 中国开放式基金排名:增长率% ====="))
688
+ titletxt="中国开放式基金排名:增长率%"
654
689
 
655
690
  df=df.replace(0,'--')
656
691
 
@@ -676,6 +711,7 @@ def oef_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
676
711
  """
677
712
  alignlist=['left','left']+['center']*(len(list(amac_sum_df.head(10)))-3)+['right']
678
713
  """
714
+ """
679
715
  print('') #在标题与表格之间空一行
680
716
  alignlist=['right','left','center','center','right','center','center']
681
717
  try:
@@ -693,6 +729,19 @@ def oef_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
693
729
  import datetime
694
730
  today = datetime.date.today()
695
731
  print(texttranslate("数据来源:东方财富/天天基金,"),today)
732
+ """
733
+ footnote1="披露净值的开放式基金数量:"+str(len(dfprint))+','
734
+ footnote2="基金类型:"+str(fund_type)+'\n'
735
+ footnote3="净值日期:"+str(nvdate)+','
736
+ import datetime; todaydt = datetime.date.today()
737
+ footnote4="数据来源:东方财富/天天基金,"+str(todaydt)
738
+ footnote=footnote1+footnote2+footnote3+footnote4
739
+
740
+ df_display_CSS(dfprint10,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=4, \
741
+ first_col_align='left',second_col_align='right', \
742
+ last_col_align='right',other_col_align='right', \
743
+ titile_font_size='16px',heading_font_size='15px', \
744
+ data_font_size='15px')
696
745
 
697
746
  return df
698
747
 
@@ -731,19 +780,20 @@ def get_oef_name_china(fund_code):
731
780
  if __name__=='__main__':
732
781
  fund='050111.SS'
733
782
  fund='000592.SS'
734
- fromdate='2020-9-1'
735
- todate='2021-9-1'
783
+ start='MRM'
784
+ end='today'
736
785
  trend_type='净值'
737
786
  power=0
738
787
  twinx=False
739
788
  zeroline=False
740
789
 
741
- def oef_trend_china(fund,fromdate,todate,trend_type='净值', \
790
+ def oef_trend_china(fund,start,end='today',trend_type='净值', \
742
791
  power=0,twinx=False, \
743
792
  loc1='upper left',loc2='lower left'):
744
793
  """
745
794
  功能:开放式基金业绩趋势,单位净值,累计净值,近三个月收益率,同类排名,总排名
746
795
  """
796
+ fromdate,todate=start_end_preprocess(start,end)
747
797
  #检查走势类型
748
798
  trendlist=["净值","收益率","排名"]
749
799
  if trend_type not in trendlist:
@@ -770,9 +820,10 @@ def oef_trend_china(fund,fromdate,todate,trend_type='净值', \
770
820
  source=texttranslate("数据来源:东方财富/天天基金")
771
821
 
772
822
  fund1=fund[:6]
773
- fund_name=ticker_name(fund1,ticker_type)
823
+ fund_name=ticker_name(fund1,'fund')
774
824
 
775
825
  #绘制单位/累计净值对比图
826
+ import pandas as pd
776
827
  if trend_type == '净值':
777
828
  df1 = ak.fund_open_fund_info_em(fund1, indicator="单位净值走势")
778
829
  df1.rename(columns={'净值日期':'date','单位净值':'单位净值'}, inplace=True)
@@ -784,8 +835,9 @@ def oef_trend_china(fund,fromdate,todate,trend_type='净值', \
784
835
  df2.set_index(['date'],inplace=True)
785
836
 
786
837
  #合并
787
- import pandas as pd
788
838
  df = pd.merge(df1,df2,left_index=True,right_index=True,how='inner')
839
+ df['日期']=df['日期'].apply(lambda x: pd.to_datetime(x))
840
+
789
841
  dfp=df[(df['日期'] >= start)]
790
842
  dfp=dfp[(dfp['日期'] <= end)]
791
843
  if len(dfp) == 0:
@@ -811,10 +863,11 @@ def oef_trend_china(fund,fromdate,todate,trend_type='净值', \
811
863
 
812
864
  #绘制累计收益率单线图
813
865
  if trend_type == '收益率':
814
- df = ak.fund_open_fund_info_em(fund=fund1, indicator="累计收益率走势")
815
- df.rename(columns={'净值日期':'date','累计收益率':'累计收益率'}, inplace=True)
816
- df['日期']=df['date']
866
+ df = ak.fund_open_fund_info_em(fund1, indicator="累计收益率走势")
867
+ #df.rename(columns={'净值日期':'date','累计收益率':'累计收益率'}, inplace=True)
868
+ df['date']=df['日期']
817
869
  df.set_index(['date'],inplace=True)
870
+ df['日期']=df['日期'].apply(lambda x: pd.to_datetime(x))
818
871
  dfp=df[(df['日期'] >= start)]
819
872
  dfp=dfp[(dfp['日期'] <= end)]
820
873
  if len(dfp) == 0:
@@ -830,7 +883,7 @@ def oef_trend_china(fund,fromdate,todate,trend_type='净值', \
830
883
 
831
884
  #绘制同类排名图:近三个月收益率
832
885
  if trend_type == '排名':
833
- df1 = ak.fund_open_fund_info_em(fund=fund1, indicator="同类排名走势")
886
+ df1 = ak.fund_open_fund_info_em(fund1, indicator="同类排名走势")
834
887
  df1.rename(columns={'报告日期':'date','同类型排名-每日近三月排名':'同类排名','总排名-每日近三月排名':'总排名'}, inplace=True)
835
888
  df1['日期']=df1['date']
836
889
  df1['总排名']=df1['总排名'].astype('int64')
@@ -841,8 +894,8 @@ def oef_trend_china(fund,fromdate,todate,trend_type='净值', \
841
894
  df2.set_index(['date'],inplace=True)
842
895
 
843
896
  #合并
844
- import pandas as pd
845
897
  df = pd.merge(df1,df2,left_index=True,right_index=True,how='inner')
898
+ df['日期']=df['日期'].apply(lambda x: pd.to_datetime(x))
846
899
  dfp=df[(df['日期'] >= start)]
847
900
  dfp=dfp[(dfp['日期'] <= end)]
848
901
  if len(dfp) == 0:
@@ -890,7 +943,9 @@ def mmf_rank_china(rank=10):
890
943
  #获取货币型基金实时信息
891
944
  df = ak.fund_money_fund_daily_em()
892
945
  collist=list(df)
893
- nvname=collist[6]
946
+ nvname=collist[3]
947
+ if df[nvname].eq('').all():
948
+ nvname=collist[6]
894
949
  nvdate=nvname[:10]
895
950
  #修改列名
896
951
  df.rename(columns={nvname:'7日年化%'}, inplace=True)
@@ -899,7 +954,8 @@ def mmf_rank_china(rank=10):
899
954
 
900
955
  dfb.sort_values(by=['7日年化%'],ascending=False,inplace=True)
901
956
  dfprint=dfb[['基金简称','基金代码','7日年化%','基金经理','手续费']]
902
- print(texttranslate("\n======= 中国货币型基金排名:7日年化收益率 ======="))
957
+ #print(texttranslate("\n======= 中国货币型基金排名:7日年化收益率 ======="))
958
+ titletxt="中国货币型基金排名:7日年化收益率"
903
959
 
904
960
  #设置打印对齐
905
961
  import pandas as pd
@@ -921,6 +977,7 @@ def mmf_rank_china(rank=10):
921
977
  """
922
978
  print(dfprint10)
923
979
  """
980
+ """
924
981
  print('') #在标题与表格之间空一行
925
982
  alignlist=['right','left','center','center','center','right']
926
983
  try:
@@ -938,6 +995,18 @@ def mmf_rank_china(rank=10):
938
995
  import datetime
939
996
  today = datetime.date.today()
940
997
  print(texttranslate("数据来源:东方财富/天天基金,"),today)
998
+ """
999
+ footnote1="披露收益率信息的货币型基金数量:"+str(len(dfprint))+'\n'
1000
+ footnote2="收益率日期:"+str(nvdate)+','
1001
+ import datetime; todaydt = datetime.date.today()
1002
+ footnote3="数据来源:东方财富/天天基金,"+str(todaydt)
1003
+ footnote=footnote1+footnote2+footnote3
1004
+
1005
+ df_display_CSS(dfprint10,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=4, \
1006
+ first_col_align='left',second_col_align='right', \
1007
+ last_col_align='right',other_col_align='right', \
1008
+ titile_font_size='16px',heading_font_size='15px', \
1009
+ data_font_size='15px')
941
1010
 
942
1011
  return df
943
1012
 
@@ -951,11 +1020,11 @@ if __name__=='__main__':
951
1020
  todate='2020-10-16'
952
1021
  power=0
953
1022
 
954
- def mmf_trend_china(fund,fromdate,todate,power=0):
1023
+ def mmf_trend_china(fund,start,end='today',power=0):
955
1024
  """
956
1025
  功能:货币型基金业绩趋势,7日年化收益率
957
1026
  """
958
-
1027
+ fromdate,todate=start_end_preprocess(start,end)
959
1028
  #检查日期
960
1029
  result,start,end=check_period(fromdate,todate)
961
1030
  if not result:
@@ -971,7 +1040,6 @@ def mmf_trend_china(fund,fromdate,todate,power=0):
971
1040
  #基金历史数据
972
1041
  import datetime; today = datetime.date.today()
973
1042
  source=texttranslate("数据来源:东方财富/天天基金")
974
-
975
1043
 
976
1044
  #绘制收益率单线图
977
1045
  fund1=fund[:6]
@@ -1029,8 +1097,12 @@ def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1029
1097
  #提取净值日期
1030
1098
  collist=list(df2)
1031
1099
  nvname1=collist[3]
1032
- nvdate=nvname1[:10]
1033
1100
  nvname2=collist[4]
1101
+ if df2[nvname1].eq('').all() or df2[nvname1].eq('---').all():
1102
+ nvname1=collist[5]
1103
+ nvname2=collist[6]
1104
+ nvdate=nvname1[:10]
1105
+
1034
1106
  #修改列名
1035
1107
  df3=df2.rename(columns={nvname1:'单位净值',nvname2:'累计净值'})
1036
1108
  df=df3[['基金简称','基金代码','类型','单位净值','累计净值','增长率','市价']]
@@ -1064,27 +1136,35 @@ def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1064
1136
  df['单位净值']=df['单位净值'].astype(float)
1065
1137
  df.sort_values(by=['单位净值'],ascending=False,inplace=True)
1066
1138
  dfprint=df[['基金简称','基金代码','类型','单位净值','市价']]
1067
- print(texttranslate("\n===== 中国ETF基金排名:单位净值 ====="))
1139
+ #print(texttranslate("\n===== 中国ETF基金排名:单位净值 ====="))
1140
+ titletxt="中国ETF基金排名:单位净值"
1141
+ dfprint=dfprint[dfprint['单位净值'] != 0]
1068
1142
 
1069
1143
  if info_type == '累计净值':
1070
1144
  df=df.replace('---',0)
1071
1145
  df['累计净值']=df['累计净值'].astype(float)
1072
1146
  df.sort_values(by=['累计净值'],ascending=False,inplace=True)
1073
1147
  dfprint=df[['基金简称','基金代码','类型','累计净值','单位净值']]
1074
- print(texttranslate("\n===== 中国ETF基金排名:累计净值 ====="))
1148
+ #print(texttranslate("\n===== 中国ETF基金排名:累计净值 ====="))
1149
+ titletxt="中国ETF基金排名:累计净值"
1150
+ dfprint=dfprint[dfprint['累计净值'] != 0]
1075
1151
 
1076
1152
  if info_type == '市价':
1077
1153
  df=df.replace('---',0)
1078
1154
  df['市价']=df['市价'].astype(float)
1079
1155
  df.sort_values(by=['市价'],ascending=False,inplace=True)
1080
1156
  dfprint=df[['基金简称','基金代码','类型','市价','单位净值']]
1081
- print(texttranslate("\n===== 中国ETF基金排名:市价 ====="))
1157
+ #print(texttranslate("\n===== 中国ETF基金排名:市价 ====="))
1158
+ titletxt="中国ETF基金排名:市价"
1159
+ dfprint=dfprint[dfprint['市价'] != 0]
1082
1160
 
1083
1161
  if info_type == '增长率':
1084
1162
  df['增长率']=df['增长率'].astype(str)
1085
1163
  df.sort_values(by=['增长率'],ascending=False,inplace=True)
1086
1164
  dfprint=df[['基金简称','基金代码','类型','增长率','市价','单位净值']]
1087
- print(texttranslate("\n===== 中国ETF基金排名:增长率 ====="))
1165
+ #print(texttranslate("\n===== 中国ETF基金排名:增长率 ====="))
1166
+ titletxt="中国ETF基金排名:增长率"
1167
+ dfprint=dfprint[dfprint['增长率'] != 0]
1088
1168
 
1089
1169
  #设置打印对齐
1090
1170
  import pandas as pd
@@ -1106,6 +1186,7 @@ def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1106
1186
  """
1107
1187
  print(dfprint10)
1108
1188
  """
1189
+ """
1109
1190
  print('') #在标题与表格之间空一行
1110
1191
  alignlist=['right','left','center','center','right','right']
1111
1192
  try:
@@ -1124,6 +1205,19 @@ def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1124
1205
  import datetime
1125
1206
  today = datetime.date.today()
1126
1207
  print(texttranslate("数据来源:东方财富/天天基金,"),today)
1208
+ """
1209
+ footnote1="披露净值信息的ETF基金数量:"+str(len(dfprint))+','
1210
+ footnote2="基金类型:"+str(fund_type)+'\n'
1211
+ footnote3="净值日期:"+str(nvdate)+','
1212
+ import datetime; todaydt = datetime.date.today()
1213
+ footnote4="数据来源:东方财富/天天基金,"+str(todaydt)
1214
+ footnote=footnote1+footnote2+footnote3+footnote4
1215
+
1216
+ df_display_CSS(dfprint10,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=3, \
1217
+ first_col_align='left',second_col_align='right', \
1218
+ last_col_align='right',other_col_align='right', \
1219
+ titile_font_size='16px',heading_font_size='15px', \
1220
+ data_font_size='15px')
1127
1221
 
1128
1222
  return df
1129
1223
 
@@ -1138,10 +1232,12 @@ if __name__=='__main__':
1138
1232
  fromdate='2020-1-1'
1139
1233
  todate='2020-10-16'
1140
1234
 
1141
- def etf_trend_china(fund,fromdate,todate,loc1='best',loc2='best',twinx=False,graph=True):
1235
+ def etf_trend_china(fund,start,end='today',loc1='best',loc2='best',twinx=False,graph=True):
1142
1236
  """
1143
1237
  功能:ETF基金业绩趋势,单位净值,累计净值
1144
1238
  """
1239
+ fromdate,todate=start_end_preprocess(start,end='today')
1240
+
1145
1241
  #检查日期
1146
1242
  result,start,end=check_period(fromdate,todate)
1147
1243
  if not result:
@@ -1167,7 +1263,8 @@ def etf_trend_china(fund,fromdate,todate,loc1='best',loc2='best',twinx=False,gra
1167
1263
  df.set_index(['date'],inplace=True)
1168
1264
  df['单位净值']=df['单位净值'].astype("float")
1169
1265
  df['累计净值']=df['累计净值'].astype("float")
1170
-
1266
+
1267
+ df['净值日期']=df['净值日期'].apply(lambda x: pd.to_datetime(x))
1171
1268
  dfp=df[(df['净值日期'] >= start)]
1172
1269
  dfp=dfp[(dfp['净值日期'] <= end)]
1173
1270
  if len(dfp) == 0:
@@ -1194,12 +1291,12 @@ if __name__=='__main__':
1194
1291
 
1195
1292
  #==============================================================================
1196
1293
 
1197
- def fund_summary_china():
1294
+ def fund_summary_china(rank=10):
1198
1295
  """
1199
1296
  功能:中国基金投资机构概况
1200
1297
  爬虫来源地址:https://zhuanlan.zhihu.com/p/97487003
1201
1298
  """
1202
- print("Searching for fund investment institutions in China ...")
1299
+ print("Searching for investment fund institutions in China ...")
1203
1300
  import akshare as ak
1204
1301
 
1205
1302
  #会员机构综合查询:
@@ -1211,7 +1308,7 @@ def fund_summary_china():
1211
1308
  try:
1212
1309
  amac_df = ak.amac_member_info()
1213
1310
  except:
1214
- print(" #Error(): data source tentatively inaccessible, try later")
1311
+ print(" #Error(fund_summary_china): data source tentatively inaccessible, try later")
1215
1312
  return None
1216
1313
 
1217
1314
  """
@@ -1220,96 +1317,49 @@ def fund_summary_china():
1220
1317
  '证券公司私募基金子公司','证券公司资管子公司','境外机构']
1221
1318
  """
1222
1319
  typelist=list(set(list(amac_df["机构类型"])))
1223
- """
1224
- maxlen=0
1225
- for t in typelist:
1226
- #tlen=strlen(t)
1227
- tlen=hzlen(t)
1228
- if tlen > maxlen: maxlen=tlen
1229
- maxlen=maxlen+1
1230
- """
1231
1320
 
1232
1321
  import pandas as pd
1233
- pd.set_option('display.max_columns',1000) # 设置最大显示列数的多少
1234
- pd.set_option('display.width',1000) # 设置宽度,就是说不换行,比较好看数据
1235
- pd.set_option('display.max_rows',500) # 设置行数的多少
1236
- pd.set_option('display.colheader_justify','left')
1237
-
1238
- print(texttranslate("\n===== 中国基金投资机构概况 ====="))
1239
- print(texttranslate("机构(会员)数量:"),end='')
1240
- num=len(list(set(list(amac_df["机构(会员)名称"]))))
1241
- print("{:,}".format(num))
1242
-
1243
- print(texttranslate("其中包括:"))
1244
- amac_sum_df=pd.DataFrame(columns=['机构类型','数量','占比%'])
1322
+ titletxt="中国基金机构类型与分布(前"+str(rank)+"名)"
1323
+
1324
+ amac_sum_df=pd.DataFrame(columns=['机构类型','机构数量','数量占比%'])
1325
+ totalnum=0
1245
1326
  for t in typelist:
1246
1327
  df_sub=amac_df[amac_df['机构类型']==t]
1247
1328
  n=len(list(set(list(df_sub['机构(会员)名称']))))
1248
- pct=round(n/num*100,2)
1329
+ if n==0: continue
1330
+ totalnum=totalnum+n
1249
1331
 
1250
- s=pd.Series({'机构类型':t,'数量':n,'占比%':pct})
1332
+ s=pd.Series({'机构类型':t,'机构数量':n})
1251
1333
  try:
1252
1334
  amac_sum_df=amac_sum_df.append(s,ignore_index=True)
1253
1335
  except:
1254
1336
  amac_sum_df=amac_sum_df._append(s,ignore_index=True)
1255
- """
1256
- tlen=hzlen(t)
1257
- prefix=' '*4+t+'.'*(maxlen-tlen)+':'
1258
- print(prefix,"{:,}".format(n),"\b,",round(n/num*100,2),'\b%')
1259
- """
1260
- #print('{t:<{len}}\t'.format(t=t,len=maxlen-len(t.encode('GBK'))+len(t)),"{:,}".format(n),"\b,",round(n/num*100,2),'\b%')
1261
- #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,' '))
1262
1337
 
1263
- 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)
1264
1341
  amac_sum_df.reset_index(drop=True,inplace=True)
1265
- amac_sum_df.index=amac_sum_df.index + 1
1266
- """
1267
- from IPython.display import display
1268
- display(amac_sum_df.head(10))
1269
- """
1270
- """
1271
- pandas2prettytable(amac_sum_df.head(10),titletxt='',firstColSpecial=True,leftColAlign='l',otherColAlign='c',tabborder=False)
1272
- """
1273
- alignlist=['left','left']+['center']*(len(list(amac_sum_df.head(10)))-3)+['right']
1274
- try:
1275
- print(amac_sum_df.head(10).to_markdown(index=True,tablefmt='plain',colalign=alignlist))
1276
- except:
1277
- #解决汉字编码gbk出错问题
1278
- print_df=amac_sum_df.head(10).to_markdown(index=True,tablefmt='plain',colalign=alignlist)
1279
- print_df2=print_df.encode("utf-8",errors="strict")
1280
- print(print_df2)
1342
+ amac_sum_df.index=amac_sum_df.index + 1
1281
1343
 
1282
- import datetime; today = datetime.date.today()
1283
- source=texttranslate("\n数据来源:中国证券投资基金业协会")
1284
- footnote=source+', '+str(today)
1285
- print(footnote)
1344
+ collist=list(amac_sum_df)
1345
+ amac_sum_df['序号']=amac_sum_df.index
1346
+ amac_sum_df=amac_sum_df[['序号']+collist]
1286
1347
 
1287
- """
1288
- print(texttranslate("\n===== 中国基金投资机构会员代表概况 ====="))
1289
- print(texttranslate("会员代表人数:"),end='')
1290
- num=len(list(set(list(amac_df["会员代表"]))))
1291
- print("{:,}".format(num))
1292
-
1293
- print(texttranslate("其中工作在:"))
1294
- amac_mbr_df=pd.DataFrame(columns=['机构类型','数量','占比%'])
1295
- for t in typelist:
1296
- df_sub=amac_df[amac_df['机构类型']==t]
1297
- n=len(list(set(list(df_sub['会员代表']))))
1298
- pct=round(n/num*100,2)
1299
-
1300
- s=pd.Series({'机构类型':t,'数量':n,'占比%':pct})
1301
- try:
1302
- amac_mbr_df=amac_sum_df.append(s,ignore_index=True)
1303
- except:
1304
- amac_mbr_df=amac_mbr_df._append(s,ignore_index=True)
1305
-
1306
- amac_mbr_df.sort_values(by=['数量'],ascending=False,inplace=True)
1307
- amac_mbr_df.reset_index(drop=True,inplace=True)
1308
- amac_mbr_df.index=amac_mbr_df.index + 1
1348
+ df10=amac_sum_df.head(rank)
1309
1349
 
1310
- pandas2prettytable(amac_mbr_df.head(10),titletxt='',firstColSpecial=True,leftColAlign='l',otherColAlign='c',tabborder=False)
1311
- print(footnote)
1312
- """
1350
+ footnote1="共有"+str(len(typelist))+'个类型,'
1351
+ footnote2=str(totalnum)+'家机构;'
1352
+ footnote3="表中类型数量占比"+str(round(df10['机构数量'].sum()/totalnum*100,2))+'%\n'
1353
+
1354
+ import datetime; todaydt = datetime.date.today()
1355
+ footnote9="数据来源:中国证券投资基金业协会,"+str(todaydt)
1356
+ footnote=footnote1+footnote2+footnote3+footnote9
1357
+
1358
+ df_display_CSS(df10,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=2, \
1359
+ first_col_align='center',second_col_align='left', \
1360
+ last_col_align='right',other_col_align='right', \
1361
+ titile_font_size='16px',heading_font_size='15px', \
1362
+ data_font_size='15px')
1313
1363
 
1314
1364
  return amac_df
1315
1365
 
@@ -1495,12 +1545,13 @@ if __name__=='__main__':
1495
1545
  step_page_list=[100,10,1]
1496
1546
  DEBUG=True
1497
1547
 
1498
- def get_pef_product_china(max_pages=2000,step_page_list=[200,10,1],DEBUG=True):
1548
+ def get_pef_product_china(max_pages=2000,step_page_list=[100,20,1],DEBUG=True):
1499
1549
  """
1500
1550
  功能:获取中国私募基金产品运营方式和状态信息,耗时较长
1501
1551
  注意:由于获取过程极易失败,因此分割为三个阶段进行下载,然后合成。
1502
1552
  """
1503
- print(" Searching pef info repeatedly, may need several hours, please wait ...")
1553
+ print(" Downloading in pages, which takes long time upon network stability and speed")
1554
+ print(" If a download is stuck, RESTART Python kernel or even Jupyter, then run again")
1504
1555
  import pandas as pd
1505
1556
 
1506
1557
  # 第1步:页数跨度最大
@@ -1559,88 +1610,134 @@ def get_pef_product_china(max_pages=2000,step_page_list=[200,10,1],DEBUG=True):
1559
1610
  #==============================================================================
1560
1611
 
1561
1612
 
1562
- def pef_product_china(DEBUG=False):
1613
+ def pef_product_china(rank=20,facecolor='papayawhip',DEBUG=False):
1563
1614
 
1564
1615
  """
1565
1616
  功能:中国私募基金管理人的产品管理概况
1566
1617
  爬虫来源地址:https://zhuanlan.zhihu.com/p/97487003
1618
+ 注意:下载数据需要极长时间,极少完全成功,谨慎运行!
1567
1619
  """
1568
- print("Searching for private equity fund (PEF) info in China, it may take hours ...")
1620
+ print("Searching for private equity fund (PEF) info in China ...")
1569
1621
  import akshare as ak
1570
1622
  import pandas as pd
1571
1623
 
1572
1624
  #私募基金管理人基金产品
1573
- product_df = get_pef_product_china(max_pages=2200,step_page_list=[200,10,1],DEBUG=False)
1574
-
1575
- print(texttranslate("\n== 中国私募基金管理人的产品与运营概况 =="))
1576
- print(texttranslate("产品数量:"),end='')
1577
- num=len(list(product_df["基金名称"]))
1578
- print("{:,}".format(num))
1579
-
1580
- #管理类型
1581
- print(texttranslate("产品的运营方式分布:"))
1582
- #typelist=list(set(list(product_df['私募基金管理人类型'])))
1583
- typelist=['受托管理','顾问管理','自我管理']
1625
+ product_df = get_pef_product_china(max_pages=2200,step_page_list=[100,22,1],DEBUG=False)
1626
+ product_df['私募基金管理人类型']=product_df['私募基金管理人类型'].apply(lambda x: '方式不明' if x=='' or x is None else x)
1627
+ product_df['运行状态']=product_df['运行状态'].apply(lambda x: '状态不明' if x=='' or x is None else x)
1628
+
1629
+ #num=len(list(product_df["基金名称"])) #统计可能有问题,原因不明
1630
+ #footnote1="找到产品数量:"+str("{:,}".format(num))+'\n'
1631
+ import datetime; todaydt = datetime.date.today()
1632
+ footnote9="数据来源:中国证券投资基金业协会,"+str(todaydt)
1633
+
1634
+ # 产品运营方式==============================================================
1635
+ titletxt="中国私募基金管理人的产品运营方式"
1636
+
1637
+ #typelist=['受托管理','顾问管理','自我管理']
1638
+ typelist=list(set(list(product_df['私募基金管理人类型'])))
1639
+ dfprint=pd.DataFrame(columns=['运营方式','产品数量','数量占比%'])
1640
+ totalnum=0
1584
1641
  for t in typelist:
1585
1642
  df_sub=product_df[product_df['私募基金管理人类型']==t]
1586
1643
  n=len(list(set(list(df_sub['基金名称']))))
1587
- prefix=' '*4+t+':'
1588
- print(prefix,"{:,}".format(n),"\b,",round(n/num*100,2),'\b%')
1589
-
1590
- #运行状态
1591
- print(texttranslate("产品的运营状态分布:"))
1592
- """
1644
+ totalnum=totalnum+n
1645
+
1646
+ s=pd.Series({'运营方式':t,'产品数量':n})
1647
+ try:
1648
+ dfprint=dfprint.append(s,ignore_index=True)
1649
+ except:
1650
+ dfprint=dfprint._append(s,ignore_index=True)
1651
+
1652
+ dfprint['数量占比%']=dfprint['产品数量'].apply(lambda x: round(x/totalnum*100,3))
1653
+ dfprint['产品数量']=dfprint['产品数量'].apply(lambda x: str("{:,}".format(x)))
1654
+
1655
+ dfprint.sort_values(by=['数量占比%'],ascending=False,inplace=True)
1656
+ dfprint.reset_index(drop=True,inplace=True)
1657
+ dfprint.index=dfprint.index + 1
1658
+ collist=list(dfprint)
1659
+ dfprint['序号']=dfprint.index
1660
+ dfprint=dfprint[['序号']+collist]
1661
+
1662
+ footnote1="找到管理产品"+str("{:,}".format(totalnum))+'个\n'
1663
+ footnote=footnote1+footnote9
1664
+
1665
+ df_display_CSS(dfprint,titletxt=titletxt,footnote=footnote,facecolor=facecolor,decimals=3, \
1666
+ first_col_align='center',second_col_align='left', \
1667
+ last_col_align='right',other_col_align='right', \
1668
+ titile_font_size='16px',heading_font_size='15px', \
1669
+ data_font_size='15px')
1670
+
1671
+ #运营状态===================================================================
1672
+ titletxt="中国私募基金管理人的产品运营状态"
1593
1673
  typelist=list(set(list(product_df['运行状态'])))
1594
- typelist=['状态不明' if i =='' else i for i in typelist]
1595
- """
1596
- typelist=['正在运作','提前清算','正常清算','延期清算','投顾协议已终止','']
1597
- maxlen=0
1598
- for t in typelist:
1599
- tlen=strlen(t)
1600
- if tlen > maxlen: maxlen=tlen
1601
- maxlen=maxlen+1
1602
-
1674
+ dfprint=pd.DataFrame(columns=['运营状态','产品数量','数量占比%'])
1675
+ totalnum=0
1603
1676
  for t in typelist:
1604
1677
  df_sub=product_df[product_df['运行状态']==t]
1605
1678
  n=len(list(set(list(df_sub['基金名称']))))
1606
- if t =='': t='状态不明'
1607
- tlen=strlen(t)
1608
- prefix=' '*4+t+' '*(maxlen-tlen)+':'
1609
- print(prefix,"{:,}".format(n),"\b,",round(n/num*100,2),'\b%')
1610
-
1611
- import datetime; today = datetime.date.today()
1612
- source=texttranslate("数据来源:中国证券投资基金业协会")
1613
- footnote=source+', '+str(today)
1614
- print(footnote)
1615
-
1616
- #推出产品数量排行
1617
- print(texttranslate("\n===== 中国推出产品数量最多的私募基金管理人 ====="))
1679
+ if n==0: continue
1680
+ totalnum=totalnum+n
1681
+
1682
+ s=pd.Series({'运营状态':t,'产品数量':n})
1683
+ try:
1684
+ dfprint=dfprint.append(s,ignore_index=True)
1685
+ except:
1686
+ dfprint=dfprint._append(s,ignore_index=True)
1687
+
1688
+ dfprint['数量占比%']=dfprint['产品数量'].apply(lambda x: round(x/totalnum*100,3))
1689
+ dfprint['产品数量']=dfprint['产品数量'].apply(lambda x: str("{:,}".format(x)))
1690
+
1691
+ dfprint.sort_values(by=['数量占比%'],ascending=False,inplace=True)
1692
+ dfprint.reset_index(drop=True,inplace=True)
1693
+ dfprint.index=dfprint.index + 1
1694
+ collist=list(dfprint)
1695
+ dfprint['序号']=dfprint.index
1696
+ dfprint=dfprint[['序号']+collist]
1697
+
1698
+ footnote1="找到运营产品"+str("{:,}".format(totalnum))+'个\n'
1699
+ footnote=footnote1+footnote9
1700
+
1701
+ df_display_CSS(dfprint,titletxt=titletxt,footnote=footnote,facecolor=facecolor,decimals=3, \
1702
+ first_col_align='center',second_col_align='left', \
1703
+ last_col_align='right',other_col_align='right', \
1704
+ titile_font_size='16px',heading_font_size='15px', \
1705
+ data_font_size='15px')
1706
+
1707
+ #推出产品数量排行===========================================================
1708
+ titletxt="中国推出产品数量最多的私募基金管理人(前"+str(rank)+"名)"
1618
1709
  subttl=pd.DataFrame(product_df.groupby(by=['私募基金管理人名称'])['基金名称'].count())
1619
1710
  subttl.rename(columns={'基金名称':'产品数量'}, inplace=True)
1620
- subttl['占比‰']=round(subttl['产品数量']/num*1000.0,2)
1711
+ subttl['数量占比‰']=round(subttl['产品数量']/totalnum*1000.0,2)
1621
1712
  subttl.sort_values(by=['产品数量'],ascending=False,inplace=True)
1622
1713
  subttl.reset_index(inplace=True)
1623
1714
 
1624
1715
  subttl.index=subttl.index + 1
1625
- subttl10=subttl.head(10)
1626
-
1627
- #设置打印对齐
1628
- pd.set_option('display.max_columns', 1000)
1629
- pd.set_option('display.width', 1000)
1630
- pd.set_option('display.max_colwidth', 1000)
1631
- pd.set_option('display.unicode.ambiguous_as_wide', True)
1632
- pd.set_option('display.unicode.east_asian_width', True)
1716
+ subttl10=subttl.head(rank)
1633
1717
 
1634
- print(subttl10)
1718
+ dfprint=subttl10
1719
+ dfprint.sort_values(by=['数量占比‰'],ascending=False,inplace=True)
1720
+ dfprint.reset_index(drop=True,inplace=True)
1721
+ dfprint.index=dfprint.index + 1
1722
+ collist=list(dfprint)
1723
+ dfprint['序号']=dfprint.index
1724
+ dfprint=dfprint[['序号']+collist]
1635
1725
 
1636
- pctsum=round(subttl10['占比‰'].sum(),2)
1637
- print(texttranslate("上述产品总计占比:"),pctsum,'\b‰')
1638
- print(footnote)
1639
-
1640
- print(texttranslate("\n===== 中国私募基金管理人的产品托管概况 ====="))
1641
- #托管产品数量排行
1726
+ pctsum=round(subttl10['数量占比‰'].sum(),2)
1727
+ footnote1="找到产品"+str("{:,}".format(totalnum))+"个,上述产品合计占比"+str(pctsum)+'‰'+'\n'
1728
+ footnote=footnote1+footnote9
1729
+
1730
+ df_display_CSS(dfprint,titletxt=titletxt,footnote=footnote,facecolor=facecolor,decimals=2, \
1731
+ first_col_align='center',second_col_align='left', \
1732
+ last_col_align='right',other_col_align='right', \
1733
+ titile_font_size='16px',heading_font_size='15px', \
1734
+ data_font_size='15px')
1735
+
1736
+
1737
+ # 托管产品==================================================================
1738
+ titletxt="中国私募基金管理人的产品托管概况(前"+str(rank)+"名)"
1642
1739
  tnum=len(list(set(list(product_df['托管人名称']))))
1643
- print(texttranslate("托管机构数量:"),"{:,}".format(tnum))
1740
+ footnote1="找到产品"+str("{:,}".format(totalnum))+"个,托管机构"+str("{:,}".format(tnum))+'家\n'
1644
1741
 
1645
1742
  subttl=pd.DataFrame(product_df.groupby(by=['托管人名称'])['基金名称'].count())
1646
1743
  subttl.rename(columns={'基金名称':'产品数量'}, inplace=True)
@@ -1650,15 +1747,30 @@ def pef_product_china(DEBUG=False):
1650
1747
  subttl=subttl[subttl['托管人名称']!='']
1651
1748
  #subttl.drop(subttl.index[0], inplace=True) # 删除第1行
1652
1749
  subttl.reset_index(drop=True,inplace=True)
1653
- subttl['占比%']=round(subttl['产品数量']/num*100.0,2)
1750
+ subttl['数量占比%']=round(subttl['产品数量']/totalnum*100.0,3)
1654
1751
 
1655
1752
  subttl.index=subttl.index + 1
1656
- subttl10=subttl.head(10)
1657
-
1658
- pctsum=round(subttl10['占比%'].sum(),2)
1659
- print(subttl10)
1660
- print(texttranslate("上述金融机构托管产品总计占比:"),pctsum,'\b%')
1661
- print(footnote)
1753
+ subttl10=subttl.head(rank)
1754
+
1755
+ pctsum=round(subttl10['数量占比%'].sum(),2)
1756
+ #print(subttl10)
1757
+ #print(texttranslate("上述金融机构托管产品总计占比:"),pctsum,'\b%')
1758
+ footnote2="上述机构托管产品合计占比:"+str(pctsum)+'%\n'
1759
+ footnote=footnote1+footnote2+footnote9
1760
+
1761
+ dfprint=subttl10
1762
+ dfprint.sort_values(by=['数量占比%'],ascending=False,inplace=True)
1763
+ dfprint.reset_index(drop=True,inplace=True)
1764
+ dfprint.index=dfprint.index + 1
1765
+ collist=list(dfprint)
1766
+ dfprint['序号']=dfprint.index
1767
+ dfprint=dfprint[['序号']+collist]
1768
+
1769
+ df_display_CSS(dfprint,titletxt=titletxt,footnote=footnote,facecolor=facecolor,decimals=3, \
1770
+ first_col_align='center',second_col_align='left', \
1771
+ last_col_align='right',other_col_align='right', \
1772
+ titile_font_size='16px',heading_font_size='15px', \
1773
+ data_font_size='15px')
1662
1774
 
1663
1775
  return product_df
1664
1776
 
siat/security_prices.py CHANGED
@@ -1244,8 +1244,8 @@ def get_prices_yahoo(ticker,start,end,retry_count=3,pause=1):
1244
1244
 
1245
1245
  print(" Successfully retrieved",len(p),"records for",ticker,ptname)
1246
1246
 
1247
- #去掉时区
1248
- p=df_index_timezone_remove(p)
1247
+ #去掉时区
1248
+ p=df_index_timezone_remove(p)
1249
1249
 
1250
1250
  return p
1251
1251
 
@@ -1331,13 +1331,13 @@ def get_prices_yf(ticker,start,end,threads=False):
1331
1331
  if ptname == ticker: ptname=''
1332
1332
 
1333
1333
  print(" Successfully retrieved",len(p),"records for",ticker1,ptname)
1334
+
1335
+ #去掉时区
1336
+ p=df_index_timezone_remove(p)
1334
1337
  else:
1335
1338
  pass
1336
1339
  #print(" #Error(get_prices_yf):",ticker1,"not found or no prices in the period or inaccessible to yahoo")
1337
1340
 
1338
- #去掉时区
1339
- p=df_index_timezone_remove(p)
1340
-
1341
1341
  return p
1342
1342
 
1343
1343
  if __name__=='__main__':
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: siat
3
- Version: 3.0.44
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=vdri-FucJ39SDdnM0AWULN9biSaQVh-dnfM03AhOuZY,80880
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
@@ -95,7 +95,7 @@ siat/sector_china.py,sha256=QSNJclhzT6V9NidziMwwAs-Kk6f7nzdK6PiPGkKrBCk,111617
95
95
  siat/sector_china_test.py,sha256=1wq7ef8Bb_L8F0h0W6FvyBrIcBTEbrTV7hljtpj49U4,5843
96
96
  siat/security_price.py,sha256=2oHskgiw41KMGfqtnA0i2YjNNV6cYgtlUK0j3YeuXWs,29185
97
97
  siat/security_price2.py,sha256=kuYh0V5cqclkM6MjZUd-N361fv3oxGVVerYINuTzZrE,24622
98
- siat/security_prices.py,sha256=m_dWQ24Au9WMNOb1o0Igm6Sg1llz7kyIX3vSXrE5Jng,102705
98
+ siat/security_prices.py,sha256=gubx-HrlnkSTByIhMC9qB2fxTMJTTxW1DH9KDGX22dY,102741
99
99
  siat/security_prices_test.py,sha256=OEphoJ87NPKoNow1QA8EU_5MUYrJF-qKoWKNapVfZNI,10779
100
100
  siat/security_trend.py,sha256=o0vpWdrJkmODCP94X-Bvn-w7efHhj9HpUYBHtLl55D0,17240
101
101
  siat/security_trend2.py,sha256=4yBY3ve0Kddu95JemS02gfLbrHVN2_gl_irr5pA4F6w,24626
@@ -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.0.44.dist-info/METADATA,sha256=lpYsF83FvwNlChiPm7slWucBOXtr6f2JcxFVEiMDSps,1448
136
- siat-3.0.44.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
137
- siat-3.0.44.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
138
- siat-3.0.44.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