siat 3.2.20__py3-none-any.whl → 3.2.30__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/allin.py +3 -0
- siat/common.py +32 -7
- siat/grafix.py +41 -7
- siat/luchy_draw.py +252 -0
- siat/market_china.py +171 -0
- siat/risk_adjusted_return2.py +22 -13
- siat/security_trend2.py +3 -2
- siat/stock.py +45 -12
- siat/stock_technical.py +137 -78
- siat/translate.py +13 -0
- {siat-3.2.20.dist-info → siat-3.2.30.dist-info}/METADATA +1 -1
- {siat-3.2.20.dist-info → siat-3.2.30.dist-info}/RECORD +14 -13
- {siat-3.2.20.dist-info → siat-3.2.30.dist-info}/WHEEL +0 -0
- {siat-3.2.20.dist-info → siat-3.2.30.dist-info}/top_level.txt +0 -0
siat/stock_technical.py
CHANGED
@@ -90,7 +90,7 @@ if __name__ =="__main__":
|
|
90
90
|
|
91
91
|
BIAS_days=[6,12,24]
|
92
92
|
|
93
|
-
|
93
|
+
CCI_days=[6,12]
|
94
94
|
|
95
95
|
WR_days=[10,6]
|
96
96
|
|
@@ -183,13 +183,15 @@ def calc_technical(df,start,end,technical='MACD', \
|
|
183
183
|
|
184
184
|
TRIX_day=12,TRIX_madays=[20], \
|
185
185
|
BIAS_days=[6,12,24], \
|
186
|
-
|
186
|
+
CCI_days=[6,12], \
|
187
187
|
WR_days=[10,6], \
|
188
188
|
ROC_day=12,ROC_madays=[6], \
|
189
189
|
DMI_DIdays=[14],DMI_ADXdays=[6], \
|
190
190
|
|
191
|
-
MFI_day=14,MFI_madays=[
|
192
|
-
|
191
|
+
MFI_day=14,MFI_madays=[6], \
|
192
|
+
|
193
|
+
#提出选择12日或25日,移动均线为10日
|
194
|
+
MOM_day=12,MOM_madays=6, \
|
193
195
|
|
194
196
|
#需要显示SAR
|
195
197
|
SAR_day=4,SAR_madays=[5,20], \
|
@@ -201,7 +203,7 @@ def calc_technical(df,start,end,technical='MACD', \
|
|
201
203
|
TSF_day=14,TSF_madays=[5,20], \
|
202
204
|
|
203
205
|
#需要显示AD
|
204
|
-
|
206
|
+
AD_madays=[5], \
|
205
207
|
|
206
208
|
#不建议使用复权价,因为最高最低价和开盘价没有复权价!
|
207
209
|
indicator='Close', \
|
@@ -586,11 +588,11 @@ def calc_technical(df,start,end,technical='MACD', \
|
|
586
588
|
TRIX_madays=[TRIX_madays]
|
587
589
|
for d in TRIX_madays:
|
588
590
|
df['trix_ma'+str(d)] = talib.MA(df['trix'],timeperiod=d)
|
589
|
-
|
591
|
+
"""
|
590
592
|
if not more_details:
|
591
593
|
#不保留TRIX
|
592
594
|
df.drop(columns = ['trix'],inplace=True)
|
593
|
-
|
595
|
+
"""
|
594
596
|
#=========== DMA: 平均线差
|
595
597
|
"""
|
596
598
|
计算公式:
|
@@ -640,11 +642,14 @@ def calc_technical(df,start,end,technical='MACD', \
|
|
640
642
|
"""
|
641
643
|
计算过程:
|
642
644
|
CCI(N日) = (TP-MA)÷MD÷0.015
|
643
|
-
说明:TP = (最高价+最低价+收盘价)÷3;
|
645
|
+
说明:TP = (最高价+最低价+收盘价)÷3;
|
646
|
+
MA=最近N日收盘价的累计之和÷N;
|
647
|
+
MD=最近N日(MA-收盘价)的累计之和÷N;
|
648
|
+
0.015为计算系数;N为计算周期,默认为14天
|
644
649
|
"""
|
645
650
|
if technical=='CCI':
|
646
|
-
|
647
|
-
df['cci'] = talib.CCI(df['High'],df['Low'],df[indicator],timeperiod=
|
651
|
+
"""
|
652
|
+
df['cci'] = talib.CCI(df['High'],df['Low'],df[indicator],timeperiod=CCI_days)
|
648
653
|
|
649
654
|
if not isinstance(CCI_madays,list):
|
650
655
|
CCI_madays=[CCI_madays]
|
@@ -655,6 +660,14 @@ def calc_technical(df,start,end,technical='MACD', \
|
|
655
660
|
if not more_details:
|
656
661
|
#不保留指标本身
|
657
662
|
df.drop(columns = ['cci'],inplace=True)
|
663
|
+
"""
|
664
|
+
if not isinstance(CCI_days,list):
|
665
|
+
CCI_days=[CCI_days]
|
666
|
+
|
667
|
+
for d in CCI_days:
|
668
|
+
df['cci'+str(d)] = talib.CCI(df['High'],df['Low'],df[indicator],timeperiod=d)
|
669
|
+
|
670
|
+
|
658
671
|
#=========== W%R: 威廉指标
|
659
672
|
"""
|
660
673
|
N日W%R = [(Hn-Ct)/(Hn-Ln)]*100
|
@@ -733,11 +746,11 @@ def calc_technical(df,start,end,technical='MACD', \
|
|
733
746
|
MFI_madays=[MFI_madays]
|
734
747
|
for d in MFI_madays:
|
735
748
|
df['mfi_ma'+str(d)] = df['mfi'].rolling(window=d).mean()
|
736
|
-
|
749
|
+
"""
|
737
750
|
if not more_details:
|
738
751
|
#不保留指标本身
|
739
752
|
df.drop(columns = ['mfi'],inplace=True)
|
740
|
-
|
753
|
+
"""
|
741
754
|
#=========== MOM:动量指标
|
742
755
|
"""
|
743
756
|
|
@@ -749,11 +762,11 @@ def calc_technical(df,start,end,technical='MACD', \
|
|
749
762
|
MOM_madays=[MOM_madays]
|
750
763
|
for d in MOM_madays:
|
751
764
|
df['mom_ma'+str(d)] = df['mom'].rolling(window=d).mean()
|
752
|
-
|
765
|
+
"""
|
753
766
|
if not more_details:
|
754
767
|
#不保留指标本身
|
755
768
|
df.drop(columns = ['mom'],inplace=True)
|
756
|
-
|
769
|
+
"""
|
757
770
|
#=========== BETA:贝塔系数
|
758
771
|
"""
|
759
772
|
动态贝塔系数?
|
@@ -794,18 +807,17 @@ def calc_technical(df,start,end,technical='MACD', \
|
|
794
807
|
"""
|
795
808
|
if technical=='AD':
|
796
809
|
|
797
|
-
#df['ad'] = talib.AD(df['High'],df['Low'],df[indicator],df['Volume'],timeperiod=AD_day)
|
798
810
|
df['ad'] = talib.AD(df['High'],df['Low'],df[indicator],df['Volume'])
|
799
811
|
|
800
812
|
if not isinstance(AD_madays,list):
|
801
813
|
AD_madays=[AD_madays]
|
802
814
|
for d in AD_madays:
|
803
815
|
df['ad_ma'+str(d)] = df['ad'].rolling(window=d).mean()
|
804
|
-
|
816
|
+
"""
|
805
817
|
if not more_details:
|
806
818
|
#不保留指标本身
|
807
819
|
df.drop(columns = ['ad'],inplace=True)
|
808
|
-
|
820
|
+
"""
|
809
821
|
|
810
822
|
|
811
823
|
#过滤日期===================================================================
|
@@ -854,7 +866,8 @@ def security_MACD(ticker,start='default',end='default', \
|
|
854
866
|
MACD_fastperiod=12,MACD_slowperiod=26,MACD_signalperiod=9, \
|
855
867
|
resample_freq='6H',smooth=True,linewidth=1.5, \
|
856
868
|
loc1='lower left',loc2='lower right', \
|
857
|
-
graph=['ALL'],printout=True,ticker_type='auto',source='auto'
|
869
|
+
graph=['ALL'],printout=True,ticker_type='auto',source='auto', \
|
870
|
+
price_line_color='red'):
|
858
871
|
"""
|
859
872
|
套壳函数:可用于股票、交易所债券、交易所基金、部分期货期权(限美股)
|
860
873
|
"""
|
@@ -864,7 +877,8 @@ def security_MACD(ticker,start='default',end='default', \
|
|
864
877
|
MACD_signalperiod=MACD_signalperiod, \
|
865
878
|
resample_freq=resample_freq,smooth=smooth,linewidth=linewidth, \
|
866
879
|
loc1=loc1,loc2=loc2, \
|
867
|
-
graph=graph,printout=printout,ticker_type=ticker_type,source=source
|
880
|
+
graph=graph,printout=printout,ticker_type=ticker_type,source=source, \
|
881
|
+
price_line_color=price_line_color)
|
868
882
|
return df
|
869
883
|
|
870
884
|
|
@@ -873,7 +887,8 @@ def stock_MACD(ticker,start='default',end='default', \
|
|
873
887
|
MACD_fastperiod=12,MACD_slowperiod=26,MACD_signalperiod=9, \
|
874
888
|
resample_freq='H',smooth=True,linewidth=1.5, \
|
875
889
|
loc1='lower left',loc2='lower right', \
|
876
|
-
graph=['ALL'],printout=True,ticker_type='auto',source='auto'
|
890
|
+
graph=['ALL'],printout=True,ticker_type='auto',source='auto', \
|
891
|
+
price_line_color='red'):
|
877
892
|
"""
|
878
893
|
功能:计算股票的技术分析指标MACD
|
879
894
|
输入:df,四种股价Open/Close/High/Low,成交量Volume
|
@@ -998,7 +1013,7 @@ def stock_MACD(ticker,start='default',end='default', \
|
|
998
1013
|
if ('EMA' in graph) or ('ALL' in graph):
|
999
1014
|
EMA_cols=[]
|
1000
1015
|
for mad in EMA_days:
|
1001
|
-
col='EMA'+str(mad)+'
|
1016
|
+
col='EMA'+str(mad)+'指数移动平均线'
|
1002
1017
|
EMA_cols=EMA_cols+[col]
|
1003
1018
|
df[col] = talib.EMA(df['Close'],timeperiod=mad)
|
1004
1019
|
|
@@ -1029,13 +1044,13 @@ def stock_MACD(ticker,start='default',end='default', \
|
|
1029
1044
|
|
1030
1045
|
df3=df1[['Close']+EMA_cols]
|
1031
1046
|
df3.rename(columns={'Close':'收盘价'},inplace=True)
|
1032
|
-
title_txt="证券价格走势分析:"+ticker_name(ticker,ticker_type)+"
|
1047
|
+
title_txt="证券价格走势分析:"+ticker_name(ticker,ticker_type)+",指数移动平均线"
|
1033
1048
|
draw_lines(df3,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
1034
1049
|
data_label=False,resample_freq=resample_freq,smooth=smooth,linewidth=linewidth*2)
|
1035
1050
|
|
1036
1051
|
if printout:
|
1037
1052
|
if len(dft3)!=0:
|
1038
|
-
print("\n==
|
1053
|
+
print("\n== 指数移动平均线交叉 ==")
|
1039
1054
|
alignlist=['left','center']
|
1040
1055
|
print(dft3[['日期','交叉类型']].to_markdown(index=False,tablefmt='plain',colalign=alignlist))
|
1041
1056
|
else:
|
@@ -1121,8 +1136,8 @@ def stock_MACD(ticker,start='default',end='default', \
|
|
1121
1136
|
"""
|
1122
1137
|
macd_plus=df4[df4['柱线MACD']>=0]
|
1123
1138
|
macd_minus=df4[df4['柱线MACD']<=0]
|
1124
|
-
ax.bar(macd_plus.index,macd_plus['柱线MACD'],color='red')
|
1125
|
-
ax.bar(macd_minus.index,macd_minus['柱线MACD'],color='green',label='柱线MACD')
|
1139
|
+
ax.bar(macd_plus.index,macd_plus['柱线MACD'],color='red',alpha=0.5)
|
1140
|
+
ax.bar(macd_minus.index,macd_minus['柱线MACD'],color='green',label='柱线MACD',alpha=0.5)
|
1126
1141
|
|
1127
1142
|
# 绘制水平辅助线
|
1128
1143
|
#plt.axhline(y=0,label='指标零线',color='cyan',linestyle=':',linewidth=linewidth*2)
|
@@ -1149,7 +1164,7 @@ def stock_MACD(ticker,start='default',end='default', \
|
|
1149
1164
|
df5=df4
|
1150
1165
|
|
1151
1166
|
ax2 = ax.twinx()
|
1152
|
-
ax2.plot(df5['收盘价'],label='收盘价',linewidth=linewidth,color=
|
1167
|
+
ax2.plot(df5['收盘价'],label='收盘价',linewidth=linewidth,color=price_line_color,ls='--')
|
1153
1168
|
|
1154
1169
|
# 右侧坐标轴标记
|
1155
1170
|
ax2.set_ylabel('收盘价',fontsize=ylabel_txt_size)
|
@@ -1225,7 +1240,8 @@ def security_RSI(ticker,start='default',end='default', \
|
|
1225
1240
|
RSI_days=[6,12,24],RSI_lines=[20,50,80], \
|
1226
1241
|
resample_freq='6H',smooth=True,linewidth=1.5, \
|
1227
1242
|
loc1='lower left',loc2='lower right', \
|
1228
|
-
graph=['ALL'],printout=True,ticker_type='auto',source='auto'
|
1243
|
+
graph=['ALL'],printout=True,ticker_type='auto',source='auto', \
|
1244
|
+
price_line_color='red'):
|
1229
1245
|
"""
|
1230
1246
|
套壳函数,除了股票,还可用于交易所债券和交易所基金(如ETF和REITS)
|
1231
1247
|
"""
|
@@ -1233,7 +1249,8 @@ def security_RSI(ticker,start='default',end='default', \
|
|
1233
1249
|
RSI_days=RSI_days,RSI_lines=RSI_lines, \
|
1234
1250
|
resample_freq=resample_freq,smooth=smooth,linewidth=linewidth, \
|
1235
1251
|
loc1=loc1,loc2=loc2, \
|
1236
|
-
graph=graph,printout=printout,ticker_type=ticker_type,source=source
|
1252
|
+
graph=graph,printout=printout,ticker_type=ticker_type,source=source, \
|
1253
|
+
price_line_color=price_line_color)
|
1237
1254
|
return df
|
1238
1255
|
|
1239
1256
|
|
@@ -1241,7 +1258,8 @@ def stock_RSI(ticker,start='default',end='default', \
|
|
1241
1258
|
RSI_days=[6,12,24],RSI_lines=[20,50,80], \
|
1242
1259
|
resample_freq='H',smooth=True,linewidth=1.5, \
|
1243
1260
|
loc1='lower left',loc2='lower right', \
|
1244
|
-
graph=['ALL'],printout=True,ticker_type='auto',source='auto'
|
1261
|
+
graph=['ALL'],printout=True,ticker_type='auto',source='auto', \
|
1262
|
+
price_line_color='red'):
|
1245
1263
|
"""
|
1246
1264
|
功能:计算股票的技术分析指标RSI
|
1247
1265
|
输入:df,四种股价Open/Close/High/Low,成交量Volume
|
@@ -1295,6 +1313,10 @@ def stock_RSI(ticker,start='default',end='default', \
|
|
1295
1313
|
return None
|
1296
1314
|
|
1297
1315
|
#============ 计算RSI
|
1316
|
+
if len(RSI_days) < 3:
|
1317
|
+
print(" #Warning(stock_RSI): RSI_days parameter needs 3 different days")
|
1318
|
+
return None
|
1319
|
+
|
1298
1320
|
#df['rsi'] = talib.RSI(df['Close'], timeperiod=RSI_days)
|
1299
1321
|
RSI_cols=[]
|
1300
1322
|
RSI_seq=1
|
@@ -1383,7 +1405,7 @@ def stock_RSI(ticker,start='default',end='default', \
|
|
1383
1405
|
df5=df4
|
1384
1406
|
|
1385
1407
|
ax2 = ax.twinx()
|
1386
|
-
ax2.plot(df5['收盘价'],label='收盘价',linewidth=linewidth,color=
|
1408
|
+
ax2.plot(df5['收盘价'],label='收盘价',linewidth=linewidth,color=price_line_color,ls='--')
|
1387
1409
|
|
1388
1410
|
# 右侧坐标轴标记
|
1389
1411
|
ax2.set_ylabel('收盘价',fontsize=ylabel_txt_size)
|
@@ -1466,7 +1488,8 @@ def security_KDJ(ticker,start='default',end='default', \
|
|
1466
1488
|
KDJ_days=[9,3,3],matypes=[0,0],KDJ_lines=[20,50,80], \
|
1467
1489
|
resample_freq='6H',smooth=True,linewidth=1.5, \
|
1468
1490
|
loc1='lower left',loc2='lower right', \
|
1469
|
-
graph=['ALL'],printout=True,ticker_type='auto',source='auto'
|
1491
|
+
graph=['ALL'],printout=True,ticker_type='auto',source='auto', \
|
1492
|
+
price_line_color='red'):
|
1470
1493
|
"""
|
1471
1494
|
套壳函数
|
1472
1495
|
"""
|
@@ -1474,7 +1497,8 @@ def security_KDJ(ticker,start='default',end='default', \
|
|
1474
1497
|
KDJ_days=KDJ_days,matypes=matypes,KDJ_lines=KDJ_lines, \
|
1475
1498
|
resample_freq=resample_freq,smooth=smooth,linewidth=linewidth, \
|
1476
1499
|
loc1=loc1,loc2=loc2, \
|
1477
|
-
graph=graph,printout=printout,ticker_type=ticker_type,source=source
|
1500
|
+
graph=graph,printout=printout,ticker_type=ticker_type,source=source, \
|
1501
|
+
price_line_color=price_line_color)
|
1478
1502
|
return df
|
1479
1503
|
|
1480
1504
|
|
@@ -1482,7 +1506,8 @@ def stock_KDJ(ticker,start='default',end='default', \
|
|
1482
1506
|
KDJ_days=[9,3,3],matypes=[0,0],KDJ_lines=[20,50,80], \
|
1483
1507
|
resample_freq='H',smooth=True,linewidth=1.5, \
|
1484
1508
|
loc1='lower left',loc2='lower right', \
|
1485
|
-
graph=['ALL'],printout=True,ticker_type='auto',source='auto'
|
1509
|
+
graph=['ALL'],printout=True,ticker_type='auto',source='auto', \
|
1510
|
+
price_line_color='red'):
|
1486
1511
|
"""
|
1487
1512
|
功能:计算股票的技术分析指标KDJ
|
1488
1513
|
输入:df,四种股价Open/Close/High/Low,成交量Volume
|
@@ -1674,7 +1699,7 @@ def stock_KDJ(ticker,start='default',end='default', \
|
|
1674
1699
|
df5=df4
|
1675
1700
|
|
1676
1701
|
ax2 = ax.twinx()
|
1677
|
-
ax2.plot(df5['收盘价'],label='收盘价',linewidth=linewidth,color=
|
1702
|
+
ax2.plot(df5['收盘价'],label='收盘价',linewidth=linewidth,color=price_line_color,ls='--')
|
1678
1703
|
|
1679
1704
|
# 右侧坐标轴标记
|
1680
1705
|
ax2.set_ylabel('收盘价',fontsize=ylabel_txt_size)
|
@@ -2442,6 +2467,8 @@ if __name__ =="__main__":
|
|
2442
2467
|
def security_technical(ticker,start='default',end='default', \
|
2443
2468
|
MA_days=[5,20],EMA_days=[5,20], \
|
2444
2469
|
MACD_fastperiod=12,MACD_slowperiod=26,MACD_signalperiod=9, \
|
2470
|
+
|
2471
|
+
#RSI参数个数必须为3个,否则出错
|
2445
2472
|
RSI_days=[6,12,24],RSI_lines=[20,50,80], \
|
2446
2473
|
KDJ_days=[9,3,3],matypes=[0,0],KDJ_lines=[20,50,80], \
|
2447
2474
|
boll_days=20,boll_years=7, \
|
@@ -2450,7 +2477,8 @@ def security_technical(ticker,start='default',end='default', \
|
|
2450
2477
|
graph=['ALL'],printout=False, \
|
2451
2478
|
date_range=False,date_freq=False,annotate=False, \
|
2452
2479
|
technical=['MACD'],indicator='Close', \
|
2453
|
-
ticker_type='auto',source='auto'
|
2480
|
+
ticker_type='auto',source='auto', \
|
2481
|
+
price_line_color='red'):
|
2454
2482
|
|
2455
2483
|
"""
|
2456
2484
|
功能:技术分析中的MACD/RSI/KDJ/布林带,支持教学演示,支持参数调节。
|
@@ -2509,21 +2537,24 @@ def security_technical(ticker,start='default',end='default', \
|
|
2509
2537
|
MACD_fastperiod=MACD_fastperiod,MACD_slowperiod=MACD_slowperiod,MACD_signalperiod=MACD_signalperiod, \
|
2510
2538
|
resample_freq=resample_freq,smooth=smooth,linewidth=linewidth, \
|
2511
2539
|
loc1=loc1,loc2=loc2, \
|
2512
|
-
graph=graph1,printout=printout,ticker_type=ticker_type,source=source
|
2540
|
+
graph=graph1,printout=printout,ticker_type=ticker_type,source=source, \
|
2541
|
+
price_line_color=price_line_color)
|
2513
2542
|
|
2514
2543
|
if 'RSI' in technical1:
|
2515
2544
|
df=security_RSI(ticker=ticker,start=fromdate,end=todate, \
|
2516
2545
|
RSI_days=RSI_days,RSI_lines=RSI_lines, \
|
2517
2546
|
resample_freq=resample_freq,smooth=smooth,linewidth=linewidth, \
|
2518
2547
|
loc1=loc1,loc2=loc2, \
|
2519
|
-
graph=graph1,printout=printout,ticker_type=ticker_type,source=source
|
2548
|
+
graph=graph1,printout=printout,ticker_type=ticker_type,source=source, \
|
2549
|
+
price_line_color=price_line_color)
|
2520
2550
|
|
2521
2551
|
if 'KDJ' in technical1:
|
2522
2552
|
df=security_KDJ(ticker=ticker,start=fromdate,end=todate, \
|
2523
2553
|
KDJ_days=KDJ_days,matypes=matypes,KDJ_lines=KDJ_lines, \
|
2524
2554
|
resample_freq=resample_freq,smooth=smooth,linewidth=linewidth, \
|
2525
2555
|
loc1=loc1,loc2=loc2, \
|
2526
|
-
graph=graph1,printout=printout,ticker_type=ticker_type,source=source
|
2556
|
+
graph=graph1,printout=printout,ticker_type=ticker_type,source=source, \
|
2557
|
+
price_line_color=price_line_color)
|
2527
2558
|
|
2528
2559
|
if 'Bollinger' in technical1 and 'Close' in indicator1:
|
2529
2560
|
df=security_Bollinger(ticker=ticker,start=fromdate,end=todate,boll_days=boll_days, \
|
@@ -2586,21 +2617,21 @@ if __name__ =="__main__":
|
|
2586
2617
|
TRIX_day=12; TRIX_madays=20
|
2587
2618
|
DMA_fastperiod=10; DMA_slowperiod=50; DMA_madays=10
|
2588
2619
|
BIAS_days=[6,12,24]
|
2589
|
-
|
2620
|
+
CCI_days=[6,12]
|
2590
2621
|
WR_days=[10,6]
|
2591
2622
|
ROC_day=12; ROC_madays=6
|
2592
2623
|
DMI_DIdays=14; DMI_ADXdays=6
|
2593
|
-
MFI_day=14; MFI_madays=[
|
2594
|
-
MOM_day=
|
2624
|
+
MFI_day=14; MFI_madays=[6]
|
2625
|
+
MOM_day=12; MOM_madays=6
|
2595
2626
|
SAR_day=4; SAR_madays=[5,20]
|
2596
2627
|
BETA_day=5; BETA_madays=[5,20]
|
2597
2628
|
TSF_day=14; TSF_madays=[5,10]
|
2598
|
-
|
2629
|
+
AD_madays=[5]
|
2599
2630
|
|
2600
2631
|
|
2601
2632
|
ticker='002594.SZ';ticker_type='auto'
|
2602
2633
|
start='2024-5-1'; end='2024-6-13'; ahead_days=30*8
|
2603
|
-
technical='
|
2634
|
+
technical='BIAS'; indicator='Close'
|
2604
2635
|
|
2605
2636
|
attention_values=[0,25,50,75]
|
2606
2637
|
more_details=True
|
@@ -2661,11 +2692,11 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
2661
2692
|
|
2662
2693
|
DMA_fastperiod=10,DMA_slowperiod=50,DMA_madays=[10], \
|
2663
2694
|
|
2664
|
-
TRIX_day=12,TRIX_madays=[
|
2695
|
+
TRIX_day=12,TRIX_madays=[20], \
|
2665
2696
|
|
2666
2697
|
BIAS_days=[6,12,24], \
|
2667
2698
|
|
2668
|
-
|
2699
|
+
CCI_days=[6,12], \
|
2669
2700
|
|
2670
2701
|
WR_days=[13,34,89], \
|
2671
2702
|
|
@@ -2673,9 +2704,10 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
2673
2704
|
|
2674
2705
|
DMI_DIdays=7,DMI_ADXdays=6, \
|
2675
2706
|
|
2676
|
-
#资金流:
|
2677
|
-
MFI_day=14,MFI_madays=[
|
2678
|
-
|
2707
|
+
#资金流:
|
2708
|
+
MFI_day=14,MFI_madays=[6], \
|
2709
|
+
|
2710
|
+
MOM_day=12,MOM_madays=6, \
|
2679
2711
|
|
2680
2712
|
#需要显示SAR
|
2681
2713
|
SAR_day=4,SAR_madays=[5,20], \
|
@@ -2687,7 +2719,7 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
2687
2719
|
TSF_day=14,TSF_madays=[5,10], \
|
2688
2720
|
|
2689
2721
|
#需要显示AD
|
2690
|
-
|
2722
|
+
AD_madays=[], \
|
2691
2723
|
|
2692
2724
|
#数据提前量,用于前置计算指标的移动平均值
|
2693
2725
|
ahead_days=30*8, \
|
@@ -2696,8 +2728,8 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
2696
2728
|
resample_freq='2H',smooth=True,linewidth=1.5, \
|
2697
2729
|
date_range=False,date_freq=False, \
|
2698
2730
|
|
2699
|
-
|
2700
|
-
annotate=
|
2731
|
+
#启用
|
2732
|
+
annotate=True, \
|
2701
2733
|
|
2702
2734
|
#除了MACD外,其他指标均应为ALL
|
2703
2735
|
graph=['ALL'], \
|
@@ -2709,11 +2741,11 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
2709
2741
|
|
2710
2742
|
#价格线的绘图参数
|
2711
2743
|
#price_line_style=(0,(1,1)), \
|
2712
|
-
price_line_style=
|
2744
|
+
price_line_style=(0,(3,1,1,1,1,1)), \
|
2713
2745
|
price_line_color=['red','green'], \
|
2714
2746
|
price_line_width=1,price_line_marker='o', \
|
2715
2747
|
marker_sizes=[30,120,250], \
|
2716
|
-
|
2748
|
+
):
|
2717
2749
|
"""
|
2718
2750
|
功能:计算和绘制证券技术分析指标的简易图,仅供进一步探索使用,仅用于单个证券(股债基)
|
2719
2751
|
|
@@ -2819,7 +2851,7 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
2819
2851
|
|
2820
2852
|
TRIX_day=TRIX_day,TRIX_madays=TRIX_madays, \
|
2821
2853
|
BIAS_days=BIAS_days, \
|
2822
|
-
|
2854
|
+
CCI_days=CCI_days, \
|
2823
2855
|
WR_days=WR_days, \
|
2824
2856
|
ROC_day=ROC_day,ROC_madays=ROC_madays, \
|
2825
2857
|
DMI_DIdays=DMI_DIdays,DMI_ADXdays=DMI_ADXdays, \
|
@@ -2837,7 +2869,7 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
2837
2869
|
TSF_day=TSF_day,TSF_madays=TSF_madays, \
|
2838
2870
|
|
2839
2871
|
#需要显示AD
|
2840
|
-
|
2872
|
+
AD_madays=AD_madays, \
|
2841
2873
|
|
2842
2874
|
indicator=indicator, \
|
2843
2875
|
more_details=more_details)
|
@@ -2976,7 +3008,10 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
2976
3008
|
except:
|
2977
3009
|
ax3.set_facecolor('papayawhip')
|
2978
3010
|
|
2979
|
-
color_list=['k','g','b','c','m','
|
3011
|
+
color_list=['k','g','b','c','m','yellowgreen','tomato','lime','orange','deepskyblue']
|
3012
|
+
|
3013
|
+
if isinstance(attention_values,int):
|
3014
|
+
attention_values=[attention_values]
|
2980
3015
|
attention_draws=[False] * len(attention_values)
|
2981
3016
|
|
2982
3017
|
for l in tech_line_collist:
|
@@ -2988,8 +3023,29 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
2988
3023
|
if labeltxt =='DIF':
|
2989
3024
|
labeltxt='快线(DIF)'
|
2990
3025
|
|
2991
|
-
ax.plot(df1.index,df1[l],label=labeltxt)
|
2992
|
-
|
3026
|
+
axline, = ax.plot(df1.index,df1[l],label=labeltxt)
|
3027
|
+
last_line_color = axline.get_color()
|
3028
|
+
|
3029
|
+
if annotate:
|
3030
|
+
df_end=df1.tail(1)
|
3031
|
+
# df_end[c]必须为数值类型,否则可能出错
|
3032
|
+
y_end = df_end[l].min() # 末端的y坐标
|
3033
|
+
x_end = df_end[l].idxmin() # 末端值的x坐标
|
3034
|
+
"""
|
3035
|
+
if annotate_value: #在标记曲线名称的同时标记其末端数值
|
3036
|
+
y1=str(int(y_end)) if abs(y_end) >= 100 else str(round(y_end,2)) if abs(y_end) >= 10 else str(round(y_end,3))
|
3037
|
+
plt.annotate(text=c+':'+y1,
|
3038
|
+
xy=(x_end, y_end),
|
3039
|
+
xytext=(x_end, y_end),color=last_line_color)
|
3040
|
+
else:
|
3041
|
+
plt.annotate(text=c,
|
3042
|
+
xy=(x_end, y_end),
|
3043
|
+
xytext=(x_end, y_end),color=last_line_color)
|
3044
|
+
"""
|
3045
|
+
ax.annotate(text=''+l.upper(),
|
3046
|
+
xy=(x_end, y_end),
|
3047
|
+
xytext=(x_end, y_end),color=last_line_color,fontsize=legend_txt_size)
|
3048
|
+
|
2993
3049
|
#判断是否绘制关注线
|
2994
3050
|
lmax=df1[l].max(); lmin=df1[l].min()
|
2995
3051
|
|
@@ -3002,7 +3058,7 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
3002
3058
|
|
3003
3059
|
#如果需要绘制关注线,且尚未绘制过,则绘制
|
3004
3060
|
if line_al and not attention_draws[pos]:
|
3005
|
-
ax.axhline(y=attention_values[pos],ls=
|
3061
|
+
ax.axhline(y=attention_values[pos],ls='dotted',c=color_list[pos],linewidth=1)
|
3006
3062
|
|
3007
3063
|
attention_draws[pos]=True
|
3008
3064
|
|
@@ -3012,20 +3068,21 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
3012
3068
|
ax.set_ylabel(ylabeltxt1,fontsize=ylabel_txt_size)
|
3013
3069
|
|
3014
3070
|
#对图例项目排序
|
3015
|
-
|
3016
|
-
|
3017
|
-
|
3018
|
-
|
3019
|
-
|
3020
|
-
|
3021
|
-
|
3022
|
-
|
3023
|
-
|
3024
|
-
|
3025
|
-
|
3026
|
-
|
3027
|
-
|
3028
|
-
|
3071
|
+
if not annotate:
|
3072
|
+
# 获取图例句柄和标签
|
3073
|
+
handles, labels = ax.get_legend_handles_labels()
|
3074
|
+
|
3075
|
+
# 指定显示顺序
|
3076
|
+
labels_sorted = sort_list_by_len(labels,reverse=False)
|
3077
|
+
handles_sorted = []
|
3078
|
+
for l in labels_sorted:
|
3079
|
+
pos=labels.index(l)
|
3080
|
+
h=handles[pos]
|
3081
|
+
handles_sorted =handles_sorted +[h]
|
3082
|
+
|
3083
|
+
# 在指定位置添加新的图例,并按照指定顺序显示
|
3084
|
+
ax.legend(handles=handles_sorted,labels=labels_sorted,loc=loc1,fontsize=legend_txt_size)
|
3085
|
+
#ax.legend(loc=loc1,fontsize=legend_txt_size)
|
3029
3086
|
|
3030
3087
|
interval=int(len(df1)/10)+1
|
3031
3088
|
ax.xaxis.set_major_locator(mdates.DayLocator(interval=interval)) # 隔interval天一个标记
|
@@ -3057,8 +3114,8 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
3057
3114
|
ax2.set_ylabel(ylabeltxt2,fontsize=ylabel_txt_size)
|
3058
3115
|
|
3059
3116
|
#细灰线先画出轮廓
|
3060
|
-
ax2.plot(df1.index,df1[indicator],label=
|
3061
|
-
linestyle=price_line_style,color='
|
3117
|
+
ax2.plot(df1.index,df1[indicator],label=ylabeltxt2, \
|
3118
|
+
linestyle=price_line_style,color='k',lw=2)
|
3062
3119
|
|
3063
3120
|
#不同颜色绘制涨跌价格线
|
3064
3121
|
first_time=True; second_time=False
|
@@ -3067,11 +3124,13 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
3067
3124
|
if df1seg['up_down'].values[0] >=0:
|
3068
3125
|
seg_color=price_line_color1
|
3069
3126
|
#labeltxt=ylabeltxt2+'(当日↑)'
|
3070
|
-
labeltxt=ylabeltxt2+'(当日阳线)'
|
3127
|
+
#labeltxt=ylabeltxt2+'(当日阳线)'
|
3128
|
+
labeltxt='当日↑'
|
3071
3129
|
else:
|
3072
3130
|
seg_color=price_line_color2
|
3073
3131
|
#labeltxt=ylabeltxt2+'(当日↓)'
|
3074
|
-
labeltxt=ylabeltxt2+'(当日阴线)'
|
3132
|
+
#labeltxt=ylabeltxt2+'(当日阴线)'
|
3133
|
+
labeltxt='当日↓'
|
3075
3134
|
|
3076
3135
|
if first_time:
|
3077
3136
|
first_time=False; second_time=True
|
@@ -3083,7 +3142,7 @@ def security_technical2(ticker,start='default',end='default',technical='MACD', \
|
|
3083
3142
|
ax2.scatter(df1seg.index,df1seg[indicator], \
|
3084
3143
|
s=df1seg['marker_size'], \
|
3085
3144
|
label=labeltxt, \
|
3086
|
-
linestyle=':',color=seg_color,lw=price_line_width,marker=price_line_marker)
|
3145
|
+
linestyle=':',color=seg_color,lw=price_line_width,marker=price_line_marker,alpha=0.5)
|
3087
3146
|
|
3088
3147
|
ax2.legend(loc=loc2,fontsize=legend_txt_size)
|
3089
3148
|
|
siat/translate.py
CHANGED
@@ -3297,7 +3297,20 @@ def ticker1_name(ticker,ticker_type='auto'):
|
|
3297
3297
|
#注意:绘图时有基于‘基金’字符的判断,决定显示收盘价还是单位净值
|
3298
3298
|
if '基金' not in tname: tname=tname + '基金'
|
3299
3299
|
break
|
3300
|
+
|
3301
|
+
#加港股标记
|
3302
|
+
if ('.HK' in ticker) and not ("港股" in tname):
|
3303
|
+
tname=tname+"港股"
|
3304
|
+
#加港股人民币柜台标志
|
3305
|
+
HKcode=ticker.split('.')[0]
|
3306
|
+
if len(HKcode)==5 and HKcode[0]=='8' and not ("人民币" in tname):
|
3307
|
+
tname=tname+"(人民币)"
|
3300
3308
|
|
3309
|
+
#加美股标记
|
3310
|
+
"""
|
3311
|
+
if len(ticker.split('.'))==1 and not ("美股" in tname):
|
3312
|
+
tname=tname+"美股"
|
3313
|
+
"""
|
3301
3314
|
return tname
|
3302
3315
|
|
3303
3316
|
#==============================================================================
|