siat 3.1.2__py3-none-any.whl → 3.1.3__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 CHANGED
@@ -3866,4 +3866,14 @@ def df_index_timezone_remove(df):
3866
3866
 
3867
3867
  return df
3868
3868
  #==============================================================================
3869
+
3870
+ def df_swap_columns(df, col1, col2):
3871
+ """
3872
+ 功能:交换df中的两个列的位置
3873
+ """
3874
+ cols = df.columns.tolist()
3875
+ i1, i2 = cols.index(col1), cols.index(col2)
3876
+ cols[i2], cols[i1] = cols[i1], cols[i2]
3877
+
3878
+ return df[cols]
3869
3879
  #==============================================================================
siat/fund_china.py CHANGED
@@ -403,7 +403,7 @@ if __name__=='__main__':
403
403
 
404
404
  df=reits_list_china(rank=10)
405
405
 
406
- def reits_list_china(rank=10,sort='最新价'):
406
+ def reits_list_china(indicator='最新价',rank=10):
407
407
  """
408
408
  功能:REITs基金信息概述和列表
409
409
  目前能正常工作
@@ -415,26 +415,37 @@ def reits_list_china(rank=10,sort='最新价'):
415
415
  print(" #Error(reits_profile_china): akshare does not work properly now")
416
416
  return None
417
417
  df2.drop('序号', axis=1, inplace=True)
418
+ df2['成交额']=df2['成交额'].apply(lambda x: int(x))
419
+ df2.fillna("---",inplace=True)
418
420
 
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)
421
+ df2=df_swap_columns(df2, col1='代码', col2='名称')
422
+ num=len(df2)
423
+
424
+ indicatorlist=list(df2)
425
+ if indicator not in indicatorlist:
426
+ print(" #Error(reits_list_china):",indicator,"is not supported")
427
+ print(" Supported indicators:",indicatorlist)
423
428
  return None
424
429
 
425
- #df2.sort_values(by=['昨收'],ascending=False,inplace=True)
426
- df2.sort_values(by=[sort],ascending=False,inplace=True)
430
+ #df2.indicator_values(by=['昨收'],ascending=False,inplace=True)
431
+ df2.sort_values(by=[indicator],ascending=False,inplace=True)
427
432
  df2.reset_index(drop=True,inplace=True)
428
- #df2['序号']=df2.index + 1
429
- num=len(df2)
433
+ collist=list(df2)
434
+
435
+ for i in ['名称','代码',indicator]:
436
+ collist.remove(i)
437
+ collist1=['名称','代码',indicator]+collist
430
438
 
439
+ df2['序号']=df2.index + 1
440
+ df2=df2[['序号']+collist1]
441
+ """
431
442
  #设置打印对齐
432
443
  pd.set_option('display.max_columns', 1000)
433
444
  pd.set_option('display.width', 1000)
434
445
  pd.set_option('display.max_colwidth', 1000)
435
446
  pd.set_option('display.unicode.ambiguous_as_wide', True)
436
447
  pd.set_option('display.unicode.east_asian_width', True)
437
-
448
+ """
438
449
  if rank > 0:
439
450
  order='前'
440
451
  dfb=df2.head(rank)
@@ -443,11 +454,8 @@ def reits_list_china(rank=10,sort='最新价'):
443
454
  rank=-rank
444
455
  dfb=df2.tail(rank)
445
456
 
446
- dfb.fillna("---",inplace=True)
447
- dfb['成交额']=dfb['成交额'].apply(lambda x: int(x))
448
-
449
457
  #print("\n===== 中国REITs基金列表(按最新价高低排列,"+order+str(rank)+"名) =====\n")
450
- titletxt="中国REITs基金列表(按"+sort+"降序排列,"+order+str(rank)+"名)"
458
+ titletxt="中国REITs基金列表(按"+indicator+"降序排列,"+order+str(rank)+"名)"
451
459
  """
452
460
  print(dfb.to_string(index=False))
453
461
  """
@@ -464,10 +472,10 @@ def reits_list_china(rank=10,sort='最新价'):
464
472
  """
465
473
  import datetime; todaydt = datetime.date.today()
466
474
  #print("\n*** 数据来源:东方财富, 总计"+str(num)+"只REITs基金,",today)
467
- footnote="数据来源:东方财富, 总计"+str(num)+"只REITs基金,"+str(todaydt)
475
+ footnote="数据来源:东方财富,共找到"+str(num)+"只REITs基金,"+str(todaydt)
468
476
 
469
477
  df_display_CSS(dfb,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=3, \
470
- first_col_align='left',second_col_align='left', \
478
+ first_col_align='center',second_col_align='left', \
471
479
  last_col_align='right',other_col_align='right', \
472
480
  titile_font_size='16px',heading_font_size='15px', \
473
481
  data_font_size='15px')
@@ -577,10 +585,12 @@ if __name__=='__main__':
577
585
  info_type='单位净值'
578
586
  fund_type='股票型'
579
587
 
580
- def oef_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
588
+ def oef_rank_china(indicator='单位净值',fund_type='全部类型',rank=5):
581
589
  """
582
590
  功能:中国开放式基金排名,单位净值,累计净值,手续费
583
591
  """
592
+ info_type=indicator
593
+
584
594
  typelist=['单位净值','累计净值','手续费','增长率']
585
595
  if info_type not in typelist:
586
596
  print(" #Error(oef_rank_china): unsupported info type",info_type)
@@ -664,26 +674,30 @@ def oef_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
664
674
  if info_type == '单位净值':
665
675
  df['单位净值']=df['单位净值'].apply(lambda x: round(x,2))
666
676
  df.sort_values(by=['单位净值'],ascending=False,inplace=True)
667
- dfprint=df[['基金简称','基金代码','基金类型','单位净值','申购状态','赎回状态']]
677
+ #dfprint=df[['基金简称','基金代码','基金类型','单位净值','申购状态','赎回状态']]
678
+ dfprint=df[['基金简称','基金代码','基金类型','单位净值','累计净值']]
668
679
  #print(texttranslate("\n===== 中国开放式基金排名:单位净值 ====="))
669
680
  titletxt="中国开放式基金排名:单位净值"
670
681
 
671
682
  if info_type == '累计净值':
672
683
  df['累计净值']=df['累计净值'].apply(lambda x: round(x,2))
673
684
  df.sort_values(by=['累计净值'],ascending=False,inplace=True)
674
- dfprint=df[['基金简称','基金代码','基金类型','累计净值','申购状态','赎回状态']]
685
+ #dfprint=df[['基金简称','基金代码','基金类型','累计净值','申购状态','赎回状态']]
686
+ dfprint=df[['基金简称','基金代码','基金类型','累计净值','单位净值']]
675
687
  #print(texttranslate("\n===== 中国开放式基金排名:累计净值 ====="))
676
688
  titletxt="中国开放式基金排名:累计净值"
677
689
 
678
690
  if info_type == '手续费':
679
691
  df.sort_values(by=['手续费'],ascending=False,inplace=True)
680
- dfprint=df[['基金简称','基金代码','基金类型','手续费','申购状态','赎回状态']]
692
+ #dfprint=df[['基金简称','基金代码','基金类型','手续费','申购状态','赎回状态']]
693
+ dfprint=df[['基金简称','基金代码','基金类型','手续费','单位净值']]
681
694
  #print(texttranslate("\n===== 中国开放式基金排名:手续费 ====="))
682
695
  titletxt="中国开放式基金排名:手续费"
683
696
 
684
697
  if info_type == '增长率':
685
698
  df.sort_values(by=['日增长率'],ascending=False,inplace=True)
686
- dfprint=df[['基金简称','基金代码','基金类型','日增长率','申购状态','赎回状态']]
699
+ #dfprint=df[['基金简称','基金代码','基金类型','日增长率','申购状态','赎回状态']]
700
+ dfprint=df[['基金简称','基金代码','基金类型','日增长率','单位净值']]
687
701
  #print(texttranslate("\n===== 中国开放式基金排名:增长率% ====="))
688
702
  titletxt="中国开放式基金排名:增长率%"
689
703
 
@@ -700,6 +714,10 @@ def oef_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
700
714
  dfprint.reset_index(drop=True,inplace=True)
701
715
  dfprint.index=dfprint.index + 1
702
716
 
717
+ collist=list(dfprint)
718
+ dfprint['序号']=dfprint.index
719
+ dfprint=dfprint[['序号']+collist]
720
+
703
721
  if rank >= 0:
704
722
  dfprint10=dfprint.head(rank)
705
723
  else:
@@ -738,7 +756,7 @@ def oef_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
738
756
  footnote=footnote1+footnote2+footnote3+footnote4
739
757
 
740
758
  df_display_CSS(dfprint10,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=4, \
741
- first_col_align='left',second_col_align='right', \
759
+ first_col_align='center',second_col_align='left', \
742
760
  last_col_align='right',other_col_align='right', \
743
761
  titile_font_size='16px',heading_font_size='15px', \
744
762
  data_font_size='15px')
@@ -787,15 +805,19 @@ if __name__=='__main__':
787
805
  twinx=False
788
806
  zeroline=False
789
807
 
790
- def oef_trend_china(fund,start,end='today',trend_type='净值', \
808
+ def oef_trend_china(ticker,start,end='today',indicator='净值', \
791
809
  power=0,twinx=False, \
792
- loc1='upper left',loc2='lower left'):
810
+ average_value=True,facecolor='whitesmoke',
811
+ loc1='best',loc2='best'):
793
812
  """
794
813
  功能:开放式基金业绩趋势,单位净值,累计净值,近三个月收益率,同类排名,总排名
795
814
  """
815
+ fund=ticker
796
816
  fromdate,todate=start_end_preprocess(start,end)
817
+ trend_type=indicator
818
+
797
819
  #检查走势类型
798
- trendlist=["净值","收益率","排名"]
820
+ trendlist=["净值","单位净值","累计净值","收益率","排名"]
799
821
  if trend_type not in trendlist:
800
822
  print(" #Error(oef_trend_china): unsupported trend type:",trend_type)
801
823
  print(" Supported trend types:",trendlist)
@@ -814,6 +836,7 @@ def oef_trend_china(fund,start,end='today',trend_type='净值', \
814
836
  """
815
837
  print("Searching for open-ended fund (OEF) trend info in China ...")
816
838
  import akshare as ak
839
+ import pandas as pd
817
840
 
818
841
  #开放式基金-历史数据
819
842
  import datetime; today = datetime.date.today()
@@ -823,7 +846,6 @@ def oef_trend_china(fund,start,end='today',trend_type='净值', \
823
846
  fund_name=ticker_name(fund1,'fund')
824
847
 
825
848
  #绘制单位/累计净值对比图
826
- import pandas as pd
827
849
  if trend_type == '净值':
828
850
  df1 = ak.fund_open_fund_info_em(fund1, indicator="单位净值走势")
829
851
  df1.rename(columns={'净值日期':'date','单位净值':'单位净值'}, inplace=True)
@@ -853,14 +875,92 @@ def oef_trend_china(fund,start,end='today',trend_type='净值', \
853
875
  titletxt=texttranslate("开放式基金的净值趋势:")+fund_name
854
876
 
855
877
  #footnote=source+', '+str(today)
856
- footnote='注意:图中为基金市场交易价格,存在溢价或折价,可能与基金公司公布的净值存在差异\n'+source+', '+str(today)
878
+ footnote='注意:图中为交易市场数据,存在溢价或折价,可能与基金公司公布的净值存在差异\n'+source+', '+str(today)
879
+
880
+ plot_line2(dfp,ticker1,colname1,label1, \
881
+ dfp,ticker2,colname2,label2, \
882
+ ylabeltxt,titletxt,footnote,power=power,twinx=twinx, \
883
+ facecolor=facecolor, \
884
+ loc1=loc1,loc2=loc2)
885
+ return df
886
+
887
+ #绘制单位净值图
888
+ if trend_type == '单位净值':
889
+ df1 = ak.fund_open_fund_info_em(fund1, indicator="单位净值走势")
890
+ df1.rename(columns={'净值日期':'date','单位净值':'单位净值'}, inplace=True)
891
+ df1['日期']=df1['date']
892
+ df1.set_index(['date'],inplace=True)
893
+ """
894
+ df2 = ak.fund_open_fund_info_em(fund1, indicator="累计净值走势")
895
+ df2.rename(columns={'净值日期':'date','累计净值':'累计净值'}, inplace=True)
896
+ df2.set_index(['date'],inplace=True)
897
+ """
898
+ #合并
899
+ #df = pd.merge(df1,df2,left_index=True,right_index=True,how='inner')
900
+ df = df1
901
+ df['日期']=df['日期'].apply(lambda x: pd.to_datetime(x))
902
+
903
+ dfp=df[(df['日期'] >= start)]
904
+ dfp=dfp[(dfp['日期'] <= end)]
905
+ if len(dfp) == 0:
906
+ print(" #Error(oef_trend_china): no info found for",fund,"in the period:",fromdate,todate)
907
+ return
908
+
909
+ #绘图
910
+ ticker1=fund1; colname1='单位净值';label1=texttranslate('单位净值')
911
+ #ticker2=fund1; colname2='累计净值';label2=texttranslate('累计净值')
912
+ #ylabeltxt='人民币元'
913
+ ylabeltxt=texttranslate('单位净值')
914
+
915
+ titletxt=texttranslate("开放式基金的净值趋势:")+fund_name
916
+
917
+ #footnote=source+', '+str(today)
918
+ footnote='图中为交易市场数据,存在溢价或折价,可能与基金公司公布的净值存在差异\n'+source+', '+str(today)
857
919
 
920
+ plot_line(dfp,colname1,label1,ylabeltxt,titletxt,footnote,power=power,loc=loc1, \
921
+ average_value=average_value,facecolor=facecolor)
922
+ """
858
923
  plot_line2(dfp,ticker1,colname1,label1, \
859
- dfp,ticker2,colname2,label2, \
860
- ylabeltxt,titletxt,footnote,power=power,twinx=twinx, \
924
+ dfp,ticker2,colname2,label2, \
925
+ ylabeltxt,titletxt,footnote,power=power,twinx=twinx, \
926
+ facecolor=facecolor, \
861
927
  loc1=loc1,loc2=loc2)
928
+ """
929
+ return df
930
+
931
+ #绘制累计净值图
932
+ if trend_type == '累计净值':
933
+ df2 = ak.fund_open_fund_info_em(fund1, indicator="累计净值走势")
934
+ df2.rename(columns={'净值日期':'date','累计净值':'累计净值'}, inplace=True)
935
+ df2['日期']=df2['date']
936
+ df2.set_index(['date'],inplace=True)
937
+
938
+ #合并
939
+ df = df2
940
+ df['日期']=df['日期'].apply(lambda x: pd.to_datetime(x))
941
+
942
+ dfp=df[(df['日期'] >= start)]
943
+ dfp=dfp[(dfp['日期'] <= end)]
944
+ if len(dfp) == 0:
945
+ print(" #Error(oef_trend_china): no info found for",fund,"in the period:",fromdate,todate)
946
+ return
947
+
948
+ #绘图
949
+ ticker2=fund1; colname2='累计净值';label2=texttranslate('累计净值')
950
+ #ylabeltxt='人民币元'
951
+ ylabeltxt=texttranslate('累计净值')
952
+
953
+ titletxt=texttranslate("开放式基金的净值趋势:")+fund_name
954
+
955
+ #footnote=source+', '+str(today)
956
+ footnote='图中为交易市场数据,存在溢价或折价,可能与基金公司公布的净值存在差异\n'+source+', '+str(today)
957
+
958
+ plot_line(dfp,colname2,label2,ylabeltxt,titletxt,footnote,power=power,loc=loc1, \
959
+ average_value=average_value,facecolor=facecolor)
960
+
862
961
  return df
863
962
 
963
+
864
964
  #绘制累计收益率单线图
865
965
  if trend_type == '收益率':
866
966
  df = ak.fund_open_fund_info_em(fund1, indicator="累计收益率走势")
@@ -875,10 +975,11 @@ def oef_trend_china(fund,start,end='today',trend_type='净值', \
875
975
  return
876
976
 
877
977
  colname='累计收益率'; collabel=texttranslate('累计收益率%')
878
- ylabeltxt=texttranslate('收益率%')
978
+ ylabeltxt=texttranslate('累计收益率%')
879
979
  titletxt=texttranslate("开放式基金的累计收益率趋势:")+fund_name
880
- footnote=source+', '+str(today)
881
- plot_line(dfp,colname,collabel,ylabeltxt,titletxt,footnote,power=power,loc=loc1)
980
+ footnote=source+''+str(today)
981
+ plot_line(dfp,colname,collabel,ylabeltxt,titletxt,footnote,power=power,loc=loc1, \
982
+ average_value=average_value,facecolor=facecolor)
882
983
  return df
883
984
 
884
985
  #绘制同类排名图:近三个月收益率
@@ -922,8 +1023,9 @@ def oef_trend_china(fund,start,end='today',trend_type='净值', \
922
1023
  dfp1=pd.DataFrame(dfp[colname1])
923
1024
  dfp2=pd.DataFrame(dfp[colname2])
924
1025
  plot_line2(dfp1,ticker1,colname1,label1, \
925
- dfp2,ticker2,colname2,label2, \
926
- ylabeltxt,titletxt,footnote,power=power,twinx=twinx, \
1026
+ dfp2,ticker2,colname2,label2, \
1027
+ ylabeltxt,titletxt,footnote,power=power,twinx=twinx, \
1028
+ facecolor=facecolor, \
927
1029
  loc1=loc1,loc2=loc2)
928
1030
 
929
1031
  return df
@@ -932,78 +1034,71 @@ def oef_trend_china(fund,start,end='today',trend_type='净值', \
932
1034
  if __name__=='__main__':
933
1035
  pass
934
1036
 
935
- def mmf_rank_china(rank=10):
1037
+ def mmf_rank_china(indicator="7日年化%",rank=5):
936
1038
  """
937
1039
  功能:中国货币型基金排名,7日年化收益率%
1040
+ 货币基金的万份收益指的是基金公司每日公布的当日每万份基金单位产生的收益金额,即万份基金单位收益。
1041
+ 注意:万份基金单位收益与万份基金累计收益是不一样的,投资者想要买货币基金应改看基金的万份基金单位收益。
1042
+ 货币基金具体的收益计算方式是:
1043
+ 货币基金收益=已确认金额/10000*当日万分收益。
1044
+ 另外,货币基金每日公布一次收益,周末及节假日,通常在节后首个交易日公布周末或这节假日期间的累计收益。
938
1045
  """
1046
+ indicator_list=["万份收益","7日年化%"]
1047
+ if indicator not in indicator_list:
1048
+ print(" #Warning(mmf_rank_china): unsupported indicator",indicator,"reset to","7日年化%")
1049
+ indicator="7日年化%"
939
1050
 
940
1051
  print("Searching for money market fund (OEF) information in China ...")
941
1052
  import akshare as ak
1053
+ import pandas as pd
942
1054
 
943
1055
  #获取货币型基金实时信息
944
1056
  df = ak.fund_money_fund_daily_em()
945
1057
  collist=list(df)
946
- nvname=collist[3]
947
- if df[nvname].eq('').all():
948
- nvname=collist[6]
949
- nvdate=nvname[:10]
1058
+ nvname1=collist[2]
1059
+ nvname2=collist[3]
1060
+ if df[nvname1].eq('').all():
1061
+ nvname1=collist[5]
1062
+ nvname2=collist[6]
1063
+ nvdate=nvname1[:10]
1064
+
950
1065
  #修改列名
951
- df.rename(columns={nvname:'7日年化%'}, inplace=True)
1066
+ df.rename(columns={nvname1:'万份收益',nvname2:'7日年化%'}, inplace=True)
952
1067
  #dfa=df.drop(df[df['7日年化%']==''].index)
953
- dfb=df[['基金代码','基金简称','7日年化%','成立日期','基金经理','手续费']]
954
-
955
- dfb.sort_values(by=['7日年化%'],ascending=False,inplace=True)
956
- dfprint=dfb[['基金简称','基金代码','7日年化%','基金经理','手续费']]
957
- #print(texttranslate("\n======= 中国货币型基金排名:7日年化收益率 ======="))
958
- titletxt="中国货币型基金排名:7日年化收益率"
959
-
960
- #设置打印对齐
961
- import pandas as pd
962
- pd.set_option('display.max_columns', 1000)
963
- pd.set_option('display.width', 1000)
964
- pd.set_option('display.max_colwidth', 1000)
965
- pd.set_option('display.unicode.ambiguous_as_wide', True)
966
- pd.set_option('display.unicode.east_asian_width', True)
967
-
1068
+ dfb=df[['基金代码','基金简称','万份收益','7日年化%','成立日期','基金经理','手续费']].copy()
1069
+ dfb=dfb[dfb['7日年化%'] != '---']
1070
+
1071
+ if indicator=='7日年化%':
1072
+ dfb.sort_values(by=['7日年化%'],ascending=False,inplace=True)
1073
+ dfprint=dfb[['基金简称','基金代码','7日年化%','万份收益']].copy()
1074
+ titletxt="中国货币型基金排名:7日年化收益率"
1075
+ if indicator=='万份收益':
1076
+ dfb.sort_values(by=['万份收益'],ascending=False,inplace=True)
1077
+ dfprint=dfb[['基金简称','基金代码','万份收益','7日年化%']].copy()
1078
+ titletxt="中国货币型基金排名:万份收益金额(元)"
1079
+
1080
+ #设置打印
968
1081
  dfprint.dropna(inplace=True)
969
1082
  dfprint.reset_index(drop=True,inplace=True)
970
1083
  dfprint.index=dfprint.index + 1
971
1084
 
972
- if rank >=0:
1085
+ collist=list(dfprint)
1086
+ dfprint['序号']=dfprint.index
1087
+ dfprint=dfprint[['序号']+collist]
1088
+
1089
+ if rank >0:
973
1090
  dfprint10=dfprint.head(rank)
974
1091
  else:
975
1092
  dfprint10=dfprint.tail(-rank)
976
- #print(dfprint10.to_string(index=False))
977
- """
978
- print(dfprint10)
979
- """
980
- """
981
- print('') #在标题与表格之间空一行
982
- alignlist=['right','left','center','center','center','right']
983
- try:
984
- print(dfprint10.to_markdown(index=True,tablefmt='plain',colalign=alignlist))
985
- except:
986
- #解决汉字编码gbk出错问题
987
- print_df=dfprint10.to_markdown(index=True,tablefmt='plain',colalign=alignlist)
988
- print_df2=print_df.encode("utf-8",errors="strict")
989
- print(print_df2)
990
-
991
- print('') #在表格与脚注之间空一行
992
- print(texttranslate("共找到披露收益率信息的货币型基金数量:"),len(dfprint))
993
-
994
- print(texttranslate("收益率日期:"),nvdate,'\b. ',end='')
995
- import datetime
996
- today = datetime.date.today()
997
- print(texttranslate("数据来源:东方财富/天天基金,"),today)
998
- """
999
- footnote1="披露收益率信息的货币型基金数量:"+str(len(dfprint))+'\n'
1000
- footnote2="收益率日期:"+str(nvdate)+','
1093
+
1094
+ footnote1="披露收益信息的货币型基金数量:"+str(len(dfprint))+','
1095
+ footnote2=str(nvdate)+'\n'
1001
1096
  import datetime; todaydt = datetime.date.today()
1002
- footnote3="数据来源:东方财富/天天基金,"+str(todaydt)
1097
+ footnote3="数据来源:东方财富/天天基金,"+str(todaydt)+"统计"
1003
1098
  footnote=footnote1+footnote2+footnote3
1004
1099
 
1005
1100
  df_display_CSS(dfprint10,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=4, \
1006
- first_col_align='left',second_col_align='right', \
1101
+ first_col_align='center',second_col_align='left', \
1007
1102
  last_col_align='right',other_col_align='right', \
1008
1103
  titile_font_size='16px',heading_font_size='15px', \
1009
1104
  data_font_size='15px')
@@ -1020,34 +1115,38 @@ if __name__=='__main__':
1020
1115
  todate='2020-10-16'
1021
1116
  power=0
1022
1117
 
1023
- def mmf_trend_china(fund,start,end='today',power=0):
1118
+ def mmf_trend_china(ticker,start,end='today',indicator='7日年化%',power=0, \
1119
+ average_value=True,facecolor='whitesmoke'):
1024
1120
  """
1025
1121
  功能:货币型基金业绩趋势,7日年化收益率
1026
1122
  """
1123
+ fund=ticker
1124
+
1027
1125
  fromdate,todate=start_end_preprocess(start,end)
1028
1126
  #检查日期
1029
1127
  result,start,end=check_period(fromdate,todate)
1030
1128
  if not result:
1031
1129
  print(" #Error(mmf_trend_china): invalid date period:",fromdate,todate)
1032
1130
  return None
1033
- import datetime
1131
+ import datetime; todaydt = datetime.date.today()
1034
1132
  startdate=datetime.datetime.strftime(start,"%Y-%m-%d")
1035
1133
  enddate=str(datetime.datetime.strftime(end,"%Y-%m-%d"))
1036
1134
 
1037
1135
  print("Searching for money market fund (MMF) trend info in China ...")
1038
1136
  import akshare as ak
1137
+ import pandas as pd
1039
1138
 
1040
1139
  #基金历史数据
1041
- import datetime; today = datetime.date.today()
1042
1140
  source=texttranslate("数据来源:东方财富/天天基金")
1043
1141
 
1044
1142
  #绘制收益率单线图
1045
1143
  fund1=fund[:6]
1046
1144
  df = ak.fund_money_fund_info_em(fund1)
1047
- df.sort_values(by=['净值日期'],ascending=True,inplace=True)
1048
1145
  df['7日年化%']=df['7日年化收益率'].astype("float")
1146
+ df['万份收益']=df['每万份收益'].astype("float")
1147
+
1148
+ df.sort_values(by=['净值日期'],ascending=True,inplace=True)
1049
1149
 
1050
- import pandas as pd
1051
1150
  df['date']=pd.to_datetime(df['净值日期'])
1052
1151
  df.set_index(['date'],inplace=True)
1053
1152
 
@@ -1057,11 +1156,16 @@ def mmf_trend_china(fund,start,end='today',power=0):
1057
1156
  print(" #Error(mmf_trend_china): no info found for",fund,"in the period:",fromdate,todate)
1058
1157
  return
1059
1158
 
1060
- colname='7日年化%'; collabel=texttranslate('7日年化%')
1159
+ if indicator=='7日年化%':
1160
+ colname='7日年化%'; collabel='7日年化%'
1161
+ else:
1162
+ colname='万份收益'; collabel="万份收益(元)"
1163
+
1061
1164
  ylabeltxt=''
1062
- titletxt=texttranslate("货币型基金的7日年化收益率趋势:")+get_fund_name_china2(fund)
1063
- footnote=source+', '+str(today)
1064
- plot_line(dfp,colname,collabel,ylabeltxt,titletxt,footnote,power=power)
1165
+ titletxt="货币型基金的收益趋势:"+get_fund_name_china2(fund)+","+collabel
1166
+ footnote=source+', '+str(todaydt)
1167
+ plot_line(dfp,colname,collabel,ylabeltxt,titletxt,footnote,power=power, \
1168
+ average_value=average_value,facecolor=facecolor)
1065
1169
 
1066
1170
  return df
1067
1171
 
@@ -1072,10 +1176,12 @@ if __name__=='__main__':
1072
1176
  fund_type='增长率'
1073
1177
  rank=10
1074
1178
 
1075
- def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1179
+ def etf_rank_china(indicator='单位净值',fund_type='全部类型',rank=5):
1076
1180
  """
1077
1181
  功能:中国ETF基金排名,单位净值,累计净值,手续费
1078
1182
  """
1183
+ info_type=indicator
1184
+
1079
1185
  typelist=['单位净值','累计净值','市价','增长率']
1080
1186
  if info_type not in typelist:
1081
1187
  print(" #Error(etf_rank_china): unsupported info type",info_type)
@@ -1105,7 +1211,7 @@ def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1105
1211
 
1106
1212
  #修改列名
1107
1213
  df3=df2.rename(columns={nvname1:'单位净值',nvname2:'累计净值'})
1108
- df=df3[['基金简称','基金代码','类型','单位净值','累计净值','增长率','市价']]
1214
+ df=df3[['基金简称','基金代码','类型','单位净值','累计净值','增长率','市价']].copy()
1109
1215
 
1110
1216
  # 过滤idx行
1111
1217
  df=df[df.index != 'idx']
@@ -1135,7 +1241,7 @@ def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1135
1241
  df=df.replace('---',0)
1136
1242
  df['单位净值']=df['单位净值'].astype(float)
1137
1243
  df.sort_values(by=['单位净值'],ascending=False,inplace=True)
1138
- dfprint=df[['基金简称','基金代码','类型','单位净值','市价']]
1244
+ dfprint=df[['基金简称','基金代码','类型','单位净值','市价']].copy()
1139
1245
  #print(texttranslate("\n===== 中国ETF基金排名:单位净值 ====="))
1140
1246
  titletxt="中国ETF基金排名:单位净值"
1141
1247
  dfprint=dfprint[dfprint['单位净值'] != 0]
@@ -1144,7 +1250,7 @@ def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1144
1250
  df=df.replace('---',0)
1145
1251
  df['累计净值']=df['累计净值'].astype(float)
1146
1252
  df.sort_values(by=['累计净值'],ascending=False,inplace=True)
1147
- dfprint=df[['基金简称','基金代码','类型','累计净值','单位净值']]
1253
+ dfprint=df[['基金简称','基金代码','类型','累计净值','单位净值']].copy()
1148
1254
  #print(texttranslate("\n===== 中国ETF基金排名:累计净值 ====="))
1149
1255
  titletxt="中国ETF基金排名:累计净值"
1150
1256
  dfprint=dfprint[dfprint['累计净值'] != 0]
@@ -1153,7 +1259,7 @@ def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1153
1259
  df=df.replace('---',0)
1154
1260
  df['市价']=df['市价'].astype(float)
1155
1261
  df.sort_values(by=['市价'],ascending=False,inplace=True)
1156
- dfprint=df[['基金简称','基金代码','类型','市价','单位净值']]
1262
+ dfprint=df[['基金简称','基金代码','类型','市价','单位净值']].copy()
1157
1263
  #print(texttranslate("\n===== 中国ETF基金排名:市价 ====="))
1158
1264
  titletxt="中国ETF基金排名:市价"
1159
1265
  dfprint=dfprint[dfprint['市价'] != 0]
@@ -1161,7 +1267,7 @@ def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1161
1267
  if info_type == '增长率':
1162
1268
  df['增长率']=df['增长率'].astype(str)
1163
1269
  df.sort_values(by=['增长率'],ascending=False,inplace=True)
1164
- dfprint=df[['基金简称','基金代码','类型','增长率','市价','单位净值']]
1270
+ dfprint=df[['基金简称','基金代码','类型','增长率','市价','单位净值']].copy()
1165
1271
  #print(texttranslate("\n===== 中国ETF基金排名:增长率 ====="))
1166
1272
  titletxt="中国ETF基金排名:增长率"
1167
1273
  dfprint=dfprint[dfprint['增长率'] != 0]
@@ -1178,6 +1284,10 @@ def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1178
1284
  dfprint.reset_index(drop=True,inplace=True)
1179
1285
  dfprint.index=dfprint.index + 1
1180
1286
 
1287
+ collist=list(dfprint)
1288
+ dfprint['序号']=dfprint.index
1289
+ dfprint=dfprint[['序号']+collist]
1290
+
1181
1291
  if rank >=0:
1182
1292
  dfprint10=dfprint.head(rank)
1183
1293
  else:
@@ -1208,13 +1318,13 @@ def etf_rank_china(info_type='单位净值',fund_type='全部类型',rank=10):
1208
1318
  """
1209
1319
  footnote1="披露净值信息的ETF基金数量:"+str(len(dfprint))+','
1210
1320
  footnote2="基金类型:"+str(fund_type)+'\n'
1211
- footnote3="净值日期:"+str(nvdate)+','
1321
+ footnote3="披露日期:"+str(nvdate)+','
1212
1322
  import datetime; todaydt = datetime.date.today()
1213
1323
  footnote4="数据来源:东方财富/天天基金,"+str(todaydt)
1214
1324
  footnote=footnote1+footnote2+footnote3+footnote4
1215
1325
 
1216
1326
  df_display_CSS(dfprint10,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=3, \
1217
- first_col_align='left',second_col_align='right', \
1327
+ first_col_align='center',second_col_align='left', \
1218
1328
  last_col_align='right',other_col_align='right', \
1219
1329
  titile_font_size='16px',heading_font_size='15px', \
1220
1330
  data_font_size='15px')
@@ -1232,33 +1342,38 @@ if __name__=='__main__':
1232
1342
  fromdate='2020-1-1'
1233
1343
  todate='2020-10-16'
1234
1344
 
1235
- def etf_trend_china(fund,start,end='today',loc1='best',loc2='best',twinx=False,graph=True):
1345
+ def etf_trend_china(ticker,start,end='today',indicator='净值',power=0, \
1346
+ average_value=True,facecolor='whitesmoke', \
1347
+ loc1='best',loc2='best',twinx=False,graph=True):
1236
1348
  """
1237
1349
  功能:ETF基金业绩趋势,单位净值,累计净值
1238
1350
  """
1351
+ fund=ticker
1239
1352
  fromdate,todate=start_end_preprocess(start,end='today')
1240
1353
 
1354
+ indicator_list=['净值','单位净值','累计净值']
1355
+ if indicator not in indicator_list:
1356
+ indicator='净值'
1357
+
1241
1358
  #检查日期
1242
1359
  result,start,end=check_period(fromdate,todate)
1243
1360
  if not result:
1244
1361
  print(" #Error(oef_trend_china): invalid date period:",fromdate,todate)
1245
1362
  return None
1246
1363
  #转换日期格式
1247
- import datetime
1364
+ import datetime; todaydt = datetime.date.today()
1248
1365
  startdate=str(datetime.datetime.strftime(start,"%Y-%m-%d"))
1249
1366
  enddate=str(datetime.datetime.strftime(end,"%Y-%m-%d"))
1250
1367
 
1251
1368
  print("Searching for exchange traded fund (ETF) trend info in China ...")
1252
1369
  import akshare as ak
1370
+ import pandas as pd
1253
1371
 
1254
- import datetime; today = datetime.date.today()
1255
1372
  source=texttranslate("数据来源:东方财富/天天基金")
1256
-
1257
1373
 
1258
1374
  #获取基金数据
1259
1375
  fund1=fund[:6]
1260
1376
  df = etf_hist_df = ak.fund_etf_fund_info_em(fund1)
1261
- import pandas as pd
1262
1377
  df['date']=pd.to_datetime(df['净值日期'])
1263
1378
  df.set_index(['date'],inplace=True)
1264
1379
  df['单位净值']=df['单位净值'].astype("float")
@@ -1275,14 +1390,25 @@ def etf_trend_china(fund,start,end='today',loc1='best',loc2='best',twinx=False,g
1275
1390
  if graph:
1276
1391
  ticker1=fund1; colname1='单位净值';label1=texttranslate('单位净值')
1277
1392
  ticker2=fund1; colname2='累计净值';label2=texttranslate('累计净值')
1278
- ylabeltxt=texttranslate('人民币元')
1279
1393
  titletxt=texttranslate("ETF基金的净值趋势:")+get_fund_name_china2(fund)
1280
- footnote=source+', '+str(today)
1281
-
1282
- plot_line2(dfp,ticker1,colname1,label1, \
1283
- dfp,ticker2,colname2,label2, \
1284
- ylabeltxt,titletxt,footnote, twinx=twinx, \
1285
- loc1=loc1,loc2=loc2)
1394
+ footnote=source+', '+str(todaydt)
1395
+
1396
+ if indicator=='净值':
1397
+ ylabeltxt=texttranslate('净值(元)')
1398
+ plot_line2(dfp,ticker1,colname1,label1, \
1399
+ dfp,ticker2,colname2,label2, \
1400
+ ylabeltxt,titletxt,footnote, twinx=twinx, \
1401
+ facecolor=facecolor,loc1=loc1,loc2=loc2)
1402
+
1403
+ if indicator=='单位净值':
1404
+ ylabeltxt=texttranslate('单位净值(元)')
1405
+ plot_line(dfp,colname1,label1,ylabeltxt,titletxt,footnote,power=power,loc=loc1, \
1406
+ average_value=average_value,facecolor=facecolor)
1407
+
1408
+ if indicator=='累计净值':
1409
+ ylabeltxt=texttranslate('累计净值(元)')
1410
+ plot_line(dfp,colname2,label2,ylabeltxt,titletxt,footnote,power=power,loc=loc1, \
1411
+ average_value=average_value,facecolor=facecolor)
1286
1412
 
1287
1413
  return dfp
1288
1414
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: siat
3
- Version: 3.1.2
3
+ Version: 3.1.3
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
@@ -17,7 +17,7 @@ siat/capm_beta.py,sha256=cxXdRVBQBllhbfz1LeTJAIWvyRYhW54nhtNUXv4HwS0,29063
17
17
  siat/capm_beta2.py,sha256=UOI4sCz3ld7yezlARqPHvgHzfduDiGeRqNa82dDTCZ8,25849
18
18
  siat/capm_beta_test.py,sha256=ImR0c5mc4hIl714XmHztdl7qg8v1E2lycKyiqnFj6qs,1745
19
19
  siat/cmat_commons.py,sha256=Nj9Kf0alywaztVoMVeVVL_EZk5jRERJy8R8kBw88_Tg,38116
20
- siat/common.py,sha256=0_fT64-X80rOPOqc6x6D_3WOLN2mKQ4UWZTuRqoLIAc,142992
20
+ siat/common.py,sha256=kGsyiuYJX-Y8VNb2mmspSp7rNc5r8eexxEt9JiKmwHM,143250
21
21
  siat/compare_cross.py,sha256=3iP9TH2h3w27F2ARZc7FjKcErYCzWRc-TPiymOyoVtw,24171
22
22
  siat/compare_cross_test.py,sha256=xra5XYmQGEtfIZL2h-GssdH2hLdFIhG3eoCrkDrL3gY,3473
23
23
  siat/concepts_iwencai.py,sha256=m1YEDtECRT6FqtzlKm91pt2I9d3Z_XoP59BtWdRdu8I,3061
@@ -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=RK2A111np2U8Jfi9S7Yt_yYa_iuxEy0mhTg24i3O4VU,87982
55
+ siat/fund_china.py,sha256=_obFT-JBjhvzX71HVyqafwFXKE3YCIMpVhsKz_Wir-4,94035
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.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,,
135
+ siat-3.1.3.dist-info/METADATA,sha256=h-Ogl_X_X9zSfrdOjdfY0uOX4hRUPUTlOHnKoMkzS9g,1447
136
+ siat-3.1.3.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
137
+ siat-3.1.3.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
138
+ siat-3.1.3.dist-info/RECORD,,
File without changes