siat 3.1.12__py3-none-any.whl → 3.1.14__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 +0 -78
- siat/exchange_bond_china.pickle +0 -0
- siat/fund_china.pickle +0 -0
- siat/fund_china.py +80 -18
- siat/markowitz2.py +122 -47
- siat/sector_china.py +6 -3
- siat/security_price2.py +43 -9
- siat/security_prices.py +31 -16
- siat/security_trend2.py +10 -2
- siat/stock.py +20 -3
- siat/stock_info.pickle +0 -0
- siat/translate.py +21 -11
- siat/translate_20240606.py +4206 -0
- {siat-3.1.12.dist-info → siat-3.1.14.dist-info}/METADATA +1 -1
- {siat-3.1.12.dist-info → siat-3.1.14.dist-info}/RECORD +17 -16
- {siat-3.1.12.dist-info → siat-3.1.14.dist-info}/WHEEL +0 -0
- {siat-3.1.12.dist-info → siat-3.1.14.dist-info}/top_level.txt +0 -0
siat/common.py
CHANGED
@@ -1480,84 +1480,6 @@ if __name__=='__main__':
|
|
1480
1480
|
rfd=rf_daily_china('2021-11-1','2021-11-28',rate_period='1Y',rate_type='treasury')
|
1481
1481
|
|
1482
1482
|
#==============================================================================
|
1483
|
-
if __name__=='__main__':
|
1484
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
1485
|
-
leading_blanks=2
|
1486
|
-
|
1487
|
-
def print_tickerlist_sharelist(tickerlist,sharelist,leading_blanks=2,ticker_type='auto'):
|
1488
|
-
"""
|
1489
|
-
功能:纵向打印投资组合的成分股和持股比例
|
1490
|
-
输入:
|
1491
|
-
tickerlist:成分股列表
|
1492
|
-
sharelist:持股份额列表
|
1493
|
-
leading_blanks:打印前导空格数
|
1494
|
-
"""
|
1495
|
-
#检查成分股与持仓比例个数是否一致
|
1496
|
-
if not (len(tickerlist) == len(sharelist)):
|
1497
|
-
print(" #Error(): numbers of tickers and shares are not same")
|
1498
|
-
return
|
1499
|
-
|
1500
|
-
#计算最长的代码长度,便于对齐
|
1501
|
-
max_ticker_len=0
|
1502
|
-
for t in tickerlist:
|
1503
|
-
tlen=len(t)
|
1504
|
-
#print(t,tlen)
|
1505
|
-
if tlen > max_ticker_len: #if的执行语句放在这里可能有bug
|
1506
|
-
max_ticker_len=tlen
|
1507
|
-
|
1508
|
-
# 将原投资组合的权重存储为numpy数组类型,为了合成投资组合计算方便
|
1509
|
-
import numpy as np
|
1510
|
-
sharelist_array = np.array(sharelist)
|
1511
|
-
total_shares=sharelist_array.sum()
|
1512
|
-
weights=sharelist_array/total_shares
|
1513
|
-
|
1514
|
-
#预处理ticker_type
|
1515
|
-
ticker_type_list=ticker_type_preprocess_mticker_mixed(tickerlist,ticker_type)
|
1516
|
-
|
1517
|
-
import pandas as pd
|
1518
|
-
df=pd.DataFrame(columns=['证券代码','证券名称','持仓比例'])
|
1519
|
-
for t in tickerlist:
|
1520
|
-
pos=tickerlist.index(t)
|
1521
|
-
tt=ticker_type_list[pos]
|
1522
|
-
tname=ticker_name(t,tt)
|
1523
|
-
tweight=weights[pos]
|
1524
|
-
|
1525
|
-
row=pd.Series({'证券代码':t,'证券名称':tname,'持仓比例':tweight})
|
1526
|
-
try:
|
1527
|
-
df=df.append(row,ignore_index=True)
|
1528
|
-
except:
|
1529
|
-
df=df._append(row,ignore_index=True)
|
1530
|
-
|
1531
|
-
#按持仓比例降序
|
1532
|
-
df.sort_values(by='持仓比例',ascending=False,inplace=True)
|
1533
|
-
"""
|
1534
|
-
#打印对齐
|
1535
|
-
pd.set_option('display.max_columns', 1000)
|
1536
|
-
pd.set_option('display.width', 1000)
|
1537
|
-
pd.set_option('display.max_colwidth', 1000)
|
1538
|
-
pd.set_option('display.unicode.ambiguous_as_wide', True)
|
1539
|
-
pd.set_option('display.unicode.east_asian_width', True)
|
1540
|
-
|
1541
|
-
print(df.to_string(index=False,header=False))
|
1542
|
-
"""
|
1543
|
-
|
1544
|
-
#打印
|
1545
|
-
df.reset_index(inplace=True) #必须,不然排序不起作用
|
1546
|
-
for i in range(len(df)):
|
1547
|
-
rows = df.loc[[i]]
|
1548
|
-
tcode=rows['证券代码'].values[0]
|
1549
|
-
tname=rows['证券名称'].values[0]
|
1550
|
-
tweight=rows['持仓比例'].values[0]
|
1551
|
-
print(' '*leading_blanks,tcode+' '*(max_ticker_len-len(tcode))+':',tname,'\b,',round(tweight,4))
|
1552
|
-
"""
|
1553
|
-
values = rows.to_string(index=False,header=False)
|
1554
|
-
"""
|
1555
|
-
|
1556
|
-
return
|
1557
|
-
|
1558
|
-
if __name__=='__main__':
|
1559
|
-
print_tickerlist_sharelist(tickerlist,sharelist,leading_blanks=2)
|
1560
|
-
#==============================================================================
|
1561
1483
|
if __name__=='__main__':
|
1562
1484
|
current=0
|
1563
1485
|
total=9
|
siat/exchange_bond_china.pickle
CHANGED
Binary file
|
siat/fund_china.pickle
CHANGED
Binary file
|
siat/fund_china.py
CHANGED
@@ -439,7 +439,7 @@ def reits_jsl_china(fund='',rank=10):
|
|
439
439
|
df1 = ak.reits_info_jsl()
|
440
440
|
df2 = ak.reits_realtime_em()
|
441
441
|
except:
|
442
|
-
print(" #Error(reits_jsl_china): sorry, data source
|
442
|
+
print(" #Error(reits_jsl_china): sorry, data source has rejected access")
|
443
443
|
return None
|
444
444
|
|
445
445
|
#合成基金类型信息
|
@@ -496,7 +496,7 @@ def reits_jsl_china(fund='',rank=10):
|
|
496
496
|
return dfb
|
497
497
|
|
498
498
|
#==============================================================================
|
499
|
-
def reit_rank_china(indicator='最新价',rank=
|
499
|
+
def reit_rank_china(indicator='最新价',rank=5):
|
500
500
|
"""
|
501
501
|
功能:套壳函数reits_list_china
|
502
502
|
"""
|
@@ -511,20 +511,24 @@ if __name__=='__main__':
|
|
511
511
|
|
512
512
|
df=reits_list_china(rank=10)
|
513
513
|
|
514
|
-
def reits_list_china(indicator='最新价',rank=
|
514
|
+
def reits_list_china(indicator='最新价',rank=5):
|
515
515
|
"""
|
516
516
|
功能:REITs基金信息概述和列表
|
517
517
|
目前能正常工作
|
518
518
|
"""
|
519
519
|
import akshare as ak
|
520
|
+
import math
|
520
521
|
try:
|
521
522
|
df2 = ak.reits_realtime_em()
|
522
523
|
except:
|
523
524
|
print(" #Error(reits_profile_china): akshare does not work properly now")
|
524
525
|
return None
|
525
526
|
df2.drop('序号', axis=1, inplace=True)
|
527
|
+
#使用-999标记空缺值,避免后续处理出错,同时避免与真正的0混淆
|
528
|
+
df2.fillna(-999,inplace=True)
|
529
|
+
#df2['成交额']=df2['成交额'].apply(lambda x: int(x) if not math.isnan(x) else x)
|
526
530
|
df2['成交额']=df2['成交额'].apply(lambda x: int(x))
|
527
|
-
df2.
|
531
|
+
df2['成交量']=df2['成交量'].apply(lambda x: int(x))
|
528
532
|
|
529
533
|
df2=df_swap_columns(df2, col1='代码', col2='名称')
|
530
534
|
num=len(df2)
|
@@ -537,7 +541,12 @@ def reits_list_china(indicator='最新价',rank=10):
|
|
537
541
|
|
538
542
|
#df2.indicator_values(by=['昨收'],ascending=False,inplace=True)
|
539
543
|
df2.sort_values(by=[indicator],ascending=False,inplace=True)
|
544
|
+
df2.replace(-999,"---",inplace=True)
|
545
|
+
|
540
546
|
df2.reset_index(drop=True,inplace=True)
|
547
|
+
df2=df2[df2[indicator] != "---"]
|
548
|
+
num1=len(df2)
|
549
|
+
|
541
550
|
collist=list(df2)
|
542
551
|
|
543
552
|
for i in ['名称','代码',indicator]:
|
@@ -580,7 +589,10 @@ def reits_list_china(indicator='最新价',rank=10):
|
|
580
589
|
"""
|
581
590
|
import datetime; todaydt = datetime.date.today()
|
582
591
|
#print("\n*** 数据来源:东方财富, 总计"+str(num)+"只REITs基金,",today)
|
583
|
-
|
592
|
+
if num == num1 or order=='前':
|
593
|
+
footnote="数据来源:新浪财经/天天基金,共找到"+str(num)+"只REITs基金,"+str(todaydt)
|
594
|
+
else:
|
595
|
+
footnote="数据来源:新浪财经/天天基金,共找到"+str(num)+"只REITs基金(其中"+str(num-num1)+"只没有"+indicator+"信息),"+str(todaydt)
|
584
596
|
|
585
597
|
df_display_CSS(dfb,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=3, \
|
586
598
|
first_col_align='center',second_col_align='left', \
|
@@ -690,8 +702,15 @@ if __name__=='__main__':
|
|
690
702
|
|
691
703
|
#==============================================================================
|
692
704
|
if __name__=='__main__':
|
693
|
-
|
705
|
+
indicator='单位净值'
|
706
|
+
|
694
707
|
fund_type='股票型'
|
708
|
+
fund_type='FOF'
|
709
|
+
fund_type='LOF'
|
710
|
+
fund_type='FOF-LOF'
|
711
|
+
|
712
|
+
rank=5
|
713
|
+
|
695
714
|
|
696
715
|
def oef_rank_china(indicator='单位净值',fund_type='全部类型',rank=5):
|
697
716
|
"""
|
@@ -709,7 +728,12 @@ def oef_rank_china(indicator='单位净值',fund_type='全部类型',rank=5):
|
|
709
728
|
import akshare as ak
|
710
729
|
|
711
730
|
#获取开放式基金实时信息
|
712
|
-
|
731
|
+
try:
|
732
|
+
df1 = ak.fund_open_fund_daily_em()
|
733
|
+
except:
|
734
|
+
print(" #Error(oef_rank_china): data source tentatively busy or unavailable, try later")
|
735
|
+
return None
|
736
|
+
|
713
737
|
collist=list(df1)
|
714
738
|
nvname1=collist[2]
|
715
739
|
nvname2=collist[3]
|
@@ -754,29 +778,49 @@ def oef_rank_china(indicator='单位净值',fund_type='全部类型',rank=5):
|
|
754
778
|
#过滤基金类型
|
755
779
|
if fund_type != '全部类型':
|
756
780
|
fundtypelist=list(set(list(df['基金类型'])))
|
781
|
+
try: fundtypelist.remove('0')
|
782
|
+
except: pass
|
783
|
+
|
784
|
+
fundtypelist=fundtypelist+['LOF','FOF-LOF']
|
757
785
|
"""
|
758
786
|
while np.nan in fundtypelist:
|
759
787
|
fundtypelist.remove(np.nan)
|
760
788
|
while 0 in fundtypelist:
|
761
789
|
fundtypelist.remove(0)
|
762
|
-
"""
|
790
|
+
"""
|
791
|
+
#检查基金类型是否存在
|
763
792
|
found=False
|
764
793
|
for ft in fundtypelist:
|
765
794
|
if ft==0: continue
|
766
795
|
if fund_type in ft:
|
767
796
|
found=True
|
768
797
|
break
|
798
|
+
|
799
|
+
#未找到基金类型
|
769
800
|
if not found:
|
770
801
|
print(" #Error(oef_rank_china): unsupported fund type",fund_type)
|
771
802
|
print(" Supported fund types:",fundtypelist)
|
772
803
|
return None
|
773
|
-
|
804
|
+
|
774
805
|
df.dropna(inplace=True)
|
806
|
+
fund_filter=lambda x: fund_type in x
|
775
807
|
df['基金类型s']=df['基金类型'].apply(fund_filter)
|
776
808
|
|
777
809
|
if fund_type == 'QDII':
|
778
810
|
df['基金类型s']=df.apply(lambda x: False if '不含' in x['基金类型'] else x['基金类型s'],axis=1)
|
779
811
|
|
812
|
+
if fund_type == 'FOF':
|
813
|
+
df['基金类型s']=df.apply(lambda x: True if (fund_type in x['基金类型'] or fund_type in x['基金简称']) else x['基金类型s'],axis=1)
|
814
|
+
df['基金类型s']=df.apply(lambda x: False if ('LOF' in x['基金类型'] or 'LOF' in x['基金简称']) else x['基金类型s'],axis=1)
|
815
|
+
|
816
|
+
if fund_type == 'LOF':
|
817
|
+
df['基金类型s']=df.apply(lambda x: True if (fund_type in x['基金类型'] or fund_type in x['基金简称']) else x['基金类型s'],axis=1)
|
818
|
+
df['基金类型s']=df.apply(lambda x: False if ('FOF' in x['基金类型'] or 'FOF' in x['基金简称']) else x['基金类型s'],axis=1)
|
819
|
+
|
820
|
+
if fund_type == 'FOF-LOF':
|
821
|
+
df['基金类型s']=df.apply(lambda x: True if (fund_type in x['基金类型'] or fund_type in x['基金简称']) else x['基金类型s'],axis=1)
|
822
|
+
|
823
|
+
|
780
824
|
df=df[df['基金类型s']==True]
|
781
825
|
|
782
826
|
if info_type == '单位净值':
|
@@ -828,8 +872,11 @@ def oef_rank_china(indicator='单位净值',fund_type='全部类型',rank=5):
|
|
828
872
|
|
829
873
|
if rank >= 0:
|
830
874
|
dfprint10=dfprint.head(rank)
|
875
|
+
order="前"
|
831
876
|
else:
|
832
877
|
dfprint10=dfprint.tail(-rank)
|
878
|
+
order="后"
|
879
|
+
titletxt=titletxt+"("+order+str(abs(rank))+"名,降序排列)"
|
833
880
|
#print(dfprint10.to_string(index=False))
|
834
881
|
"""
|
835
882
|
print(dfprint10)
|
@@ -860,7 +907,8 @@ def oef_rank_china(indicator='单位净值',fund_type='全部类型',rank=5):
|
|
860
907
|
footnote2="基金类型:"+str(fund_type)+'\n'
|
861
908
|
footnote3="净值日期:"+str(nvdate)+','
|
862
909
|
import datetime; todaydt = datetime.date.today()
|
863
|
-
footnote4="数据来源:东方财富/天天基金,"+str(todaydt)
|
910
|
+
#footnote4="数据来源:东方财富/天天基金,"+str(todaydt)
|
911
|
+
footnote4="数据来源:新浪财经/天天基金"
|
864
912
|
footnote=footnote1+footnote2+footnote3+footnote4
|
865
913
|
|
866
914
|
df_display_CSS(dfprint10,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=4, \
|
@@ -1140,7 +1188,8 @@ def oef_trend_china(ticker,start,end='today',indicator='净值', \
|
|
1140
1188
|
|
1141
1189
|
#==============================================================================
|
1142
1190
|
if __name__=='__main__':
|
1143
|
-
|
1191
|
+
indicator="万份收益"
|
1192
|
+
rank=5
|
1144
1193
|
|
1145
1194
|
def mmf_rank_china(indicator="7日年化%",rank=5):
|
1146
1195
|
"""
|
@@ -1153,7 +1202,7 @@ def mmf_rank_china(indicator="7日年化%",rank=5):
|
|
1153
1202
|
"""
|
1154
1203
|
indicator_list=["万份收益","7日年化%"]
|
1155
1204
|
if indicator not in indicator_list:
|
1156
|
-
print(" #Warning(mmf_rank_china): unsupported indicator",indicator
|
1205
|
+
print(" #Warning(mmf_rank_china): unsupported indicator",indicator)
|
1157
1206
|
print(" Supported indicators:",indicator_list)
|
1158
1207
|
#indicator="7日年化%"
|
1159
1208
|
return None
|
@@ -1167,9 +1216,10 @@ def mmf_rank_china(indicator="7日年化%",rank=5):
|
|
1167
1216
|
collist=list(df)
|
1168
1217
|
nvname1=collist[2]
|
1169
1218
|
nvname2=collist[3]
|
1170
|
-
if df[nvname1].eq('').all():
|
1219
|
+
if df[nvname1].eq('').all() or df[nvname1].eq('---').all():
|
1171
1220
|
nvname1=collist[5]
|
1172
1221
|
nvname2=collist[6]
|
1222
|
+
|
1173
1223
|
nvdate=nvname1[:10]
|
1174
1224
|
|
1175
1225
|
#修改列名
|
@@ -1185,7 +1235,11 @@ def mmf_rank_china(indicator="7日年化%",rank=5):
|
|
1185
1235
|
if indicator=='万份收益':
|
1186
1236
|
dfb.sort_values(by=['万份收益'],ascending=False,inplace=True)
|
1187
1237
|
dfprint=dfb[['基金简称','基金代码','万份收益','7日年化%']].copy()
|
1188
|
-
titletxt="
|
1238
|
+
titletxt="中国货币型基金排名:万份收益金额(元)"
|
1239
|
+
|
1240
|
+
if len(dfprint)==0:
|
1241
|
+
print(" #Warning(mmf_rank_china): zero records found for",indicator)
|
1242
|
+
return None
|
1189
1243
|
|
1190
1244
|
#设置打印
|
1191
1245
|
dfprint.dropna(inplace=True)
|
@@ -1198,13 +1252,16 @@ def mmf_rank_china(indicator="7日年化%",rank=5):
|
|
1198
1252
|
|
1199
1253
|
if rank >0:
|
1200
1254
|
dfprint10=dfprint.head(rank)
|
1255
|
+
order="前"
|
1201
1256
|
else:
|
1202
1257
|
dfprint10=dfprint.tail(-rank)
|
1258
|
+
order="后"
|
1259
|
+
titletxt=titletxt+"("+order+str(abs(rank))+"名,降序)"
|
1203
1260
|
|
1204
|
-
footnote1="
|
1261
|
+
footnote1="披露信息的货币型基金数量:"+str(len(dfprint))+','
|
1205
1262
|
footnote2=str(nvdate)+'\n'
|
1206
1263
|
import datetime; todaydt = datetime.date.today()
|
1207
|
-
footnote3="
|
1264
|
+
footnote3="数据来源:新浪财经/天天基金,"+str(todaydt)+"统计"
|
1208
1265
|
footnote=footnote1+footnote2+footnote3
|
1209
1266
|
|
1210
1267
|
df_display_CSS(dfprint10,titletxt=titletxt,footnote=footnote,facecolor='papayawhip',decimals=4, \
|
@@ -1346,6 +1403,7 @@ def etf_rank_china(indicator='单位净值',fund_type='全部类型',rank=5):
|
|
1346
1403
|
|
1347
1404
|
df=df[df['基金类型s']==True]
|
1348
1405
|
|
1406
|
+
|
1349
1407
|
#df=df.replace('---',0)
|
1350
1408
|
if info_type == '单位净值':
|
1351
1409
|
df=df.replace('---',0)
|
@@ -1400,8 +1458,12 @@ def etf_rank_china(indicator='单位净值',fund_type='全部类型',rank=5):
|
|
1400
1458
|
|
1401
1459
|
if rank >=0:
|
1402
1460
|
dfprint10=dfprint.head(rank)
|
1461
|
+
order="前"
|
1403
1462
|
else:
|
1404
1463
|
dfprint10=dfprint.tail(-rank)
|
1464
|
+
order="后"
|
1465
|
+
titletxt=titletxt+"("+order+str(abs(rank))+"名,降序排列)"
|
1466
|
+
|
1405
1467
|
#print(dfprint10.to_string(index=False))
|
1406
1468
|
"""
|
1407
1469
|
print(dfprint10)
|
@@ -1908,12 +1970,12 @@ def pef_product_china(rank=20,facecolor='papayawhip',DEBUG=False):
|
|
1908
1970
|
titletxt="中国私募基金管理人的产品运营状态"
|
1909
1971
|
typelist=list(set(list(product_df['运行状态'])))
|
1910
1972
|
dfprint=pd.DataFrame(columns=['运营状态','产品数量','数量占比%'])
|
1911
|
-
totalnum=0
|
1973
|
+
#totalnum=0
|
1912
1974
|
for t in typelist:
|
1913
1975
|
df_sub=product_df[product_df['运行状态']==t]
|
1914
1976
|
n=len(list(set(list(df_sub['基金名称']))))
|
1915
1977
|
if n==0: continue
|
1916
|
-
totalnum=totalnum+n
|
1978
|
+
#totalnum=totalnum+n
|
1917
1979
|
|
1918
1980
|
s=pd.Series({'运营状态':t,'产品数量':n})
|
1919
1981
|
try:
|