siat 3.0.10__py3-none-any.whl → 3.0.20__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 +51 -22
- siat/common.py +136 -9
- siat/financials_china.py +83 -47
- siat/financials_china2.py +272 -119
- siat/grafix.py +130 -62
- siat/markowitz2.py +27 -3
- siat/risk_adjusted_return2.py +136 -62
- siat/security_trend2.py +39 -25
- siat/stock.py +127 -47
- siat/stock_china.py +160 -53
- siat/stock_technical.py +1 -1
- siat/valuation.py +34 -7
- {siat-3.0.10.dist-info → siat-3.0.20.dist-info}/METADATA +1 -1
- {siat-3.0.10.dist-info → siat-3.0.20.dist-info}/RECORD +16 -16
- {siat-3.0.10.dist-info → siat-3.0.20.dist-info}/WHEEL +0 -0
- {siat-3.0.10.dist-info → siat-3.0.20.dist-info}/top_level.txt +0 -0
siat/stock_china.py
CHANGED
@@ -1100,10 +1100,13 @@ def stock_profile_china(ticker,category='profile', \
|
|
1100
1100
|
business_period='recent', \
|
1101
1101
|
financial_quarters=8, \
|
1102
1102
|
valuation_start='2020-1-1', \
|
1103
|
+
|
1104
|
+
#参数prettytab和tabborder弃用,保留只为了兼容性
|
1103
1105
|
prettytab=False, \
|
1104
1106
|
tabborder=False, \
|
1107
|
+
|
1105
1108
|
loc1='upper left',loc2='upper right', \
|
1106
|
-
):
|
1109
|
+
facecolor='papayawhip'):
|
1107
1110
|
"""
|
1108
1111
|
功能:介绍中国A股的主要信息,包括公司基本信息、主营信息、股东信息、财务信息、分红历史和市场估值等。
|
1109
1112
|
ticker:A股股票代码
|
@@ -1122,6 +1125,8 @@ def stock_profile_china(ticker,category='profile', \
|
|
1122
1125
|
返回值:无。
|
1123
1126
|
建议运行环境:Anaconda Jupyter Notebook,其他环境未测试。
|
1124
1127
|
"""
|
1128
|
+
DEBUG=False
|
1129
|
+
|
1125
1130
|
#检查是否A股
|
1126
1131
|
_,_,suffix=split_prefix_suffix(ticker)
|
1127
1132
|
if not (suffix.upper() in ['SS','SZ','BJ']):
|
@@ -1148,15 +1153,15 @@ def stock_profile_china(ticker,category='profile', \
|
|
1148
1153
|
baiwan=1000000.0
|
1149
1154
|
wan=10000.0
|
1150
1155
|
|
1151
|
-
|
1156
|
+
import akshare as ak
|
1152
1157
|
# 个股基本信息======================================================================================
|
1153
|
-
if category
|
1158
|
+
if any(s in category for s in ['profile','basic']): #判断category中是否包含任意子串
|
1154
1159
|
|
1155
1160
|
# 个股基本信息查询1=============================================================================
|
1156
1161
|
try:
|
1157
1162
|
df6=ak.stock_profile_cninfo(symbol=ticker1)
|
1158
1163
|
except:
|
1159
|
-
print(" #Warning(stock_profile_china): profile info not found for",
|
1164
|
+
print(" #Warning(stock_profile_china): profile info not found or inaccessible for",ticker1)
|
1160
1165
|
return
|
1161
1166
|
|
1162
1167
|
# 整理信息
|
@@ -1228,7 +1233,8 @@ def stock_profile_china(ticker,category='profile', \
|
|
1228
1233
|
dftmp15=dftmp14.T
|
1229
1234
|
dftmp15.reset_index(inplace=True)
|
1230
1235
|
|
1231
|
-
titletxt=ticker_name(ticker)
|
1236
|
+
titletxt=ticker_name(ticker)
|
1237
|
+
"""
|
1232
1238
|
if prettytab:
|
1233
1239
|
pandas2prettytable(dftmp15,titletxt,firstColSpecial=False,leftColAlign='l',otherColAlign='l',tabborder=tabborder)
|
1234
1240
|
print(' ','数据来源:巨潮资讯,',str(today))
|
@@ -1236,16 +1242,21 @@ def stock_profile_china(ticker,category='profile', \
|
|
1236
1242
|
print('\n*** '+titletxt+'\n')
|
1237
1243
|
print(dftmp15.to_markdown(tablefmt='Simple',index=False,colalign=['left']))
|
1238
1244
|
print('\n数据来源:巨潮资讯,',str(today))
|
1239
|
-
|
1240
|
-
|
1245
|
+
"""
|
1246
|
+
titletxt1=titletxt+":基本信息"
|
1247
|
+
footnote='数据来源:巨潮资讯,'+str(today)
|
1248
|
+
df_display_CSS(df=dftmp15,titletxt=titletxt1,footnote=footnote, \
|
1249
|
+
facecolor=facecolor,decimals=2,last_col_align='left')
|
1250
|
+
|
1251
|
+
print("*****",titletxt+":业务范围")
|
1241
1252
|
longtext=df6.iloc[0]["主营业务"]
|
1242
1253
|
print_sentence(longtext,mid_symbol=[';','。'])
|
1243
1254
|
|
1244
|
-
print("\n
|
1255
|
+
print("\n*****",titletxt+":经营范围")
|
1245
1256
|
longtext=df6.iloc[0]["经营范围"]
|
1246
1257
|
print_sentence(longtext,mid_symbol=[';','。'])
|
1247
1258
|
|
1248
|
-
print("\n
|
1259
|
+
print("\n*****",titletxt+":机构简介")
|
1249
1260
|
longtext=df6.iloc[0]["机构简介"]
|
1250
1261
|
print_sentence(longtext,mid_symbol=[';','。'])
|
1251
1262
|
|
@@ -1296,7 +1307,8 @@ def stock_profile_china(ticker,category='profile', \
|
|
1296
1307
|
cols2=['分类方向','分类','营业收入-同比增长','营业成本-同比增长','毛利率','毛利率-同比增长']
|
1297
1308
|
|
1298
1309
|
dftmp1=dftmp[cols1]
|
1299
|
-
titletxt1=ticker_name(ticker)+':主营业务构成,'+period
|
1310
|
+
titletxt1=ticker_name(ticker)+':主营业务构成,'+period
|
1311
|
+
"""
|
1300
1312
|
if prettytab:
|
1301
1313
|
pandas2prettytable(dftmp1,titletxt1,firstColSpecial=True,leftColAlign='l',otherColAlign='c',tabborder=tabborder)
|
1302
1314
|
print(' ','数据来源:益盟-F10,',str(today))
|
@@ -1304,9 +1316,15 @@ def stock_profile_china(ticker,category='profile', \
|
|
1304
1316
|
print('\n*** '+titletxt1+'\n')
|
1305
1317
|
print(dftmp1.to_markdown(tablefmt='Simple',index=False,colalign=['left','left','right','right','right','right','right']))
|
1306
1318
|
print('\n数据来源:益盟-F10,',str(today))
|
1319
|
+
"""
|
1320
|
+
footnote='数据来源:益盟-F10,'+str(today)
|
1321
|
+
df_display_CSS(df=dftmp1,titletxt=titletxt1,footnote=footnote, \
|
1322
|
+
first_col_align='left',second_col_align='left', \
|
1323
|
+
facecolor=facecolor,decimals=2)
|
1307
1324
|
|
1308
1325
|
dftmp2=dftmp[cols2]
|
1309
|
-
titletxt2=ticker_name(ticker)+':主营业务增长,'+period
|
1326
|
+
titletxt2=ticker_name(ticker)+':主营业务增长,'+period
|
1327
|
+
"""
|
1310
1328
|
if prettytab:
|
1311
1329
|
pandas2prettytable(dftmp2,titletxt2,firstColSpecial=True,leftColAlign='l',otherColAlign='c',tabborder=tabborder)
|
1312
1330
|
print(' ','数据来源:益盟-F10,',str(today))
|
@@ -1314,7 +1332,11 @@ def stock_profile_china(ticker,category='profile', \
|
|
1314
1332
|
print('\n*** '+titletxt2+'\n')
|
1315
1333
|
print(dftmp2.to_markdown(tablefmt='Simple',index=False,colalign=['left','left','right','right','right','right']))
|
1316
1334
|
print('\n数据来源:益盟-F10,',str(today))
|
1317
|
-
|
1335
|
+
"""
|
1336
|
+
df_display_CSS(df=dftmp2,titletxt=titletxt2,footnote=footnote, \
|
1337
|
+
first_col_align='left',second_col_align='left', \
|
1338
|
+
facecolor=facecolor,decimals=2)
|
1339
|
+
|
1318
1340
|
# 历史分红信息查询=============================================================================
|
1319
1341
|
"""
|
1320
1342
|
if category == 'dividend':
|
@@ -1357,7 +1379,8 @@ def stock_profile_china(ticker,category='profile', \
|
|
1357
1379
|
print(dftmp3.to_markdown(tablefmt='Simple',index=False,colalign=['left','center','center','right','center','center','center','left']))
|
1358
1380
|
print('\n数据来源:巨潮资讯,',str(today))
|
1359
1381
|
"""
|
1360
|
-
if category
|
1382
|
+
#if category in ['dividend','split']:
|
1383
|
+
if any(s in category for s in ['dividend','split']):
|
1361
1384
|
# 分红
|
1362
1385
|
titletxt=ticker_name(ticker)+':分红历史'
|
1363
1386
|
try:
|
@@ -1384,6 +1407,7 @@ def stock_profile_china(ticker,category='profile', \
|
|
1384
1407
|
dftmp3=dftmp[newcols]
|
1385
1408
|
|
1386
1409
|
titletxt=ticker_name(ticker)+':分红历史'
|
1410
|
+
"""
|
1387
1411
|
if prettytab:
|
1388
1412
|
pandas2prettytable(dftmp3,titletxt,firstColSpecial=False,leftColAlign='l',otherColAlign='c',tabborder=tabborder)
|
1389
1413
|
print('【注】送股/转增:股数/10股,派息:元(税前)/10股,数据来源:新浪财经,',str(today))
|
@@ -1392,6 +1416,10 @@ def stock_profile_china(ticker,category='profile', \
|
|
1392
1416
|
alignlist=['center']+['right']*(len(list(dftmp3))-1)
|
1393
1417
|
print(dftmp3.to_markdown(tablefmt='Simple',index=False,colalign=alignlist))
|
1394
1418
|
print('【注】送股/转增:股数/10股,派息:元(税前)/10股,数据来源:新浪财经,',str(today))
|
1419
|
+
"""
|
1420
|
+
footnote='【注】送股/转增:股数/10股,派息:元(税前)/10股,数据来源:新浪财经,'+str(today)
|
1421
|
+
df_display_CSS(df=dftmp3,titletxt=titletxt,footnote=footnote, \
|
1422
|
+
facecolor=facecolor,decimals=2)
|
1395
1423
|
|
1396
1424
|
# 配股
|
1397
1425
|
titletxt=ticker_name(ticker)+':配股历史'
|
@@ -1400,13 +1428,13 @@ def stock_profile_china(ticker,category='profile', \
|
|
1400
1428
|
except:
|
1401
1429
|
print('')
|
1402
1430
|
print(titletxt)
|
1403
|
-
print(" #Warning(stock_profile_china):
|
1431
|
+
print(" #Warning(stock_profile_china): allotment info not found for stock",ticker)
|
1404
1432
|
return
|
1405
1433
|
|
1406
1434
|
if len(df3p)==0:
|
1407
1435
|
print('')
|
1408
1436
|
print(titletxt)
|
1409
|
-
print("
|
1437
|
+
print(" #Warning(stock_profile_china): no allotment info found for stock",ticker)
|
1410
1438
|
return
|
1411
1439
|
|
1412
1440
|
# 整理信息
|
@@ -1415,7 +1443,7 @@ def stock_profile_china(ticker,category='profile', \
|
|
1415
1443
|
|
1416
1444
|
newcols=['公告日期','配股方案','配股价格','股权登记日','除权日','缴款起始日','缴款终止日','配股上市日']
|
1417
1445
|
dftmp3=dftmp[newcols]
|
1418
|
-
|
1446
|
+
"""
|
1419
1447
|
if prettytab:
|
1420
1448
|
pandas2prettytable(dftmp3,titletxt,firstColSpecial=False,leftColAlign='l',otherColAlign='c',tabborder=tabborder)
|
1421
1449
|
print('【注】配股方案:每10股的配股数,配股价格为元。数据来源:新浪财经,',str(today))
|
@@ -1424,10 +1452,15 @@ def stock_profile_china(ticker,category='profile', \
|
|
1424
1452
|
alignlist=['center']+['right']*(len(list(dftmp3))-1)
|
1425
1453
|
print(dftmp3.to_markdown(tablefmt='Simple',index=False,colalign=alignlist))
|
1426
1454
|
print('【注】配股方案:每10股的配股数,配股价格为元。数据来源:新浪财经,',str(today))
|
1427
|
-
|
1455
|
+
"""
|
1456
|
+
footnote='【注】配股方案:每10股的配股数,配股价格为元。数据来源:新浪财经,'+str(today)
|
1457
|
+
df_display_CSS(df=dftmp3,titletxt=titletxt,footnote=footnote, \
|
1458
|
+
facecolor=facecolor,decimals=2)
|
1459
|
+
|
1428
1460
|
|
1429
1461
|
# 主要股东信息查询=============================================================================
|
1430
|
-
if category
|
1462
|
+
#if category in ['shareholder','investor']:
|
1463
|
+
if any(s in category for s in ['shareholder','investor']):
|
1431
1464
|
try:
|
1432
1465
|
df4=ak.stock_main_stock_holder(stock=ticker1)
|
1433
1466
|
except:
|
@@ -1470,7 +1503,9 @@ def stock_profile_china(ticker,category='profile', \
|
|
1470
1503
|
return
|
1471
1504
|
|
1472
1505
|
#df4b=df4a[df4a['持股比例'] != 0]
|
1473
|
-
df4a['持股比例'].replace(0,'unknown',inplace=True)
|
1506
|
+
#df4a['持股比例'].replace(0,'unknown',inplace=True)
|
1507
|
+
#df4a['持股比例'].replace(0,'?',inplace=True)
|
1508
|
+
df4a['持股比例'].replace(0,'--',inplace=True)
|
1474
1509
|
dftmp=df4a.head(10).copy(deep=True)
|
1475
1510
|
|
1476
1511
|
enddate=str(dftmp.head(1)['截至日期'][0])
|
@@ -1498,7 +1533,7 @@ def stock_profile_china(ticker,category='profile', \
|
|
1498
1533
|
#newcols=['编号','股东名称','股本性质','持股比例(%)','持股数量(百万股)']
|
1499
1534
|
newcols=['编号','股东名称','股本性质','持股比例(%)']
|
1500
1535
|
dftmp1=dftmp[newcols]
|
1501
|
-
|
1536
|
+
"""
|
1502
1537
|
if prettytab:
|
1503
1538
|
pandas2prettytable(dftmp1,titletxt,firstColSpecial=False,leftColAlign='c',otherColAlign='c',tabborder=tabborder)
|
1504
1539
|
print(' ','数据来源:新浪财经,',str(today))
|
@@ -1507,10 +1542,16 @@ def stock_profile_china(ticker,category='profile', \
|
|
1507
1542
|
#print(dftmp1.to_markdown(tablefmt='Simple',index=False,colalign=['center','left','left','right','right']))
|
1508
1543
|
print(dftmp1.to_markdown(tablefmt='Simple',index=False,colalign=['center','left','left','right']))
|
1509
1544
|
print('\n数据来源:新浪财经,',str(today))
|
1510
|
-
|
1545
|
+
"""
|
1546
|
+
footnote='数据来源:新浪财经,'+str(today)
|
1547
|
+
df_display_CSS(df=dftmp1,titletxt=titletxt,footnote=footnote, \
|
1548
|
+
first_col_align='center',second_col_align='left', \
|
1549
|
+
facecolor=facecolor,decimals=2)
|
1550
|
+
|
1511
1551
|
|
1512
1552
|
# 主要市场指标查询=============================================================================
|
1513
|
-
if category == 'valuation':
|
1553
|
+
#if category == 'valuation':
|
1554
|
+
if any(s in category for s in ['valuation','market']):
|
1514
1555
|
try:
|
1515
1556
|
#df5=ak.stock_a_lg_indicator(symbol=ticker1)
|
1516
1557
|
df5=ak.stock_a_indicator_lg(symbol=ticker1)
|
@@ -1544,7 +1585,8 @@ def stock_profile_china(ticker,category='profile', \
|
|
1544
1585
|
footnote3="数据来源:乐咕乐股,"+str(today)
|
1545
1586
|
|
1546
1587
|
# 计算市盈率的均值,中位数、最大最小值
|
1547
|
-
va='pe'; va_name="市盈率"
|
1588
|
+
#va='pe'; va_name="市盈率"
|
1589
|
+
va='pe_ttm'; va_name="市盈率TTM"
|
1548
1590
|
va_mean=round(dftmp2[va].mean(),1)
|
1549
1591
|
va_median=round(dftmp2[va].median(),1)
|
1550
1592
|
va_max=round(dftmp2[va].max(),1)
|
@@ -1554,12 +1596,23 @@ def stock_profile_china(ticker,category='profile', \
|
|
1554
1596
|
footnote=va_txt+";"+mv_txt+"\n"+footnote3
|
1555
1597
|
|
1556
1598
|
# 市盈率与总市值
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1599
|
+
if DEBUG:
|
1600
|
+
display(dftmp2)
|
1601
|
+
"""
|
1602
|
+
plot2_line2(df1=dftmp2,ticker1='',colname1=va,label1=va_name, \
|
1603
|
+
df2=dftmp2,ticker2='',colname2='total_mv(yi)',label2='总市值(亿元)', \
|
1604
|
+
ylabeltxt='',titletxt=titletxt,footnote=footnote, \
|
1605
|
+
date_range=True,date_freq='Q',date_fmt='%Y-%m',twinx=True, \
|
1606
|
+
resample_freq='D', \
|
1607
|
+
loc1=loc1,loc2=loc2, \
|
1608
|
+
color1='red',color2='blue',facecolor=facecolor)
|
1609
|
+
"""
|
1610
|
+
plot_line2(df1=dftmp2,ticker1='',colname1=va,label1=va_name, \
|
1611
|
+
df2=dftmp2,ticker2='',colname2='total_mv(yi)',label2='总市值(亿元)', \
|
1612
|
+
ylabeltxt='',titletxt=titletxt,footnote=footnote, \
|
1613
|
+
twinx=True, \
|
1614
|
+
resample_freq='D',loc1='best',loc2='best', \
|
1615
|
+
color1='red',color2='blue',facecolor='whitesmoke')
|
1563
1616
|
|
1564
1617
|
# 计算市净率的均值,中位数、最大最小值
|
1565
1618
|
va='pb'; va_name="市净率"
|
@@ -1571,16 +1624,24 @@ def stock_profile_china(ticker,category='profile', \
|
|
1571
1624
|
|
1572
1625
|
footnote=va_txt+";"+mv_txt+"\n"+footnote3
|
1573
1626
|
|
1574
|
-
#
|
1627
|
+
# 市净率与总市值
|
1628
|
+
"""
|
1575
1629
|
plot2_line2(dftmp2,'',va,va_name, \
|
1576
1630
|
dftmp2,'','total_mv(yi)','总市值(亿元)', \
|
1577
1631
|
'',titletxt,footnote, \
|
1578
1632
|
date_range=True,date_freq='Q',date_fmt='%Y-%m',twinx=True, \
|
1579
1633
|
resample_freq='D',loc1=loc1,loc2=loc2, \
|
1580
|
-
color1='red',color2='blue')
|
1581
|
-
|
1634
|
+
color1='red',color2='blue',facecolor=facecolor)
|
1635
|
+
"""
|
1636
|
+
plot_line2(df1=dftmp2,ticker1='',colname1=va,label1=va_name, \
|
1637
|
+
df2=dftmp2,ticker2='',colname2='total_mv(yi)',label2='总市值(亿元)', \
|
1638
|
+
ylabeltxt='',titletxt=titletxt,footnote=footnote, \
|
1639
|
+
twinx=True, \
|
1640
|
+
resample_freq='D',loc1='best',loc2='best', \
|
1641
|
+
color1='red',color2='blue',facecolor='whitesmoke')
|
1642
|
+
|
1582
1643
|
# 计算市销率的均值,中位数、最大最小值
|
1583
|
-
va='
|
1644
|
+
va='ps_ttm'; va_name="市销率TTM"
|
1584
1645
|
va_mean=round(dftmp2[va].mean(),1)
|
1585
1646
|
va_median=round(dftmp2[va].median(),1)
|
1586
1647
|
va_max=round(dftmp2[va].max(),1)
|
@@ -1589,16 +1650,25 @@ def stock_profile_china(ticker,category='profile', \
|
|
1589
1650
|
|
1590
1651
|
footnote=va_txt+";"+mv_txt+"\n"+footnote3
|
1591
1652
|
|
1592
|
-
#
|
1653
|
+
# 市销率与总市值
|
1654
|
+
"""
|
1593
1655
|
plot2_line2(dftmp2,'',va,va_name, \
|
1594
1656
|
dftmp2,'','total_mv(yi)','总市值(亿元)', \
|
1595
1657
|
'',titletxt,footnote, \
|
1596
1658
|
date_range=True,date_freq='Q',date_fmt='%Y-%m',twinx=True, \
|
1597
1659
|
resample_freq='D',loc1=loc1,loc2=loc2, \
|
1598
|
-
color1='red',color2='blue')
|
1660
|
+
color1='red',color2='blue',facecolor=facecolor)
|
1661
|
+
"""
|
1662
|
+
plot_line2(df1=dftmp2,ticker1='',colname1=va,label1=va_name, \
|
1663
|
+
df2=dftmp2,ticker2='',colname2='total_mv(yi)',label2='总市值(亿元)', \
|
1664
|
+
ylabeltxt='',titletxt=titletxt,footnote=footnote, \
|
1665
|
+
twinx=True, \
|
1666
|
+
resample_freq='D',loc1='best',loc2='best', \
|
1667
|
+
color1='red',color2='blue',facecolor='whitesmoke')
|
1599
1668
|
|
1600
1669
|
# 计算股息率的均值,中位数、最大最小值
|
1601
|
-
va='dv_ratio'; va_name="股息率"
|
1670
|
+
#va='dv_ratio'; va_name="股息率"
|
1671
|
+
va='dv_ttm'; va_name="股息率TTM"
|
1602
1672
|
va_mean=round(dftmp2[va].mean(),1)
|
1603
1673
|
va_median=round(dftmp2[va].median(),1)
|
1604
1674
|
va_max=round(dftmp2[va].max(),1)
|
@@ -1607,16 +1677,26 @@ def stock_profile_china(ticker,category='profile', \
|
|
1607
1677
|
|
1608
1678
|
footnote=va_txt+";"+mv_txt+"\n"+footnote3
|
1609
1679
|
|
1610
|
-
#
|
1680
|
+
# 股息率与总市值
|
1681
|
+
"""
|
1611
1682
|
plot2_line2(dftmp2,'',va,va_name+'%', \
|
1612
1683
|
dftmp2,'','total_mv(yi)','总市值(亿元)', \
|
1613
1684
|
'',titletxt,footnote, \
|
1614
1685
|
date_range=True,date_freq='Q',date_fmt='%Y-%m',twinx=True, \
|
1615
|
-
|
1616
|
-
color1='red',color2='blue')
|
1617
|
-
|
1686
|
+
loc1=loc1,loc2=loc2, \
|
1687
|
+
color1='red',color2='blue',facecolor=facecolor)
|
1688
|
+
"""
|
1689
|
+
plot_line2(df1=dftmp2,ticker1='',colname1=va,label1=va_name+'%', \
|
1690
|
+
df2=dftmp2,ticker2='',colname2='total_mv(yi)',label2='总市值(亿元)', \
|
1691
|
+
ylabeltxt='',titletxt=titletxt,footnote=footnote, \
|
1692
|
+
twinx=True, \
|
1693
|
+
resample_freq='D',loc1='best',loc2='best', \
|
1694
|
+
color1='red',color2='blue',facecolor='whitesmoke')
|
1695
|
+
|
1696
|
+
|
1618
1697
|
# 财务基本面指标查询=============================================================================
|
1619
|
-
if category == 'financial':
|
1698
|
+
#if category == 'financial':
|
1699
|
+
if any(s in category for s in ['financial','healthy']):
|
1620
1700
|
|
1621
1701
|
try:
|
1622
1702
|
df7=ak.stock_financial_analysis_indicator(symbol=ticker1)
|
@@ -1654,7 +1734,7 @@ def stock_profile_china(ticker,category='profile', \
|
|
1654
1734
|
dftmp1=dftmp.T
|
1655
1735
|
dftmp1.reset_index(inplace=True)
|
1656
1736
|
dftmp1.rename(columns={'index':'项目'},inplace=True)
|
1657
|
-
|
1737
|
+
"""
|
1658
1738
|
if prettytab:
|
1659
1739
|
pandas2prettytable(dftmp1,titletxt,firstColSpecial=False,leftColAlign='l',otherColAlign='r',tabborder=tabborder)
|
1660
1740
|
print(' ','数据来源:新浪财经,',str(today))
|
@@ -1663,7 +1743,12 @@ def stock_profile_china(ticker,category='profile', \
|
|
1663
1743
|
colalignList=['left','right','right','right','right','right','right','right','right']
|
1664
1744
|
print(dftmp1.to_markdown(tablefmt='Simple',index=False,colalign=colalignList))
|
1665
1745
|
print('\n数据来源:新浪财经,',str(today))
|
1666
|
-
|
1746
|
+
"""
|
1747
|
+
footnote='数据来源:新浪财经,'+str(today)
|
1748
|
+
df_display_CSS(df=dftmp1,titletxt=titletxt,footnote=footnote, \
|
1749
|
+
facecolor=facecolor,decimals=2, \
|
1750
|
+
heading_font_size='16px',data_font_size='16px')
|
1751
|
+
|
1667
1752
|
"""
|
1668
1753
|
加权平均每股收益:
|
1669
1754
|
指计算时股份数用按月对总股数加权计算的数据,理由是由于公司投入的资本和资产不同,收益产生的基础也不同。
|
@@ -1704,7 +1789,7 @@ def stock_profile_china(ticker,category='profile', \
|
|
1704
1789
|
dftmp1=dftmp.T
|
1705
1790
|
dftmp1.reset_index(inplace=True)
|
1706
1791
|
dftmp1.rename(columns={'index':'项目'},inplace=True)
|
1707
|
-
|
1792
|
+
"""
|
1708
1793
|
if prettytab:
|
1709
1794
|
pandas2prettytable(dftmp1,titletxt,firstColSpecial=False,leftColAlign='l',otherColAlign='r',tabborder=tabborder)
|
1710
1795
|
print(' ','数据来源:新浪财经,',str(today))
|
@@ -1713,7 +1798,12 @@ def stock_profile_china(ticker,category='profile', \
|
|
1713
1798
|
colalignList=['left','right','right','right','right','right','right','right','right']
|
1714
1799
|
print(dftmp1.to_markdown(tablefmt='Simple',index=False,colalign=colalignList))
|
1715
1800
|
print('\n数据来源:新浪财经,',str(today))
|
1716
|
-
|
1801
|
+
"""
|
1802
|
+
df_display_CSS(df=dftmp1,titletxt=titletxt,footnote=footnote, \
|
1803
|
+
facecolor=facecolor,decimals=2, \
|
1804
|
+
heading_font_size='16px',data_font_size='16px')
|
1805
|
+
|
1806
|
+
|
1717
1807
|
"""
|
1718
1808
|
总资产利润率=利润总额/平均总资产
|
1719
1809
|
总资产净利润率=净利润/平均总资产
|
@@ -1744,7 +1834,7 @@ def stock_profile_china(ticker,category='profile', \
|
|
1744
1834
|
dftmp2=dftmp1.T
|
1745
1835
|
dftmp2.reset_index(inplace=True)
|
1746
1836
|
dftmp2.rename(columns={'index':'项目'},inplace=True)
|
1747
|
-
|
1837
|
+
"""
|
1748
1838
|
if prettytab:
|
1749
1839
|
pandas2prettytable(dftmp2,titletxt,firstColSpecial=False,leftColAlign='l',otherColAlign='r',tabborder=tabborder)
|
1750
1840
|
print(' ','数据来源:新浪财经,',str(today))
|
@@ -1753,7 +1843,12 @@ def stock_profile_china(ticker,category='profile', \
|
|
1753
1843
|
colalignList=['left','right','right','right','right','right','right','right','right']
|
1754
1844
|
print(dftmp2.to_markdown(tablefmt='Simple',index=False,colalign=colalignList))
|
1755
1845
|
print('\n数据来源:新浪财经,',str(today))
|
1756
|
-
|
1846
|
+
"""
|
1847
|
+
df_display_CSS(df=dftmp2,titletxt=titletxt,footnote=footnote, \
|
1848
|
+
facecolor=facecolor,decimals=2, \
|
1849
|
+
heading_font_size='16px',data_font_size='16px')
|
1850
|
+
|
1851
|
+
|
1757
1852
|
"""
|
1758
1853
|
净资产收益率=净利润/净资产。净资产=所有者权益+少数股东权益
|
1759
1854
|
|
@@ -1778,7 +1873,7 @@ def stock_profile_china(ticker,category='profile', \
|
|
1778
1873
|
dftmp1=dftmp.T
|
1779
1874
|
dftmp1.reset_index(inplace=True)
|
1780
1875
|
dftmp1.rename(columns={'index':'项目'},inplace=True)
|
1781
|
-
|
1876
|
+
"""
|
1782
1877
|
if prettytab:
|
1783
1878
|
pandas2prettytable(dftmp1,titletxt,firstColSpecial=False,leftColAlign='l',otherColAlign='r',tabborder=tabborder)
|
1784
1879
|
print(' ','数据来源:新浪财经,',str(today))
|
@@ -1789,7 +1884,10 @@ def stock_profile_china(ticker,category='profile', \
|
|
1789
1884
|
print('\n数据来源:新浪财经,',str(today))
|
1790
1885
|
|
1791
1886
|
"""
|
1792
|
-
|
1887
|
+
df_display_CSS(df=dftmp1,titletxt=titletxt,footnote=footnote, \
|
1888
|
+
facecolor=facecolor,decimals=2, \
|
1889
|
+
heading_font_size='16px',data_font_size='16px')
|
1890
|
+
|
1793
1891
|
|
1794
1892
|
titletxt=ticker_name(ticker)+":主要财务信息,资产负债分析"
|
1795
1893
|
colList=['日期','财报类别','流动比率','速动比率','现金比率(%)','利息支付倍数','长期债务与营运资金比率(%)', \
|
@@ -1818,7 +1916,7 @@ def stock_profile_china(ticker,category='profile', \
|
|
1818
1916
|
dftmp1=dftmp.T
|
1819
1917
|
dftmp1.reset_index(inplace=True)
|
1820
1918
|
dftmp1.rename(columns={'index':'项目'},inplace=True)
|
1821
|
-
|
1919
|
+
"""
|
1822
1920
|
if prettytab:
|
1823
1921
|
pandas2prettytable(dftmp1,titletxt,firstColSpecial=False,leftColAlign='l',otherColAlign='r',tabborder=tabborder)
|
1824
1922
|
print(' ','数据来源:新浪财经,',str(today))
|
@@ -1827,7 +1925,12 @@ def stock_profile_china(ticker,category='profile', \
|
|
1827
1925
|
colalignList=['left','right','right','right','right','right','right','right','right']
|
1828
1926
|
print(dftmp1.to_markdown(tablefmt='Simple',index=False,colalign=colalignList))
|
1829
1927
|
print('\n数据来源:新浪财经,',str(today))
|
1830
|
-
|
1928
|
+
"""
|
1929
|
+
df_display_CSS(df=dftmp1,titletxt=titletxt,footnote=footnote, \
|
1930
|
+
facecolor=facecolor,decimals=2, \
|
1931
|
+
heading_font_size='16px',data_font_size='16px')
|
1932
|
+
|
1933
|
+
|
1831
1934
|
"""
|
1832
1935
|
股东权益比率(又称自有资本比率或净资产比率)是股东权益与资产总额的比率。
|
1833
1936
|
固定资产净值率是指固定资产原价扣除其累计磨损额后的余额即固定资产折余价值对固定资产原价的比率。
|
@@ -1859,7 +1962,7 @@ def stock_profile_china(ticker,category='profile', \
|
|
1859
1962
|
dftmp1.reset_index(inplace=True)
|
1860
1963
|
dftmp1.rename(columns={'index':'项目'},inplace=True)
|
1861
1964
|
|
1862
|
-
|
1965
|
+
"""
|
1863
1966
|
if prettytab:
|
1864
1967
|
pandas2prettytable(dftmp1,titletxt,firstColSpecial=False,leftColAlign='l',otherColAlign='r',tabborder=tabborder)
|
1865
1968
|
print(' ','数据来源:新浪财经,',str(today))
|
@@ -1868,7 +1971,11 @@ def stock_profile_china(ticker,category='profile', \
|
|
1868
1971
|
colalignList=['left','right','right','right','right','right','right','right','right']
|
1869
1972
|
print(dftmp1.to_markdown(tablefmt='Simple',index=False,colalign=colalignList))
|
1870
1973
|
print('\n数据来源:新浪财经,',str(today))
|
1871
|
-
|
1974
|
+
"""
|
1975
|
+
df_display_CSS(df=dftmp1,titletxt=titletxt,footnote=footnote, \
|
1976
|
+
facecolor=facecolor,decimals=2, \
|
1977
|
+
heading_font_size='15px',data_font_size='15px')
|
1978
|
+
|
1872
1979
|
"""
|
1873
1980
|
资产的经营现金流量回报率是经营活动产生的现金流量净额/总资产,是体现企业收现能力的指标之一。
|
1874
1981
|
|
siat/stock_technical.py
CHANGED
@@ -2615,7 +2615,7 @@ def security_technical2(ticker,start='default',end='default', \
|
|
2615
2615
|
fig = plt.figure()
|
2616
2616
|
ax = fig.add_subplot(111)
|
2617
2617
|
#plt.gca().set_facecolor('whitesmoke')
|
2618
|
-
|
2618
|
+
fig.gca().set_facecolor(facecolor) #放在这里生效,放尾部不生效
|
2619
2619
|
|
2620
2620
|
line0=False; line30=False; line50=False; line80=False
|
2621
2621
|
for l in tech_line_collist:
|
siat/valuation.py
CHANGED
@@ -927,7 +927,9 @@ if __name__=='__main__':
|
|
927
927
|
def security_valuation(tickers,indicators,start,end, \
|
928
928
|
preprocess='none',scaling_option='start', \
|
929
929
|
twinx=False,loc1='best',loc2='best', \
|
930
|
-
graph=True,
|
930
|
+
graph=True,facecolor='whitesmoke', \
|
931
|
+
annotate=False,annotate_value=False, \
|
932
|
+
mark_top=False,mark_bottom=False,mark_end=False):
|
931
933
|
"""
|
932
934
|
功能:绘制估值走势
|
933
935
|
"""
|
@@ -985,7 +987,8 @@ def security_valuation(tickers,indicators,start,end, \
|
|
985
987
|
draw_lines(df2,y_label=ylabeltxt,x_label=footnote, \
|
986
988
|
axhline_value=0,axhline_label='', \
|
987
989
|
title_txt=titletxt,data_label=False, \
|
988
|
-
resample_freq='D',loc=loc1
|
990
|
+
resample_freq='D',loc=loc1,facecolor=facecolor,
|
991
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
|
989
992
|
|
990
993
|
return df
|
991
994
|
|
@@ -1020,7 +1023,7 @@ def security_valuation(tickers,indicators,start,end, \
|
|
1020
1023
|
ylabeltxt='',titletxt=titletxt,footnote=footnote, \
|
1021
1024
|
twinx=twinx, \
|
1022
1025
|
resample_freq='D',loc1=loc1,loc2=loc2, \
|
1023
|
-
color1='red',color2='blue')
|
1026
|
+
color1='red',color2='blue',facecolor=facecolor)
|
1024
1027
|
return df
|
1025
1028
|
|
1026
1029
|
# 绘制双线: 两只证券,一个指标。twinx双轴绘图
|
@@ -1057,7 +1060,7 @@ def security_valuation(tickers,indicators,start,end, \
|
|
1057
1060
|
ylabeltxt=ylabeltxt,titletxt=titletxt,footnote=footnote, \
|
1058
1061
|
twinx=twinx, \
|
1059
1062
|
resample_freq='D',loc1=loc1,loc2=loc2, \
|
1060
|
-
color1='red',color2='blue')
|
1063
|
+
color1='red',color2='blue',facecolor=facecolor)
|
1061
1064
|
|
1062
1065
|
return df
|
1063
1066
|
|
@@ -1089,7 +1092,11 @@ def security_valuation(tickers,indicators,start,end, \
|
|
1089
1092
|
draw_lines(dfs2,y_label=y_label,x_label=x_label, \
|
1090
1093
|
axhline_value=0,axhline_label=axhline_label, \
|
1091
1094
|
title_txt=titletxt,data_label=False, \
|
1092
|
-
resample_freq='D',loc=loc1,
|
1095
|
+
resample_freq='D',loc=loc1, \
|
1096
|
+
annotate=annotate,annotate_value=annotate_value, \
|
1097
|
+
plus_sign=plus_sign, \
|
1098
|
+
facecolor=facecolor, \
|
1099
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
|
1093
1100
|
|
1094
1101
|
return df
|
1095
1102
|
|
@@ -1130,7 +1137,10 @@ def security_valuation(tickers,indicators,start,end, \
|
|
1130
1137
|
draw_lines(dfs2,y_label=y_label,x_label=x_label, \
|
1131
1138
|
axhline_value=0,axhline_label=axhline_label, \
|
1132
1139
|
title_txt=titletxt,data_label=False, \
|
1133
|
-
resample_freq='D',loc=loc1,
|
1140
|
+
resample_freq='D',loc=loc1,plus_sign=plus_sign, \
|
1141
|
+
annotate=annotate,annotate_value=annotate_value, \
|
1142
|
+
facecolor=facecolor, \
|
1143
|
+
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
|
1134
1144
|
|
1135
1145
|
return df
|
1136
1146
|
|
@@ -1142,7 +1152,7 @@ if __name__=='__main__':
|
|
1142
1152
|
base=''
|
1143
1153
|
|
1144
1154
|
|
1145
|
-
def print_valuation(df,indicator='PE',base=''):
|
1155
|
+
def print_valuation(df,indicator='PE',base='',facecolor='whitesmoke'):
|
1146
1156
|
"""
|
1147
1157
|
功能:显示同行估值数字,并进行对比
|
1148
1158
|
"""
|
@@ -1217,9 +1227,26 @@ def print_valuation(df,indicator='PE',base=''):
|
|
1217
1227
|
df4=df3[['证券名称',col_mean,'均值排名',col_latest_date,'排名@'+col_latest_date,col_mean_rel,col_latest_rel,'均值对比','对比@'+col_latest_date]]
|
1218
1228
|
|
1219
1229
|
titletxt="*** 估值对比:"+indicator+",降序排列"
|
1230
|
+
"""
|
1220
1231
|
print("\n",titletxt,'\n')
|
1221
1232
|
alignlist=['left','right','center','right','center']+['right']*(len(list(df4))-5)
|
1222
1233
|
print(df4.to_markdown(index=False,tablefmt='simple',colalign=alignlist))
|
1234
|
+
"""
|
1235
|
+
disph=df4.style.hide() #不显示索引列
|
1236
|
+
dispp=disph.format(precision=2) #设置带有小数点的列精度调整为小数点后2位
|
1237
|
+
#设置标题/列名
|
1238
|
+
dispt=dispp.set_caption(titletxt).set_table_styles(
|
1239
|
+
[{'selector':'caption', #设置标题
|
1240
|
+
'props':[('color','black'),('font-size','16px'),('font-weight','bold')]}, \
|
1241
|
+
{'selector':'th.col_heading', #设置列名
|
1242
|
+
'props':[('color','black'),('text-align','center'),('margin','auto')]}])
|
1243
|
+
#设置列数值对齐
|
1244
|
+
dispf=dispt.set_properties(**{'text-align':'center'})
|
1245
|
+
#设置前景背景颜色
|
1246
|
+
dispf2=dispf.set_properties(**{'background-color':facecolor,'color':fontcolor})
|
1247
|
+
|
1248
|
+
from IPython.display import display
|
1249
|
+
display(dispf2)
|
1223
1250
|
|
1224
1251
|
print(" ")
|
1225
1252
|
if diff > 0:
|