siat 3.1.11__py3-none-any.whl → 3.1.13__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 +127 -38
- siat/markowitz2.py +122 -47
- siat/sector_china.py +100 -33
- 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/stock_technical.py +2 -2
- siat/translate.py +18 -14
- siat/translate_20240606.py +4206 -0
- {siat-3.1.11.dist-info → siat-3.1.13.dist-info}/METADATA +1 -1
- {siat-3.1.11.dist-info → siat-3.1.13.dist-info}/RECORD +18 -17
- {siat-3.1.11.dist-info → siat-3.1.13.dist-info}/WHEEL +0 -0
- {siat-3.1.11.dist-info → siat-3.1.13.dist-info}/top_level.txt +0 -0
siat/security_prices.py
CHANGED
@@ -716,6 +716,10 @@ if __name__=='__main__':
|
|
716
716
|
ticker='100303.SZ'
|
717
717
|
ticker_type='auto'
|
718
718
|
|
719
|
+
ticker='000418'
|
720
|
+
ticker='180202.SZ'
|
721
|
+
ticker_type='fund'
|
722
|
+
|
719
723
|
fromdate='2024-1-1'; todate='2024-3-31'
|
720
724
|
adjust=''
|
721
725
|
|
@@ -768,14 +772,15 @@ def get_price_ak_cn(ticker,fromdate,todate,adjust='',ticker_type='auto'):
|
|
768
772
|
df=None
|
769
773
|
found=df_have_data(df)
|
770
774
|
|
771
|
-
|
775
|
+
#股票(无复权)指数/基金/债券
|
772
776
|
if found != 'Found':
|
773
777
|
if ticker_type in ['auto','stock'] and suffix not in ['SW']:
|
774
778
|
try:
|
775
779
|
#指数/股票/基金
|
776
780
|
df = ak.stock_zh_index_daily(symbol=ticker2)
|
777
781
|
df['Date']=df['date'].apply(lambda x: pd.to_datetime(x))
|
778
|
-
except:
|
782
|
+
except:
|
783
|
+
df=None
|
779
784
|
found=df_have_data(df)
|
780
785
|
|
781
786
|
if found != 'Found':
|
@@ -783,7 +788,8 @@ def get_price_ak_cn(ticker,fromdate,todate,adjust='',ticker_type='auto'):
|
|
783
788
|
#特殊函数(不考虑复权)
|
784
789
|
df=ak.stock_zh_a_cdr_daily(ticker2,start1,end1)
|
785
790
|
df['Date']=pd.to_datetime(df['date'])
|
786
|
-
except:
|
791
|
+
except:
|
792
|
+
df=None
|
787
793
|
found=df_have_data(df)
|
788
794
|
|
789
795
|
if found != 'Found':
|
@@ -806,7 +812,8 @@ def get_price_ak_cn(ticker,fromdate,todate,adjust='',ticker_type='auto'):
|
|
806
812
|
#优先抓取交易所债券行情
|
807
813
|
df = exchange_bond_price(ticker2,fromdate,todate,graph=False,data_crop=False)
|
808
814
|
df['Date']=df.index
|
809
|
-
except:
|
815
|
+
except:
|
816
|
+
df=None
|
810
817
|
found=df_have_data(df)
|
811
818
|
|
812
819
|
#已找到证券信息,但在规定时段无数据
|
@@ -818,7 +825,8 @@ def get_price_ak_cn(ticker,fromdate,todate,adjust='',ticker_type='auto'):
|
|
818
825
|
df=ak.stock_zh_a_daily(ticker2,start1,end1,adjust=adjust)
|
819
826
|
df['Date']=df['date']
|
820
827
|
df['Date']=df['Date'].dt.tz_localize(None)
|
821
|
-
except:
|
828
|
+
except:
|
829
|
+
df=None
|
822
830
|
found=df_have_data(df)
|
823
831
|
|
824
832
|
if found != 'Found':
|
@@ -826,7 +834,8 @@ def get_price_ak_cn(ticker,fromdate,todate,adjust='',ticker_type='auto'):
|
|
826
834
|
#接着查找指数
|
827
835
|
df = ak.stock_zh_index_daily(symbol=ticker2)
|
828
836
|
df['Date']=df['date'].apply(lambda x: pd.to_datetime(x))
|
829
|
-
except:
|
837
|
+
except:
|
838
|
+
df=None
|
830
839
|
found=df_have_data(df)
|
831
840
|
|
832
841
|
if found != 'Found':
|
@@ -834,7 +843,8 @@ def get_price_ak_cn(ticker,fromdate,todate,adjust='',ticker_type='auto'):
|
|
834
843
|
#最后查找开放式基金
|
835
844
|
df =get_price_oef_china(ticker2,fromdate,todate)
|
836
845
|
df['Date']=df.index
|
837
|
-
except:
|
846
|
+
except:
|
847
|
+
df=None
|
838
848
|
found=df_have_data(df)
|
839
849
|
|
840
850
|
#基金。因部分债券代码(特别是国债)与基金代码重合,需要甄别!
|
@@ -843,18 +853,20 @@ def get_price_ak_cn(ticker,fromdate,todate,adjust='',ticker_type='auto'):
|
|
843
853
|
#优先抓取开放式基金单位净值
|
844
854
|
df =get_price_oef_china(ticker2,fromdate,todate)
|
845
855
|
df['Date']=df.index
|
846
|
-
except:
|
856
|
+
except:
|
857
|
+
df=None
|
847
858
|
found=df_have_data(df)
|
848
859
|
|
849
860
|
#已找到证券信息,但在规定时段无数据
|
850
|
-
if found=='Empty': return df
|
861
|
+
#if found=='Empty': return df
|
851
862
|
|
852
|
-
if found != 'Found':
|
863
|
+
if found != 'Found': #未找到,其次从股票爬虫抓取基金行情
|
853
864
|
try:
|
854
865
|
df=ak.stock_zh_a_daily(ticker2,start1,end1,adjust=adjust)
|
855
866
|
df['Date']=df['date']
|
856
867
|
df['Date']=df['Date'].dt.tz_localize(None)
|
857
|
-
except:
|
868
|
+
except:
|
869
|
+
df=None
|
858
870
|
found=df_have_data(df)
|
859
871
|
|
860
872
|
if found != 'Found':
|
@@ -862,23 +874,26 @@ def get_price_ak_cn(ticker,fromdate,todate,adjust='',ticker_type='auto'):
|
|
862
874
|
#再次查找股票指数
|
863
875
|
df = ak.stock_zh_index_daily(symbol=ticker2)
|
864
876
|
df['Date']=df['date'].apply(lambda x: pd.to_datetime(x))
|
865
|
-
except:
|
877
|
+
except:
|
878
|
+
df=None
|
866
879
|
found=df_have_data(df)
|
867
880
|
|
868
881
|
if found != 'Found':
|
869
882
|
try:
|
870
|
-
|
883
|
+
#最后从债券爬虫查找基金信息
|
871
884
|
df = exchange_bond_price(ticker2,fromdate,todate,graph=False,data_crop=False)
|
872
885
|
df['Date']=df.index
|
873
|
-
except:
|
886
|
+
except:
|
887
|
+
df=None
|
874
888
|
found=df_have_data(df)
|
875
889
|
|
876
|
-
|
890
|
+
#申万指数
|
877
891
|
if suffix in ['SW']:
|
878
892
|
try:
|
879
893
|
df = fetch_price_swindex(prefix,fromdate,todate)
|
880
894
|
df['Date']=df.index
|
881
|
-
except:
|
895
|
+
except:
|
896
|
+
df=None
|
882
897
|
#print(" #Error(get_price_ak_cn): failed to retrieve prices for",ticker)
|
883
898
|
found=df_have_data(df)
|
884
899
|
|
siat/security_trend2.py
CHANGED
@@ -71,8 +71,6 @@ if __name__=='__main__':
|
|
71
71
|
source='auto'
|
72
72
|
ticker_type='auto'
|
73
73
|
|
74
|
-
df=security_trend(ticker,indicator=indicator)
|
75
|
-
|
76
74
|
#测试组4
|
77
75
|
ticker=["GCZ25.CMX","GCZ24.CMX"]
|
78
76
|
indicator='Close'
|
@@ -80,6 +78,16 @@ if __name__=='__main__':
|
|
80
78
|
end="2020-6-30"
|
81
79
|
|
82
80
|
|
81
|
+
#测试组5
|
82
|
+
ticker=["180801.SZ","180101.SZ"]
|
83
|
+
indicator='Close'
|
84
|
+
start="2024-1-1"
|
85
|
+
end="2024-5-30"
|
86
|
+
ticker_type='fund'
|
87
|
+
|
88
|
+
df=security_trend(ticker,indicator,start,end,ticker_type=ticker_type)
|
89
|
+
|
90
|
+
|
83
91
|
def security_trend(ticker,indicator='Close', \
|
84
92
|
start='default',end='default', \
|
85
93
|
|
siat/stock.py
CHANGED
@@ -596,11 +596,14 @@ if __name__ =="__main__":
|
|
596
596
|
average_value=False
|
597
597
|
|
598
598
|
ticker='600519.SS'; indicator='Exp Ret Volatility%'
|
599
|
-
fromdate='2022-3-25'; todate='2024-3-25'
|
600
599
|
|
600
|
+
ticker='180202.SZ'
|
601
|
+
ticker_type='fund'
|
601
602
|
|
602
|
-
|
603
|
-
|
603
|
+
fromdate='2024-1-1'; todate='2024-5-25'
|
604
|
+
|
605
|
+
|
606
|
+
df=security_indicator(ticker,indicator,fromdate,todate,ticker_type=ticker_type)
|
604
607
|
|
605
608
|
def security_indicator(ticker,indicator,fromdate,todate, \
|
606
609
|
zeroline=False, \
|
@@ -624,6 +627,20 @@ def security_indicator(ticker,indicator,fromdate,todate, \
|
|
624
627
|
print(" #Error(security_indicator): zero record found for",ticker)
|
625
628
|
return None
|
626
629
|
|
630
|
+
#奇怪错误:仅仅抓取到1个记录,应对办法:改变开始时间,貌似仅存在于REIT基金
|
631
|
+
if len(pricedf)==1:
|
632
|
+
fromdate1=date_adjust(fromdate,adjust=-365*2)
|
633
|
+
pricedf,found=get_price_1ticker_mixed(ticker=ticker,fromdate=fromdate1, \
|
634
|
+
todate=todate,source=source,ticker_type=ticker_type)
|
635
|
+
if len(pricedf)==1:
|
636
|
+
fromdate1=date_adjust(fromdate,adjust=-365*1)
|
637
|
+
pricedf,found=get_price_1ticker_mixed(ticker=ticker,fromdate=fromdate1, \
|
638
|
+
todate=todate,source=source,ticker_type=ticker_type)
|
639
|
+
if len(pricedf)==1:
|
640
|
+
fromdate1=fromdate
|
641
|
+
pricedf,found=get_price_1ticker_mixed(ticker=ticker,fromdate=fromdate1, \
|
642
|
+
todate=todate,source=source,ticker_type=ticker_type)
|
643
|
+
|
627
644
|
# 去掉时区信息,避免日期时区冲突问题
|
628
645
|
pricedf=df_index_timezone_remove(pricedf)
|
629
646
|
"""
|
siat/stock_info.pickle
CHANGED
Binary file
|
siat/stock_technical.py
CHANGED
@@ -2009,7 +2009,7 @@ def security_bollinger(ticker,fromdate,todate,boll_days=20, \
|
|
2009
2009
|
print(" #Error(security_bollinger): price info not found for",ticker)
|
2010
2010
|
return None
|
2011
2011
|
if found not in ['Found']:
|
2012
|
-
print(" #Error(): ticker info either inaccessible or not found for",ticker)
|
2012
|
+
print(" #Error(security_bollinger): ticker info either inaccessible or not found for",ticker)
|
2013
2013
|
return None
|
2014
2014
|
|
2015
2015
|
# 滚动均值与标准差
|
@@ -2045,7 +2045,7 @@ def security_bollinger(ticker,fromdate,todate,boll_days=20, \
|
|
2045
2045
|
data_label=False,resample_freq='6H',smooth=smooth, \
|
2046
2046
|
date_range=date_range,date_freq=date_freq,date_fmt='%Y-%m-%d', \
|
2047
2047
|
colorlist=colorlist,lslist=lslist,lwlist=lwlist, \
|
2048
|
-
band_area=['上(压力)线','下(支撑)线'],mark_end=mark_end)
|
2048
|
+
band_area=['上(压力)线','下(支撑)线'],mark_end=mark_end,loc=loc)
|
2049
2049
|
|
2050
2050
|
return df1
|
2051
2051
|
|
siat/translate.py
CHANGED
@@ -1211,10 +1211,10 @@ def codetranslate0(code):
|
|
1211
1211
|
["162204",'泰达宏利行业混合A'],["015601",'泰达宏利行业混合C'],
|
1212
1212
|
["660015",'农银行业轮动混合A'],["015850",'农银行业轮动混合C'],
|
1213
1213
|
|
1214
|
-
["SPY",'SPDR
|
1215
|
-
["SPYG",'SPDR
|
1216
|
-
["VOO",'Vanguard
|
1217
|
-
["VOOV",'Vanguard
|
1214
|
+
["SPY",'SPDR标普500ETF'],['SPYD','SPDR标普500股利优先ETF'],
|
1215
|
+
["SPYG",'SPDR标普500成长优先ETF'],['SPYV','SPDR标普500价值优先ETF'],
|
1216
|
+
["VOO",'Vanguard标普500ETF'],['VOOG','Vanguard标普500成长优先ETF'],
|
1217
|
+
["VOOV",'Vanguard标普500价值优先ETF'],['IVV','iShares标普500ETF'],
|
1218
1218
|
["DGT",'SPDR Global Dow ETF'],['ICF','iShares C&S REIT ETF'],
|
1219
1219
|
["FRI",'FT S&P REIT Index Fund'],['IEMG','iShares核心MSCI新兴市场ETF'],
|
1220
1220
|
['245710.KS','KINDEX越南VN30指数ETF'],['02801.HK','iShares核心MSCI中国指数ETF'],
|
@@ -2990,16 +2990,15 @@ if __name__=='__main__':
|
|
2990
2990
|
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
2991
2991
|
leading_blanks=2
|
2992
2992
|
|
2993
|
-
def print_tickerlist_sharelist(tickerlist,sharelist,leading_blanks=2):
|
2993
|
+
def print_tickerlist_sharelist(tickerlist,sharelist,leading_blanks=2,ticker_type='auto'):
|
2994
2994
|
"""
|
2995
|
-
|
2995
|
+
功能:纵向打印投资组合的成分股和持股比例
|
2996
2996
|
输入:
|
2997
|
-
tickerlist
|
2997
|
+
tickerlist:成分股列表
|
2998
2998
|
sharelist:持股份额列表
|
2999
2999
|
leading_blanks:打印前导空格数
|
3000
|
-
注意:放在本文件中的原因是需要使用函数codetranslate
|
3001
3000
|
"""
|
3002
|
-
|
3001
|
+
#检查成分股与持仓比例个数是否一致
|
3003
3002
|
if not (len(tickerlist) == len(sharelist)):
|
3004
3003
|
print(" #Error(): numbers of tickers and shares are not same")
|
3005
3004
|
return
|
@@ -3017,12 +3016,16 @@ def print_tickerlist_sharelist(tickerlist,sharelist,leading_blanks=2):
|
|
3017
3016
|
sharelist_array = np.array(sharelist)
|
3018
3017
|
total_shares=sharelist_array.sum()
|
3019
3018
|
weights=sharelist_array/total_shares
|
3019
|
+
|
3020
|
+
#预处理ticker_type
|
3021
|
+
ticker_type_list=ticker_type_preprocess_mticker_mixed(tickerlist,ticker_type)
|
3020
3022
|
|
3021
3023
|
import pandas as pd
|
3022
3024
|
df=pd.DataFrame(columns=['证券代码','证券名称','持仓比例'])
|
3023
3025
|
for t in tickerlist:
|
3024
3026
|
pos=tickerlist.index(t)
|
3025
|
-
|
3027
|
+
tt=ticker_type_list[pos]
|
3028
|
+
tname=ticker_name(t,tt)
|
3026
3029
|
tweight=weights[pos]
|
3027
3030
|
|
3028
3031
|
row=pd.Series({'证券代码':t,'证券名称':tname,'持仓比例':tweight})
|
@@ -3060,7 +3063,7 @@ def print_tickerlist_sharelist(tickerlist,sharelist,leading_blanks=2):
|
|
3060
3063
|
|
3061
3064
|
if __name__=='__main__':
|
3062
3065
|
print_tickerlist_sharelist(tickerlist,sharelist,leading_blanks=2)
|
3063
|
-
|
3066
|
+
|
3064
3067
|
#==============================================================================
|
3065
3068
|
#==============================================================================
|
3066
3069
|
#整理证券名称
|
@@ -3225,9 +3228,10 @@ def ticker1_name(ticker,ticker_type='auto'):
|
|
3225
3228
|
return ticker
|
3226
3229
|
|
3227
3230
|
#快速转换
|
3228
|
-
|
3229
|
-
|
3230
|
-
|
3231
|
+
if ticker_type=='auto':
|
3232
|
+
tname=codetranslate(ticker)
|
3233
|
+
if tname != ticker: #翻译成功
|
3234
|
+
return tname
|
3231
3235
|
|
3232
3236
|
symbol=ticker1_cvt2yahoo(ticker)
|
3233
3237
|
|