siat 3.0.4__py3-none-any.whl → 3.0.15__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 +2 -1
- siat/capm_beta2.py +51 -22
- siat/common.py +30 -3
- siat/fama_french.py +2 -0
- siat/financials_china.py +28 -21
- siat/financials_china2.py +199 -106
- siat/grafix.py +109 -45
- siat/markowitz.py +25 -14
- siat/markowitz2.py +2446 -0
- siat/risk_adjusted_return2.py +169 -85
- siat/security_trend2.py +39 -25
- siat/stock.py +127 -47
- siat/stock_china.py +1 -1
- siat/stock_technical.py +33 -12
- siat/valuation.py +34 -7
- {siat-3.0.4.dist-info → siat-3.0.15.dist-info}/METADATA +1 -1
- {siat-3.0.4.dist-info → siat-3.0.15.dist-info}/RECORD +19 -18
- {siat-3.0.4.dist-info → siat-3.0.15.dist-info}/WHEEL +1 -1
- {siat-3.0.4.dist-info → siat-3.0.15.dist-info}/top_level.txt +0 -0
siat/security_trend2.py
CHANGED
@@ -87,7 +87,7 @@ def security_trend(ticker,indicator='Close', \
|
|
87
87
|
|
88
88
|
kline=False,kline_demo=False,mav=[5,10,20], \
|
89
89
|
|
90
|
-
|
90
|
+
dividend=False,split=False, \
|
91
91
|
|
92
92
|
ret_type='Annual Ret%',RF=0,regression_period=365,market_index="auto", \
|
93
93
|
sortby='tpw_mean',trailing=7,trend_threshhold=0.05, \
|
@@ -95,11 +95,15 @@ def security_trend(ticker,indicator='Close', \
|
|
95
95
|
graph=True,twinx=False,loc1='best',loc2='best', \
|
96
96
|
datatag=False,power=0, \
|
97
97
|
smooth=True,date_range=False,date_freq=False, \
|
98
|
-
|
98
|
+
|
99
|
+
preprocess='none',scaling_option='change%', \
|
100
|
+
|
99
101
|
annotate=False,annotate_value=False, \
|
100
|
-
printout=False,source='auto', \
|
101
102
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
102
|
-
|
103
|
+
|
104
|
+
printout=False,source='auto', \
|
105
|
+
ticker_type='auto', \
|
106
|
+
facecolor='whitesmoke'):
|
103
107
|
|
104
108
|
"""
|
105
109
|
功能:组合指令,分析证券指标走势,支持多个证券、多个指标和多种绘图方式。
|
@@ -205,7 +209,8 @@ def security_trend(ticker,indicator='Close', \
|
|
205
209
|
fromdate=date_adjust(todate,adjust=-60)
|
206
210
|
if not isinstance(mav,list):
|
207
211
|
mav=[mav]
|
208
|
-
df=candlestick(stkcd=tickers[0],fromdate=fromdate,todate=todate,mav=mav,
|
212
|
+
df=candlestick(stkcd=tickers[0],fromdate=fromdate,todate=todate,mav=mav, \
|
213
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
209
214
|
return df
|
210
215
|
|
211
216
|
if kline and kline_demo:
|
@@ -216,30 +221,31 @@ def security_trend(ticker,indicator='Close', \
|
|
216
221
|
if start in ['default']:
|
217
222
|
fromdate=date_adjust(todate,adjust=-7)
|
218
223
|
|
219
|
-
df=candlestick_demo(tickers[0],fromdate=fromdate,todate=todate,
|
224
|
+
df=candlestick_demo(tickers[0],fromdate=fromdate,todate=todate, \
|
225
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
220
226
|
return df
|
221
227
|
|
222
228
|
# 处理股票分红和股票分拆:需要访问雅虎财经=====================================
|
223
|
-
if
|
229
|
+
if dividend:
|
224
230
|
if portfolio_flag:
|
225
|
-
print(" #Warning(security_trend):
|
231
|
+
print(" #Warning(security_trend): investment portfolio does not support for stock dividend")
|
226
232
|
return None
|
227
233
|
|
228
234
|
if start in ['default']:
|
229
235
|
fromdate=date_adjust(todate,adjust=-365*5)
|
230
|
-
print(" #Notice: try to access Yahoo for stock dividend
|
231
|
-
df=stock_dividend(ticker=tickers[0],fromdate=fromdate,todate=todate)
|
236
|
+
print(" #Notice: try to access Yahoo for stock dividend ...")
|
237
|
+
df=stock_dividend(ticker=tickers[0],fromdate=fromdate,todate=todate,facecolor=facecolor)
|
232
238
|
return df
|
233
239
|
|
234
|
-
if
|
240
|
+
if split:
|
235
241
|
if portfolio_flag:
|
236
|
-
print(" #Warning(security_trend):
|
242
|
+
print(" #Warning(security_trend): investment portfolio does not support for stock split")
|
237
243
|
return None
|
238
244
|
|
239
245
|
if start in ['default']:
|
240
246
|
fromdate=date_adjust(todate,adjust=-365*5)
|
241
|
-
print(" #Notice: try to access Yahoo for stock split
|
242
|
-
df=stock_split(ticker=tickers[0],fromdate=fromdate,todate=todate)
|
247
|
+
print(" #Notice: try to access Yahoo for stock split ...")
|
248
|
+
df=stock_split(ticker=tickers[0],fromdate=fromdate,todate=todate,facecolor=facecolor)
|
243
249
|
return df
|
244
250
|
|
245
251
|
|
@@ -354,7 +360,8 @@ def security_trend(ticker,indicator='Close', \
|
|
354
360
|
datatag=datatag,power=power,graph=graph, \
|
355
361
|
source=source, \
|
356
362
|
mark_top=mark_top,mark_bottom=mark_bottom, \
|
357
|
-
mark_end=mark_end,ticker_type=ticker_type
|
363
|
+
mark_end=mark_end,ticker_type=ticker_type, \
|
364
|
+
facecolor=facecolor)
|
358
365
|
return df
|
359
366
|
|
360
367
|
# 情形2:单个证券,两个普通指标,twinx==True =================================
|
@@ -362,7 +369,7 @@ def security_trend(ticker,indicator='Close', \
|
|
362
369
|
df=compare_security(tickers=tickers[0],measures=measures[:2], \
|
363
370
|
fromdate=fromdate,todate=todate,twinx=twinx, \
|
364
371
|
loc1=loc1,loc2=loc2,graph=graph,source=source, \
|
365
|
-
ticker_type=ticker_type)
|
372
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
366
373
|
return df
|
367
374
|
|
368
375
|
# 情形3:单个证券,两个及以上普通指标=========================================
|
@@ -374,7 +381,7 @@ def security_trend(ticker,indicator='Close', \
|
|
374
381
|
annotate=annotate,annotate_value=annotate_value, \
|
375
382
|
source=source,
|
376
383
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
377
|
-
ticker_type=ticker_type)
|
384
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
378
385
|
return df
|
379
386
|
|
380
387
|
# 情形4:两个证券,取第一个普通指标,twinx==True =============================
|
@@ -382,7 +389,7 @@ def security_trend(ticker,indicator='Close', \
|
|
382
389
|
df=compare_security(tickers=tickers,measures=measures[0], \
|
383
390
|
fromdate=fromdate,todate=todate,twinx=twinx, \
|
384
391
|
loc1=loc1,loc2=loc2,graph=graph,source=source, \
|
385
|
-
ticker_type=ticker_type)
|
392
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
386
393
|
return df
|
387
394
|
|
388
395
|
# 情形5:两个及以上证券,取第一个普通指标=====================================
|
@@ -403,7 +410,7 @@ def security_trend(ticker,indicator='Close', \
|
|
403
410
|
|
404
411
|
if ((ticker_num == 2 and not twinx) or ticker_num > 2) and indicator_group1:
|
405
412
|
df=compare_msecurity(tickers=tickers,measure=measures[0], \
|
406
|
-
|
413
|
+
start=fromdate,end=todate, \
|
407
414
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
408
415
|
preprocess=preprocess,linewidth=linewidth, \
|
409
416
|
scaling_option=scaling_option, \
|
@@ -412,7 +419,7 @@ def security_trend(ticker,indicator='Close', \
|
|
412
419
|
smooth=smooth, \
|
413
420
|
source=source, \
|
414
421
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
415
|
-
ticker_type=ticker_type)
|
422
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
416
423
|
return df
|
417
424
|
|
418
425
|
# 情形6:单个或多个证券,单个或多个RAR指标,支持投资组合=======================
|
@@ -423,16 +430,21 @@ def security_trend(ticker,indicator='Close', \
|
|
423
430
|
graph=graph,axhline_value=0,axhline_label='', \
|
424
431
|
printout=printout, \
|
425
432
|
sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
|
426
|
-
annotate=annotate,
|
427
|
-
|
433
|
+
annotate=annotate,annotate_value=annotate_value, \
|
434
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
435
|
+
mktidx=market_index,source=source, \
|
436
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
428
437
|
return df
|
429
438
|
|
430
439
|
# 情形7:单个或多个证券,CAPM贝塔系数=========================================
|
431
440
|
if indicator_group4:
|
432
441
|
df=compare_beta_security(ticker=tickers,start=fromdate,end=todate, \
|
433
442
|
RF=RF,regression_period=regression_period, \
|
434
|
-
graph=graph,
|
435
|
-
|
443
|
+
graph=graph,facecolor=facecolor, \
|
444
|
+
annotate=annotate,annotate_value=annotate_value, \
|
445
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
446
|
+
mktidx=market_index,source=source, \
|
447
|
+
ticker_type=ticker_type)
|
436
448
|
|
437
449
|
return df
|
438
450
|
|
@@ -442,7 +454,9 @@ def security_trend(ticker,indicator='Close', \
|
|
442
454
|
df=security_valuation(tickers=tickers,indicators=measures,start=fromdate,end=todate, \
|
443
455
|
preprocess=preprocess,scaling_option=scaling_option, \
|
444
456
|
twinx=twinx,loc1=loc1,loc2=loc2, \
|
445
|
-
graph=graph,
|
457
|
+
graph=graph,facecolor=facecolor, \
|
458
|
+
annotate=annotate,annotate_value=annotate_value, \
|
459
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
|
446
460
|
return df
|
447
461
|
|
448
462
|
# 其他未预料情形
|
siat/stock.py
CHANGED
@@ -455,7 +455,7 @@ if __name__ =="__main__":
|
|
455
455
|
|
456
456
|
|
457
457
|
def stock_price(ticker,fromdate,todate,adj=False, \
|
458
|
-
datatag=False,power=0,source='auto'):
|
458
|
+
datatag=False,power=0,source='auto',facecolor='whitesmoke'):
|
459
459
|
"""
|
460
460
|
功能:绘制证券价格折线图。
|
461
461
|
输入:证券代码ticker;开始日期fromdate,结束日期todate;
|
@@ -486,7 +486,8 @@ def stock_price(ticker,fromdate,todate,adj=False, \
|
|
486
486
|
|
487
487
|
collabel=ectranslate(pricetype)
|
488
488
|
ylabeltxt=collabel
|
489
|
-
plot_line(df1,pricetype,collabel,ylabeltxt,titletxt,footnote,
|
489
|
+
plot_line(df1,pricetype,collabel,ylabeltxt,titletxt,footnote, \
|
490
|
+
datatag=datatag,power=power,facecolor=facecolor)
|
490
491
|
|
491
492
|
return df
|
492
493
|
|
@@ -604,8 +605,9 @@ if __name__ =="__main__":
|
|
604
605
|
def security_indicator(ticker,indicator,fromdate,todate, \
|
605
606
|
zeroline=False, \
|
606
607
|
average_value=False, \
|
607
|
-
datatag=False,power=0,graph=True,source='auto',
|
608
|
-
mark_top=True,mark_bottom=True,mark_end=True,
|
608
|
+
datatag=False,power=0,graph=True,source='auto', \
|
609
|
+
mark_top=True,mark_bottom=True,mark_end=True, \
|
610
|
+
ticker_type='auto',facecolor='whitesmoke'):
|
609
611
|
"""
|
610
612
|
功能:单只证券的全部指标
|
611
613
|
"""
|
@@ -667,7 +669,8 @@ def security_indicator(ticker,indicator,fromdate,todate, \
|
|
667
669
|
|
668
670
|
plot_line(erdf3,indicator,collabel,ylabeltxt,titletxt,footnote,datatag=datatag, \
|
669
671
|
power=power,zeroline=zeroline,average_value=average_value, \
|
670
|
-
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end
|
672
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
673
|
+
facecolor=facecolor)
|
671
674
|
|
672
675
|
return erdf3
|
673
676
|
|
@@ -762,7 +765,7 @@ if __name__ =="__main__":
|
|
762
765
|
annotate=False
|
763
766
|
|
764
767
|
def security_mindicators(ticker,measures,fromdate,todate, \
|
765
|
-
graph=True,smooth=True,loc='best', \
|
768
|
+
graph=True,smooth=True,loc='best',facecolor='whitesmoke', \
|
766
769
|
date_range=False,date_freq=False, \
|
767
770
|
annotate=False,annotate_value=False, \
|
768
771
|
source='auto', \
|
@@ -837,7 +840,7 @@ def security_mindicators(ticker,measures,fromdate,todate, \
|
|
837
840
|
data_label=False,resample_freq='6H',smooth=smooth, \
|
838
841
|
date_range=date_range,date_freq=date_freq,date_fmt='%Y-%m-%d', \
|
839
842
|
annotate=annotate,annotate_value=annotate_value, \
|
840
|
-
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
|
843
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,facecolor=facecolor)
|
841
844
|
|
842
845
|
return df1
|
843
846
|
|
@@ -1204,7 +1207,8 @@ if __name__ =="__main__":
|
|
1204
1207
|
#==============================================================================
|
1205
1208
|
def comp_1security_2measures(df,measure1,measure2,twinx=False, \
|
1206
1209
|
loc1='upper left',loc2='lower left', \
|
1207
|
-
graph=True,
|
1210
|
+
graph=True,facecolor='whitesmoke', \
|
1211
|
+
ticker_type='auto'):
|
1208
1212
|
"""
|
1209
1213
|
功能:对比绘制一只证券两个指标的折线图。
|
1210
1214
|
输入:证券指标数据集df;行情类别measure1/2。
|
@@ -1249,7 +1253,7 @@ def comp_1security_2measures(df,measure1,measure2,twinx=False, \
|
|
1249
1253
|
#绘图
|
1250
1254
|
plot_line2(df,ticker,measure1,label1,df,ticker,measure2,label2, \
|
1251
1255
|
ylabeltxt,titletxt,footnote,zeroline=zeroline,twinx=twinx, \
|
1252
|
-
loc1=loc1,loc2=loc2)
|
1256
|
+
loc1=loc1,loc2=loc2,facecolor=facecolor)
|
1253
1257
|
|
1254
1258
|
return
|
1255
1259
|
|
@@ -1264,7 +1268,7 @@ if __name__ =="__main__":
|
|
1264
1268
|
#==============================================================================
|
1265
1269
|
def comp_2securities_1measure(df1,df2,measure,twinx=False,loc1='upper left', \
|
1266
1270
|
loc2='lower left',graph=True, \
|
1267
|
-
ticker_type=['auto','auto']):
|
1271
|
+
ticker_type=['auto','auto'],facecolor='whitesmoke'):
|
1268
1272
|
"""
|
1269
1273
|
功能:对比绘制两只证券的相同指标折线图。
|
1270
1274
|
输入:指标数据集df1/2;证券代码ticker1/2;指标类别measure。
|
@@ -1315,7 +1319,7 @@ def comp_2securities_1measure(df1,df2,measure,twinx=False,loc1='upper left', \
|
|
1315
1319
|
|
1316
1320
|
plot_line2(df1,ticker1,measure,label,df2,ticker2,measure,label, \
|
1317
1321
|
ylabeltxt,titletxt,footnote,zeroline=zeroline,twinx=twinx, \
|
1318
|
-
loc1=loc1,loc2=loc2)
|
1322
|
+
loc1=loc1,loc2=loc2,facecolor=facecolor)
|
1319
1323
|
|
1320
1324
|
return
|
1321
1325
|
|
@@ -1331,7 +1335,7 @@ if __name__ =="__main__":
|
|
1331
1335
|
#==============================================================================
|
1332
1336
|
def compare_security(tickers,measures,fromdate,todate,twinx=False, \
|
1333
1337
|
loc1='best',loc2='lower left',graph=True,source='auto', \
|
1334
|
-
ticker_type='auto'):
|
1338
|
+
ticker_type='auto',facecolor='whitesmoke'):
|
1335
1339
|
"""
|
1336
1340
|
功能:函数克隆compare_stock
|
1337
1341
|
"""
|
@@ -1341,13 +1345,13 @@ def compare_security(tickers,measures,fromdate,todate,twinx=False, \
|
|
1341
1345
|
result=compare_stock(tickers=tickers,measures=measures, \
|
1342
1346
|
fromdate=fromdate,todate=todate,twinx=twinx, \
|
1343
1347
|
loc1=loc1,loc2=loc2,graph=graph,source=source, \
|
1344
|
-
ticker_type=ticker_type)
|
1348
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
1345
1349
|
return result
|
1346
1350
|
|
1347
1351
|
#==============================================================================
|
1348
1352
|
def compare_stock(tickers,measures,fromdate,todate,twinx=False, \
|
1349
1353
|
loc1='best',loc2='lower left',graph=True,source='auto', \
|
1350
|
-
ticker_type='auto'):
|
1354
|
+
ticker_type='auto',facecolor='whitesmoke'):
|
1351
1355
|
"""
|
1352
1356
|
功能:对比绘制折线图:一只证券的两种测度,或两只证券的同一个测度。
|
1353
1357
|
输入:
|
@@ -1419,7 +1423,8 @@ def compare_stock(tickers,measures,fromdate,todate,twinx=False, \
|
|
1419
1423
|
#绘制单个证券的双指标对比图
|
1420
1424
|
if graph:
|
1421
1425
|
comp_1security_2measures(pltdf1,measure1,measure2,twinx=twinx, \
|
1422
|
-
loc1=loc1,loc2=loc2,graph=graph,
|
1426
|
+
loc1=loc1,loc2=loc2,graph=graph, \
|
1427
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
1423
1428
|
|
1424
1429
|
try:
|
1425
1430
|
result1=pltdf1[[measure1]]
|
@@ -1466,7 +1471,7 @@ def compare_stock(tickers,measures,fromdate,todate,twinx=False, \
|
|
1466
1471
|
if graph:
|
1467
1472
|
comp_2securities_1measure(pltdf1,pltdf2,measure1,twinx=twinx, \
|
1468
1473
|
loc1=loc1,loc2=loc2,graph=graph, \
|
1469
|
-
ticker_type=ticker_type_list)
|
1474
|
+
ticker_type=ticker_type_list,facecolor=facecolor)
|
1470
1475
|
|
1471
1476
|
try:
|
1472
1477
|
result1=pltdf1[[measure1]]
|
@@ -1531,7 +1536,7 @@ def compare_msecurity(tickers,measure,start,end, \
|
|
1531
1536
|
preprocess='none',linewidth=1.5, \
|
1532
1537
|
scaling_option='start', \
|
1533
1538
|
plus_sign=False, \
|
1534
|
-
graph=True,loc='best', \
|
1539
|
+
graph=True,loc='best',facecolor='whitesmoke', \
|
1535
1540
|
annotate=False,annotate_value=False, \
|
1536
1541
|
smooth=True, \
|
1537
1542
|
source='auto', \
|
@@ -1672,7 +1677,7 @@ def compare_msecurity(tickers,measure,start,end, \
|
|
1672
1677
|
draw_lines(dfs2,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
1673
1678
|
data_label=False,resample_freq='H',smooth=smooth,linewidth=linewidth,loc=loc, \
|
1674
1679
|
annotate=annotate,annotate_value=annotate_value,plus_sign=plus_sign, \
|
1675
|
-
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
|
1680
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,facecolor=facecolor)
|
1676
1681
|
|
1677
1682
|
return dfs2
|
1678
1683
|
|
@@ -1698,7 +1703,8 @@ if __name__ =="__main__":
|
|
1698
1703
|
|
1699
1704
|
|
1700
1705
|
def compare_mrrr(tickers,start,end,ret_measure='Exp Ret%',risk_type='Volatility', \
|
1701
|
-
annotate=False,graph=True,smooth=True,winsorize_limits=[0.05,0.05]
|
1706
|
+
annotate=False,graph=True,smooth=True,winsorize_limits=[0.05,0.05], \
|
1707
|
+
facecolor='whitesmoke'):
|
1702
1708
|
"""
|
1703
1709
|
功能:rrr = return-risk ratio
|
1704
1710
|
比较多个证券的简单收益-风险性价比,基于compare_msecurity
|
@@ -1759,7 +1765,8 @@ def compare_mrrr(tickers,start,end,ret_measure='Exp Ret%',risk_type='Volatility'
|
|
1759
1765
|
|
1760
1766
|
print("Rendering graphics ...")
|
1761
1767
|
draw_lines(df2,y_label,x_label,axhline_value=0,axhline_label='',title_txt=title_txt, \
|
1762
|
-
data_label=False,resample_freq='D',smooth=smooth,annotate=annotate
|
1768
|
+
data_label=False,resample_freq='D',smooth=smooth,annotate=annotate, \
|
1769
|
+
facecolor=facecolor)
|
1763
1770
|
|
1764
1771
|
return df2
|
1765
1772
|
|
@@ -1778,7 +1785,9 @@ if __name__ =="__main__":
|
|
1778
1785
|
df=compare_msecurity(tickers2,measure1,start,end)
|
1779
1786
|
df=compare_msecurity(tickers2,measure2,start,end)
|
1780
1787
|
#==============================================================================
|
1781
|
-
def stock_Kline(ticker,start='default',end='default',volume=True,
|
1788
|
+
def stock_Kline(ticker,start='default',end='default',volume=True, \
|
1789
|
+
style='China',facecolor='whitesmoke', \
|
1790
|
+
mav=[5,10]):
|
1782
1791
|
"""
|
1783
1792
|
套壳函数,为了与stock_MACD等函数相似
|
1784
1793
|
"""
|
@@ -1803,13 +1812,14 @@ def stock_Kline(ticker,start='default',end='default',volume=True,style='China',m
|
|
1803
1812
|
print(" #Warning(stock_Kline): invalid date for",start)
|
1804
1813
|
start=date_adjust(todate,adjust=-31)
|
1805
1814
|
|
1806
|
-
df=candlestick(stkcd=ticker,fromdate=start,todate=end,volume=volume,
|
1815
|
+
df=candlestick(stkcd=ticker,fromdate=start,todate=end,volume=volume, \
|
1816
|
+
style=style,facecolor=facecolor,mav=mav)
|
1807
1817
|
|
1808
1818
|
return df
|
1809
1819
|
|
1810
1820
|
|
1811
1821
|
def candlestick(stkcd,fromdate,todate,volume=True,style='China',mav=[5,10], \
|
1812
|
-
ticker_type='auto'):
|
1822
|
+
ticker_type='auto',facecolor='whitesmoke'):
|
1813
1823
|
"""
|
1814
1824
|
功能:绘制证券价格K线图。
|
1815
1825
|
输入:证券代码ticker;开始日期fromdate,结束日期todate;
|
@@ -1862,7 +1872,7 @@ def candlestick(stkcd,fromdate,todate,volume=True,style='China',mav=[5,10], \
|
|
1862
1872
|
marketcolors=mc,
|
1863
1873
|
edgecolor='black',
|
1864
1874
|
figcolor='white',
|
1865
|
-
facecolor=
|
1875
|
+
facecolor=facecolor,
|
1866
1876
|
gridcolor='cyan',
|
1867
1877
|
rc=mpfrc)
|
1868
1878
|
|
@@ -2002,7 +2012,7 @@ if __name__ =="__main__":
|
|
2002
2012
|
#==============================================================================
|
2003
2013
|
def stock_Kline_demo(ticker,start='default',end='default', \
|
2004
2014
|
colorup='red',colordown='green',width=0.5, \
|
2005
|
-
ticker_type='auto'):
|
2015
|
+
ticker_type='auto',facecolor='whitesmoke'):
|
2006
2016
|
"""
|
2007
2017
|
套壳函数,为了与stock_Kline保持一致
|
2008
2018
|
"""
|
@@ -2029,7 +2039,7 @@ def stock_Kline_demo(ticker,start='default',end='default', \
|
|
2029
2039
|
|
2030
2040
|
df=candlestick_demo(stkcd=ticker,fromdate=start,todate=end, \
|
2031
2041
|
colorup=colorup,colordown=colordown,width=width, \
|
2032
|
-
ticker_type=ticker_type)
|
2042
|
+
ticker_type=ticker_type,facecolor=facecolor)
|
2033
2043
|
|
2034
2044
|
return df
|
2035
2045
|
|
@@ -2043,7 +2053,7 @@ if __name__ =="__main__":
|
|
2043
2053
|
|
2044
2054
|
def candlestick_demo(stkcd,fromdate,todate, \
|
2045
2055
|
colorup='red',colordown='green',width=0.7, \
|
2046
|
-
ticker_type='auto'):
|
2056
|
+
ticker_type='auto',facecolor='whitesmoke'):
|
2047
2057
|
"""
|
2048
2058
|
功能:绘制证券价格K线图,叠加收盘价。
|
2049
2059
|
输入:证券代码ticker;开始日期fromdate,结束日期todate;
|
@@ -2100,6 +2110,7 @@ def candlestick_demo(stkcd,fromdate,todate, \
|
|
2100
2110
|
ax.xaxis_date() #draw dates in x axis
|
2101
2111
|
ax.autoscale_view()
|
2102
2112
|
fig.autofmt_xdate()
|
2113
|
+
fig.gca().set_facecolor(facecolor)
|
2103
2114
|
|
2104
2115
|
titletxt0=text_lang("K线图/蜡烛图演示:","Security Price Candlestick Demo: ")
|
2105
2116
|
titletxt=titletxt0 + ticker_name(str(stkcd),ticker_type=ticker_type)
|
@@ -2129,13 +2140,13 @@ if __name__ =="__main__":
|
|
2129
2140
|
fromdate="2021-1-1"
|
2130
2141
|
todate="2022-9-26"
|
2131
2142
|
|
2132
|
-
def stock_dividend(ticker,fromdate,todate):
|
2143
|
+
def stock_dividend(ticker,fromdate,todate,facecolor='whitesmoke',fontcolor='black'):
|
2133
2144
|
"""
|
2134
2145
|
功能:显示股票的分红历史
|
2135
2146
|
输入:单一股票代码
|
2136
2147
|
输出:分红历史
|
2137
2148
|
"""
|
2138
|
-
print("
|
2149
|
+
print(" Searching for the dividend info of stock",ticker,"... ...")
|
2139
2150
|
result,startdt,enddt=check_period(fromdate,todate)
|
2140
2151
|
if not result:
|
2141
2152
|
print(" #Error(stock_dividend): invalid period",fromdate,todate)
|
@@ -2174,6 +2185,7 @@ def stock_dividend(ticker,fromdate,todate):
|
|
2174
2185
|
pd.set_option('display.unicode.ambiguous_as_wide', True)
|
2175
2186
|
pd.set_option('display.unicode.east_asian_width', True)
|
2176
2187
|
pd.set_option('display.width', 180) # 设置打印宽度(**重要**)
|
2188
|
+
pd.set_option('display.colheader_justify', 'center')
|
2177
2189
|
"""
|
2178
2190
|
pd.set_option('display.max_columns', 1000)
|
2179
2191
|
pd.set_option('display.width', 1000)
|
@@ -2188,7 +2200,9 @@ def stock_dividend(ticker,fromdate,todate):
|
|
2188
2200
|
from datetime import datetime
|
2189
2201
|
weekdayfmt=lambda x : x.isoweekday()
|
2190
2202
|
divdf['Weekdayiso']= divdf['Index Date'].apply(weekdayfmt)
|
2191
|
-
wdlist=['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
|
2203
|
+
#wdlist=['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
|
2204
|
+
#wdlist=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
|
2205
|
+
wdlist=['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
|
2192
2206
|
wdfmt=lambda x : wdlist[x-1]
|
2193
2207
|
divdf['Weekday']= divdf['Weekdayiso'].apply(wdfmt)
|
2194
2208
|
|
@@ -2198,29 +2212,49 @@ def stock_dividend(ticker,fromdate,todate):
|
|
2198
2212
|
divprt=divdf[['Seq','Dividend Date','Weekday','Dividends']]
|
2199
2213
|
|
2200
2214
|
lang=check_language()
|
2215
|
+
tname=ticker_name(ticker,'stock')
|
2216
|
+
fromdatey2md=startdt.strftime('%y/%m/%d')
|
2217
|
+
todatey2md=enddt.strftime('%y/%m/%d')
|
2218
|
+
|
2201
2219
|
if lang == 'English':
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2220
|
+
titletxt=texttranslate("股票分红历史")+': '+tname
|
2221
|
+
periodtxt=texttranslate("历史期间:")+' '+fromdatey2md+"-"+todatey2md
|
2222
|
+
sourcetxt=texttranslate("数据来源: 雅虎财经,")
|
2205
2223
|
|
2206
2224
|
#修改列命为英文
|
2207
2225
|
divprt.columns = [texttranslate('序号'),texttranslate('日期'),texttranslate('星期'),texttranslate('股息')]
|
2208
|
-
|
2209
|
-
sourcetxt=texttranslate("数据来源: 雅虎财经,")
|
2210
2226
|
else:
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2227
|
+
titletxt="股票分红历史:"+tname
|
2228
|
+
periodtxt="期间: "+fromdatey2md+"-"+todatey2md
|
2229
|
+
sourcetxt="数据来源: 雅虎,"
|
2214
2230
|
|
2215
2231
|
#修改列命为中文
|
2216
2232
|
divprt.columns = ['序号','日期','星期','股息']
|
2217
|
-
|
2218
|
-
sourcetxt="数据来源: 雅虎财经,"
|
2219
|
-
|
2233
|
+
"""
|
2220
2234
|
print(divprt.to_string(index=False))
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2235
|
+
"""
|
2236
|
+
print(' ') #空一行
|
2237
|
+
|
2238
|
+
disph=divprt.style.hide() #不显示索引列
|
2239
|
+
dispp=disph.format(precision=4) #设置带有小数点的列精度调整为小数点后2位
|
2240
|
+
#设置标题/列名对齐
|
2241
|
+
dispt=dispp.set_caption(titletxt).set_table_styles(
|
2242
|
+
[{'selector':'caption', #设置标题
|
2243
|
+
'props':[('color','black'),('font-size','16px'),('font-weight','bold')]}, \
|
2244
|
+
{'selector':'th.col_heading', #设置列名
|
2245
|
+
'props':[('color','black'),('text-align','center'),('margin','auto')]}])
|
2246
|
+
#设置列数值对齐
|
2247
|
+
dispf=dispt.set_properties(**{'text-align':'center'})
|
2248
|
+
#设置前景背景颜色
|
2249
|
+
dispf2=dispf.set_properties(**{'background-color':facecolor,'color':fontcolor})
|
2250
|
+
|
2251
|
+
from IPython.display import display
|
2252
|
+
display(dispf2)
|
2253
|
+
|
2254
|
+
print(periodtxt)
|
2255
|
+
import datetime; todaydt=datetime.date.today(); todayy2md=todaydt.strftime('%y/%m/%d')
|
2256
|
+
#print('\n*** '+sourcetxt,today)
|
2257
|
+
print(sourcetxt,todayy2md)
|
2224
2258
|
|
2225
2259
|
return divdf
|
2226
2260
|
|
@@ -2231,13 +2265,13 @@ if __name__ =="__main__":
|
|
2231
2265
|
todate='2020-6-30'
|
2232
2266
|
|
2233
2267
|
#==============================================================================
|
2234
|
-
def stock_split(ticker,fromdate,todate):
|
2268
|
+
def stock_split(ticker,fromdate,todate,facecolor='whitesmoke',fontcolor='black'):
|
2235
2269
|
"""
|
2236
2270
|
功能:显示股票的分拆历史
|
2237
2271
|
输入:单一股票代码
|
2238
2272
|
输出:分拆历史
|
2239
2273
|
"""
|
2240
|
-
print("
|
2274
|
+
print(" Searching for the split info of stock",ticker,"... ...")
|
2241
2275
|
result,startdt,enddt=check_period(fromdate,todate)
|
2242
2276
|
if not result:
|
2243
2277
|
print(" #Error(stock_split): invalid period",fromdate,todate)
|
@@ -2290,7 +2324,8 @@ def stock_split(ticker,fromdate,todate):
|
|
2290
2324
|
from datetime import datetime
|
2291
2325
|
weekdayfmt=lambda x : x.isoweekday()
|
2292
2326
|
divdf['Weekdayiso']= divdf['Index Date'].apply(weekdayfmt)
|
2293
|
-
wdlist=['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
|
2327
|
+
#wdlist=['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
|
2328
|
+
wdlist=['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
|
2294
2329
|
wdfmt=lambda x : wdlist[x-1]
|
2295
2330
|
divdf['Weekday']= divdf['Weekdayiso'].apply(wdfmt)
|
2296
2331
|
|
@@ -2305,6 +2340,8 @@ def stock_split(ticker,fromdate,todate):
|
|
2305
2340
|
divprt=divdf[['Seq','Split Date','Weekday','Splits']]
|
2306
2341
|
|
2307
2342
|
lang=check_language()
|
2343
|
+
tname=ticker_name(ticker,'stock')
|
2344
|
+
"""
|
2308
2345
|
if lang == 'English':
|
2309
2346
|
print('\n======== '+texttranslate("股票分拆历史")+' ========')
|
2310
2347
|
print(texttranslate("股票:"),ticker,'\b,',ticker_name(ticker))
|
@@ -2325,6 +2362,49 @@ def stock_split(ticker,fromdate,todate):
|
|
2325
2362
|
import datetime
|
2326
2363
|
today = datetime.date.today()
|
2327
2364
|
print('\n*** '+sourcetxt,today)
|
2365
|
+
"""
|
2366
|
+
fromdatey2md=startdt.strftime('%y/%m/%d')
|
2367
|
+
todatey2md=enddt.strftime('%y/%m/%d')
|
2368
|
+
|
2369
|
+
if lang == 'English':
|
2370
|
+
titletxt=texttranslate("股票分拆历史")+': '+tname
|
2371
|
+
periodtxt=texttranslate("历史期间:")+' '+fromdatey2md+"-"+todatey2md
|
2372
|
+
sourcetxt=texttranslate("数据来源: 雅虎财经,")
|
2373
|
+
|
2374
|
+
#修改列命为英文
|
2375
|
+
divprt.columns = [texttranslate('序号'),texttranslate('日期'),texttranslate('星期'),texttranslate('股息')]
|
2376
|
+
else:
|
2377
|
+
titletxt="股票分拆历史:"+tname
|
2378
|
+
periodtxt="期间: "+fromdatey2md+"-"+todatey2md
|
2379
|
+
sourcetxt="数据来源: 雅虎,"
|
2380
|
+
|
2381
|
+
#修改列命为中文
|
2382
|
+
divprt.columns = ['序号','日期','星期','股息']
|
2383
|
+
"""
|
2384
|
+
print(divprt.to_string(index=False))
|
2385
|
+
"""
|
2386
|
+
print(' ') #空一行
|
2387
|
+
|
2388
|
+
disph=divprt.style.hide() #不显示索引列
|
2389
|
+
dispp=disph.format(precision=4) #设置带有小数点的列精度调整为小数点后2位
|
2390
|
+
#设置标题/列名
|
2391
|
+
dispt=dispp.set_caption(titletxt).set_table_styles(
|
2392
|
+
[{'selector':'caption', #设置标题
|
2393
|
+
'props':[('color','black'),('font-size','16px'),('font-weight','bold')]}, \
|
2394
|
+
{'selector':'th.col_heading', #设置列名
|
2395
|
+
'props':[('color','black'),('text-align','center'),('margin','auto')]}])
|
2396
|
+
#设置列数值对齐
|
2397
|
+
dispf=dispt.set_properties(**{'text-align':'center'})
|
2398
|
+
#设置前景背景颜色
|
2399
|
+
dispf2=dispf.set_properties(**{'background-color':facecolor,'color':fontcolor})
|
2400
|
+
|
2401
|
+
from IPython.display import display
|
2402
|
+
display(dispf2)
|
2403
|
+
|
2404
|
+
print(periodtxt)
|
2405
|
+
import datetime; todaydt=datetime.date.today(); todayy2md=todaydt.strftime('%y/%m/%d')
|
2406
|
+
#print('\n*** '+sourcetxt,today)
|
2407
|
+
print(sourcetxt,todayy2md)
|
2328
2408
|
|
2329
2409
|
return divdf
|
2330
2410
|
|
siat/stock_china.py
CHANGED
@@ -1103,7 +1103,7 @@ def stock_profile_china(ticker,category='profile', \
|
|
1103
1103
|
prettytab=False, \
|
1104
1104
|
tabborder=False, \
|
1105
1105
|
loc1='upper left',loc2='upper right', \
|
1106
|
-
):
|
1106
|
+
facecolor='papayawhip'):
|
1107
1107
|
"""
|
1108
1108
|
功能:介绍中国A股的主要信息,包括公司基本信息、主营信息、股东信息、财务信息、分红历史和市场估值等。
|
1109
1109
|
ticker:A股股票代码
|