siat 3.1.23__py3-none-any.whl → 3.2.1__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/capm_beta2.py +41 -19
- siat/markowitz2-20240620.py +2614 -0
- siat/markowitz2.py +52 -4
- siat/risk_adjusted_return2.py +45 -6
- siat/sector_china.py +17 -9
- siat/security_price2.py +12 -1
- siat/security_prices.py +38 -17
- siat/security_trend2-20240620.py +493 -0
- siat/security_trend2.py +17 -11
- siat/stock.py +76 -22
- siat/stock_technical-20240620.py +2736 -0
- siat/stock_technical.py +207 -52
- siat/valuation_china.py +7 -5
- {siat-3.1.23.dist-info → siat-3.2.1.dist-info}/METADATA +1 -1
- {siat-3.1.23.dist-info → siat-3.2.1.dist-info}/RECORD +17 -14
- {siat-3.1.23.dist-info → siat-3.2.1.dist-info}/WHEEL +0 -0
- {siat-3.1.23.dist-info → siat-3.2.1.dist-info}/top_level.txt +0 -0
siat/stock.py
CHANGED
@@ -605,7 +605,8 @@ if __name__ =="__main__":
|
|
605
605
|
|
606
606
|
df=security_indicator(ticker,indicator,fromdate,todate,ticker_type=ticker_type)
|
607
607
|
|
608
|
-
def security_indicator(ticker,indicator,
|
608
|
+
def security_indicator(ticker,indicator, \
|
609
|
+
fromdate,todate,adjust='', \
|
609
610
|
zeroline=False, \
|
610
611
|
average_value=False, \
|
611
612
|
datatag=False,power=0,graph=True,source='auto', \
|
@@ -614,12 +615,24 @@ def security_indicator(ticker,indicator,fromdate,todate, \
|
|
614
615
|
"""
|
615
616
|
功能:单只证券的全部指标
|
616
617
|
"""
|
618
|
+
#判断复权价
|
619
|
+
adjust_list=['','qfq','hfq']
|
620
|
+
if adjust not in adjust_list:
|
621
|
+
print(" #Warning(security_indicator): invalid adjust",adjust)
|
622
|
+
print(" Supported adjust:",adjust_list)
|
623
|
+
adjust='qfq'
|
624
|
+
|
625
|
+
if ('Adj' in indicator) and (adjust == ''):
|
626
|
+
adjust='qfq'
|
627
|
+
|
617
628
|
fromdate1=date_adjust(fromdate,adjust=-365*3)
|
618
629
|
|
619
630
|
from siat.security_price2 import get_price_1ticker_mixed
|
620
631
|
#pricedf=get_prices_all(ticker,fromdate1,todate,source=source,ticker_type=ticker_type)
|
621
|
-
pricedf,found=get_price_1ticker_mixed(ticker=ticker,
|
622
|
-
|
632
|
+
pricedf,found=get_price_1ticker_mixed(ticker=ticker, \
|
633
|
+
fromdate=fromdate1,todate=todate, \
|
634
|
+
adjust=adjust, \
|
635
|
+
source=source,ticker_type=ticker_type)
|
623
636
|
if pricedf is None:
|
624
637
|
print(" #Error(security_indicator): security info not found for",ticker)
|
625
638
|
return None
|
@@ -631,15 +644,18 @@ def security_indicator(ticker,indicator,fromdate,todate, \
|
|
631
644
|
if len(pricedf)==1:
|
632
645
|
fromdate1=date_adjust(fromdate,adjust=-365*2)
|
633
646
|
pricedf,found=get_price_1ticker_mixed(ticker=ticker,fromdate=fromdate1, \
|
634
|
-
|
647
|
+
adjust=adjust, \
|
648
|
+
todate=todate,source=source,ticker_type=ticker_type)
|
635
649
|
if len(pricedf)==1:
|
636
650
|
fromdate1=date_adjust(fromdate,adjust=-365*1)
|
637
651
|
pricedf,found=get_price_1ticker_mixed(ticker=ticker,fromdate=fromdate1, \
|
638
|
-
|
652
|
+
adjust=adjust, \
|
653
|
+
todate=todate,source=source,ticker_type=ticker_type)
|
639
654
|
if len(pricedf)==1:
|
640
655
|
fromdate1=fromdate
|
641
656
|
pricedf,found=get_price_1ticker_mixed(ticker=ticker,fromdate=fromdate1, \
|
642
|
-
|
657
|
+
adjust=adjust, \
|
658
|
+
todate=todate,source=source,ticker_type=ticker_type)
|
643
659
|
|
644
660
|
# 去掉时区信息,避免日期时区冲突问题
|
645
661
|
pricedf=df_index_timezone_remove(pricedf)
|
@@ -698,10 +714,12 @@ def security_indicator(ticker,indicator,fromdate,todate, \
|
|
698
714
|
return erdf3
|
699
715
|
|
700
716
|
|
701
|
-
def stock_ret(ticker,fromdate,todate,
|
717
|
+
def stock_ret(ticker,fromdate,todate, \
|
718
|
+
adjust='', \
|
719
|
+
rtype="Daily Ret%", \
|
702
720
|
datatag=False,power=0,graph=True,source='auto',ticker_type='auto'):
|
703
721
|
"""
|
704
|
-
|
722
|
+
功能:绘制证券收益率折线图,单个证券,单个指标。
|
705
723
|
输入:证券代码ticker;开始日期fromdate,结束日期todate;收益率类型type;
|
706
724
|
是否标注数据标签datatag,默认否;多项式趋势线的阶数,若为0则不绘制趋势线。
|
707
725
|
输出:绘制证券价格折线图
|
@@ -710,9 +728,15 @@ def stock_ret(ticker,fromdate,todate,rtype="Daily Ret%", \
|
|
710
728
|
#调整抓取样本的开始日期366*2=732,以便保证有足够的样本供后续计算
|
711
729
|
fromdate1=date_adjust(fromdate, -732)
|
712
730
|
|
731
|
+
#判断复权价
|
732
|
+
adjust_list=['','qfq','hfq']
|
733
|
+
if adjust not in adjust_list:
|
734
|
+
print(" #Warning(stock_ret): invalid adjust",adjust)
|
735
|
+
print(" Supported adjust:",adjust_list)
|
736
|
+
adjust='qfq'
|
737
|
+
if 'Adj' in rtype: adjust='qfq'
|
738
|
+
|
713
739
|
#抓取证券价格
|
714
|
-
adj=False; adjust=''
|
715
|
-
if 'Adj' in rtype: adj=True; adjust='qfq'
|
716
740
|
from siat.security_price2 import get_price_1ticker_mixed
|
717
741
|
#pricedf=get_price(ticker,fromdate1,todate,adj=adj,source=source)
|
718
742
|
pricedf,found=get_price_1ticker_mixed(ticker=ticker,fromdate=fromdate1, \
|
@@ -787,7 +811,9 @@ if __name__ =="__main__":
|
|
787
811
|
loc='best'
|
788
812
|
annotate=False
|
789
813
|
|
790
|
-
def security_mindicators(ticker,measures,
|
814
|
+
def security_mindicators(ticker,measures,
|
815
|
+
fromdate,todate, \
|
816
|
+
adjust='', \
|
791
817
|
graph=True,smooth=True,loc='best',facecolor='whitesmoke', \
|
792
818
|
date_range=False,date_freq=False, \
|
793
819
|
annotate=False,annotate_value=False, \
|
@@ -814,12 +840,27 @@ def security_mindicators(ticker,measures,fromdate,todate, \
|
|
814
840
|
|
815
841
|
if isinstance(measures,str):
|
816
842
|
measures=[measures]
|
817
|
-
|
843
|
+
|
844
|
+
#判断复权价
|
845
|
+
adjust_list=['','qfq','hfq']
|
846
|
+
if adjust not in adjust_list:
|
847
|
+
print(" #Warning(security_mindicators): invalid adjust",adjust)
|
848
|
+
print(" Supported adjust:",adjust_list)
|
849
|
+
adjust='qfq'
|
850
|
+
|
851
|
+
if adjust =='':
|
852
|
+
for m in measures:
|
853
|
+
if 'Adj' in m:
|
854
|
+
adjust='qfq'
|
855
|
+
break
|
856
|
+
|
857
|
+
#抓取股价
|
818
858
|
try:
|
819
859
|
from siat.security_price2 import get_price_1ticker_mixed
|
820
860
|
#pricedf=get_price(ticker,fromdate1,todate,source=source)
|
821
|
-
pricedf,found=get_price_1ticker_mixed(ticker=ticker,fromdate=fromdate1, \
|
822
|
-
|
861
|
+
pricedf,found=get_price_1ticker_mixed(ticker=ticker,fromdate=fromdate1,todate=todate, \
|
862
|
+
adjust=adjust, \
|
863
|
+
source=source,ticker_type=ticker_type)
|
823
864
|
except:
|
824
865
|
print(" #Error(security_mindicators): price info not found for",ticker)
|
825
866
|
return None
|
@@ -1356,7 +1397,9 @@ if __name__ =="__main__":
|
|
1356
1397
|
df2=stock_ret(ticker2,fromdate,todate,graph=False)
|
1357
1398
|
comp_2securities_1measure(df1,df2,measure)
|
1358
1399
|
#==============================================================================
|
1359
|
-
def compare_security(tickers,measures,fromdate,todate,
|
1400
|
+
def compare_security(tickers,measures,fromdate,todate, \
|
1401
|
+
adjust='', \
|
1402
|
+
twinx=False, \
|
1360
1403
|
loc1='best',loc2='lower left',graph=True,source='auto', \
|
1361
1404
|
ticker_type='auto',facecolor='whitesmoke'):
|
1362
1405
|
"""
|
@@ -1366,13 +1409,17 @@ def compare_security(tickers,measures,fromdate,todate,twinx=False, \
|
|
1366
1409
|
from siat.security_prices import upper_ticker
|
1367
1410
|
tickers=upper_ticker(tickers)
|
1368
1411
|
result=compare_stock(tickers=tickers,measures=measures, \
|
1369
|
-
fromdate=fromdate,todate=todate,
|
1412
|
+
fromdate=fromdate,todate=todate, \
|
1413
|
+
adjust=adjust, \
|
1414
|
+
twinx=twinx, \
|
1370
1415
|
loc1=loc1,loc2=loc2,graph=graph,source=source, \
|
1371
1416
|
ticker_type=ticker_type,facecolor=facecolor)
|
1372
1417
|
return result
|
1373
1418
|
|
1374
1419
|
#==============================================================================
|
1375
|
-
def compare_stock(tickers,measures,fromdate,todate,
|
1420
|
+
def compare_stock(tickers,measures,fromdate,todate, \
|
1421
|
+
adjust='', \
|
1422
|
+
twinx=False, \
|
1376
1423
|
loc1='best',loc2='lower left',graph=True,source='auto', \
|
1377
1424
|
ticker_type='auto',facecolor='whitesmoke'):
|
1378
1425
|
"""
|
@@ -1425,10 +1472,13 @@ def compare_stock(tickers,measures,fromdate,todate,twinx=False, \
|
|
1425
1472
|
if measure_num >= 1: measure1 = measures[0]
|
1426
1473
|
if measure_num >= 2: measure2 = measures[1]
|
1427
1474
|
|
1428
|
-
|
1475
|
+
#单一证券代码+两个测度指标
|
1429
1476
|
if (security_num == 1) and (measure_num >= 2):
|
1477
|
+
if (('Adj' in measure1) or ('Adj' in measure2)) and (adjust ==''):
|
1478
|
+
adjust='qfq'
|
1479
|
+
|
1430
1480
|
#证券ticker1:抓取行情,并计算其各种期间的收益率
|
1431
|
-
df1a=stock_ret(ticker1,fromdate,todate,graph=False,source=source,ticker_type=ticker_type)
|
1481
|
+
df1a=stock_ret(ticker1,fromdate,todate,adjust=adjust,graph=False,source=source,ticker_type=ticker_type)
|
1432
1482
|
if df1a is None: return None,None
|
1433
1483
|
if DEBUG: print("compare|df1a first date:",df1a.index[0])
|
1434
1484
|
#加入价格波动指标
|
@@ -1460,6 +1510,9 @@ def compare_stock(tickers,measures,fromdate,todate,twinx=False, \
|
|
1460
1510
|
|
1461
1511
|
elif (security_num >= 2) and (measure_num >= 1):
|
1462
1512
|
#双证券+单个测度指标
|
1513
|
+
if ('Adj' in measure1) and (adjust ==''):
|
1514
|
+
adjust='qfq'
|
1515
|
+
|
1463
1516
|
#解析ticker_type
|
1464
1517
|
if isinstance(ticker_type,str):
|
1465
1518
|
ticker_type1=ticker_type2=ticker_type
|
@@ -1471,7 +1524,7 @@ def compare_stock(tickers,measures,fromdate,todate,twinx=False, \
|
|
1471
1524
|
ticker_type_list=[ticker_type1,ticker_type2]
|
1472
1525
|
|
1473
1526
|
#证券ticker1:抓取行情,并计算其各种期间的收益率
|
1474
|
-
df1a=stock_ret(ticker1,fromdate,todate,graph=False,source=source,ticker_type=ticker_type1)
|
1527
|
+
df1a=stock_ret(ticker1,fromdate,todate,adjust=adjust,graph=False,source=source,ticker_type=ticker_type1)
|
1475
1528
|
if df1a is None: return None,None
|
1476
1529
|
#加入价格波动指标
|
1477
1530
|
df1b=price_volatility2(df1a,ticker1,fromdate,todate,graph=False,ticker_type=ticker_type1)
|
@@ -1483,7 +1536,7 @@ def compare_stock(tickers,measures,fromdate,todate,twinx=False, \
|
|
1483
1536
|
pltdf1=df1d[df1d.index >= fromdate]
|
1484
1537
|
|
1485
1538
|
#证券ticker2:
|
1486
|
-
df2a=stock_ret(ticker2,fromdate,todate,graph=False,source=source,ticker_type=ticker_type2)
|
1539
|
+
df2a=stock_ret(ticker2,fromdate,todate,adjust=adjust,graph=False,source=source,ticker_type=ticker_type2)
|
1487
1540
|
if df2a is None: return None,None
|
1488
1541
|
df2b=price_volatility2(df2a,ticker2,fromdate,todate,graph=False,ticker_type=ticker_type2)
|
1489
1542
|
df2c=ret_volatility2(df2b,ticker2,fromdate,todate,graph=False,ticker_type=ticker_type2)
|
@@ -1555,6 +1608,7 @@ if __name__ =="__main__":
|
|
1555
1608
|
|
1556
1609
|
|
1557
1610
|
def compare_msecurity(tickers,measure,start,end, \
|
1611
|
+
adjust='', \
|
1558
1612
|
axhline_value=0,axhline_label='', \
|
1559
1613
|
preprocess='none',linewidth=1.5, \
|
1560
1614
|
scaling_option='start', \
|
@@ -1628,7 +1682,7 @@ def compare_msecurity(tickers,measure,start,end, \
|
|
1628
1682
|
tt=ticker_type_list[pos]
|
1629
1683
|
|
1630
1684
|
with HiddenPrints():
|
1631
|
-
df_tmp=security_indicator(t,measure,start,end,graph=False,source=source,ticker_type=tt)
|
1685
|
+
df_tmp=security_indicator(t,measure,start,end,adjust=adjust,graph=False,source=source,ticker_type=tt)
|
1632
1686
|
if df_tmp is None:
|
1633
1687
|
print(" #Warning(compare_msecurity): security info not found for",t)
|
1634
1688
|
continue
|