siat 1.7.49__py3-none-any.whl → 1.7.51__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/markowitz.py CHANGED
@@ -2180,35 +2180,8 @@ def security_correlation(tickers,start,end,info_type='Close'):
2180
2180
  return df_coor
2181
2181
 
2182
2182
  #==============================================================================
2183
-
2184
-
2185
-
2186
-
2187
-
2188
-
2189
-
2190
-
2191
-
2192
-
2193
-
2194
-
2195
-
2196
-
2197
-
2198
-
2199
-
2200
-
2201
-
2202
-
2203
-
2204
-
2205
-
2206
-
2207
-
2208
-
2209
-
2210
-
2211
-
2212
-
2183
+ #==============================================================================
2184
+ #==============================================================================
2185
+ #==============================================================================
2213
2186
 
2214
2187
 
siat/sector_china.py CHANGED
@@ -20,6 +20,7 @@ from siat.translate import *
20
20
  from siat.bond_base import *
21
21
  from siat.stock import *
22
22
  from siat.risk_adjusted_return import *
23
+ from siat.financials_china2 import *
23
24
  #==============================================================================
24
25
 
25
26
  if __name__=='__main__':
@@ -661,6 +662,7 @@ def print_industry_sw(itype='I',numberPerLine=5,colalign='left'):
661
662
  if __name__=='__main__':
662
663
  iname='食品饮料'
663
664
  iname='银行'
665
+ iname='汽车'
664
666
  numberPerLine=5
665
667
  colalign='right'
666
668
 
@@ -676,6 +678,9 @@ def print_industry_component_sw(iname,numberPerLine=5,colalign='left'):
676
678
  clist,cdf=industry_stock_sw(icode,top=1000)
677
679
 
678
680
  cdf['icode']=cdf['证券代码'].apply(lambda x: x+'.SS' if x[:1] in ['6'] else (x+'.SZ' if x[:1] in ['0','3'] else x+'.BJ' ))
681
+
682
+ # 删除'证券名称'为None的行
683
+ cdf=cdf.mask(cdf.eq('None')).dropna()
679
684
  cdf['name_code']=cdf.apply(lambda x: x['证券名称']+'('+x['icode']+')',axis=1)
680
685
 
681
686
  ilist=list(cdf['name_code'])
@@ -721,7 +726,7 @@ def industry_sw_code(iname):
721
726
  icode=industry[industry['name']==iname]['code'].values[0]
722
727
  except:
723
728
  #未查到
724
- print(" #Warning(industry_sw_code): industry name not found",iname)
729
+ #print(" #Warning(industry_sw_code): industry name not found",iname)
725
730
  return None
726
731
 
727
732
  return icode
@@ -758,7 +763,7 @@ def industry_sw_codes(inamelist):
758
763
  if not (icode is None):
759
764
  icodelist=icodelist+[icode]
760
765
  else:
761
- print(" #Warning(industries_sw_code): industry code not found",i)
766
+ print(" #Warning(industries_sw_code): industry name not found",i)
762
767
  return None
763
768
 
764
769
  return icodelist
@@ -1415,10 +1420,10 @@ def rank_industry_sw_sharpe(idfall,base_return='Exp Ret%',graph=True,axisamp=0.8
1415
1420
 
1416
1421
  #==============================================================================
1417
1422
  if __name__=='__main__':
1418
- industry='801843'
1423
+ industry='801780'
1419
1424
  top=5
1420
1425
 
1421
- def industry_stock_sw(industry='801270',top=5):
1426
+ def industry_stock_sw(industry='801270',top=5,printout=False):
1422
1427
  """
1423
1428
  功能:获取申万行业指数的成分股
1424
1429
  排序:按照权重从大到小,重仓优先
@@ -1456,6 +1461,12 @@ def industry_stock_sw(industry='801270',top=5):
1456
1461
  else:
1457
1462
  clist1=clist1+[c+'.SZ']
1458
1463
 
1464
+ if printout:
1465
+ title_txt="申万行业指数成分股排名与权重:"+industry_sw_name(industry)+'指数('+industry+')'
1466
+ import datetime as dt; today=str(dt.date.today())
1467
+ footnote="*** 数据来源:sina/EM,"+str(today)
1468
+ df_directprint(cdf1,title_txt,footnote)
1469
+
1459
1470
  return clist1,cdf1
1460
1471
 
1461
1472
  if __name__=='__main__':
@@ -1582,6 +1593,162 @@ def rank_msecurity_performance(tickers,start,end, \
1582
1593
 
1583
1594
  return df1
1584
1595
  #==============================================================================
1596
+ #==============================================================================
1597
+ if __name__=='__main__':
1598
+ tickers=['801160','801120','801170','801710','801890','801040','801130','801180','801720','801970']
1599
+ start='2022-1-1'
1600
+ end='2023-3-22'
1601
+ info_type='Close'
1602
+
1603
+ df=get_industry_sw('I')
1604
+ df=industry_correlation_sw(df,tickers,start,end,info_type='Close')
1605
+
1606
+ def cm2inch(x,y):
1607
+ return x/2.54,y/2.54
1608
+
1609
+ def industry_correlation_sw(df,tickers,start,end,info_type='Close'):
1610
+ """
1611
+ 功能:股票/指数收盘价之间的相关性
1612
+ info_type='Close': 默认Close, 还可为Open/High/Low/Volume
1613
+ """
1614
+ # 检查行业个数
1615
+ if not isinstance(tickers,list) or len(tickers) < 2:
1616
+ print(" #Error(industry_correlation_sw): number of industries too few",tickers)
1617
+ return None
1618
+
1619
+ # 检查信息类型
1620
+ info_types=['Close','Open','High','Low','Volume']
1621
+ info_types_cn=['收盘价','开盘价','最高价','最低价','成交量']
1622
+ if not(info_type in info_types):
1623
+ print(" #Error(industry_correlation_sw): invalid information type",info_type)
1624
+ print(" Supported information type:",info_types)
1625
+ return None
1626
+ pos=info_types.index(info_type)
1627
+ info_type_cn=info_types_cn[pos]
1628
+
1629
+ # 检查日期
1630
+ result,startdt,enddt=check_period(start,end)
1631
+ if not result:
1632
+ print(" #Error(industry_correlation_sw): invalid period",start,end)
1633
+ return None
1634
+
1635
+ # 合成行业行情信息
1636
+ print(" Consolidating industry performance, please wait ...")
1637
+ import pandas as pd
1638
+
1639
+ """
1640
+ tickercodes=industry_sw_codes(tickers)
1641
+ if tickercodes is None:
1642
+ tickercodes=tickers
1643
+ """
1644
+
1645
+ dfs=None
1646
+ for ind in tickers:
1647
+ dft=df[df['ticker']==ind]
1648
+ if dft is None:
1649
+ print(" #Warning(industry_correlation_sw): unknown industry code",ind)
1650
+ continue
1651
+
1652
+ dft2=dft[(dft.index >= startdt) & (dft.index <= enddt)]
1653
+ dft3=pd.DataFrame(dft2[info_type])
1654
+ dft3.rename(columns={info_type:industry_sw_name(ind)},inplace=True)
1655
+
1656
+ if dfs is None:
1657
+ dfs=dft3
1658
+ else:
1659
+ dfs=pd.merge(dfs,dft3,how='inner',left_index=True,right_index=True)
1660
+ dfs.dropna(axis=0,inplace=True)
1661
+
1662
+ df_coor = dfs.corr()
1663
+
1664
+ print(" Preparing cross-industry correlations, please wait ...")
1665
+ # here put the import lib
1666
+ import seaborn as sns
1667
+ sns.set(font='SimHei') # 解决Seaborn中文显示问题
1668
+
1669
+ fig = plt.figure(figsize=(cm2inch(12,8)))
1670
+ ax1 = plt.gca()
1671
+
1672
+ #构造mask,去除重复数据显示
1673
+ import numpy as np
1674
+ mask = np.zeros_like(df_coor)
1675
+ mask[np.triu_indices_from(mask)] = True
1676
+ mask2 = mask
1677
+ mask = (np.flipud(mask)-1)*(-1)
1678
+ mask = np.rot90(mask,k = -1)
1679
+
1680
+ im1 = sns.heatmap(df_coor,annot=True,cmap="YlGnBu"
1681
+ , mask=mask#构造mask,去除重复数据显示
1682
+ ,vmax=1,vmin=-1
1683
+ , fmt='.2f',ax = ax1,annot_kws={"size": 6})
1684
+
1685
+ ax1.tick_params(axis = 'both', length=0)
1686
+
1687
+ #计算相关性显著性并显示
1688
+ from scipy.stats import pearsonr
1689
+ rlist = []
1690
+ plist = []
1691
+ for i in dfs.columns.values:
1692
+ for j in dfs.columns.values:
1693
+ r,p = pearsonr(dfs[i],dfs[j])
1694
+ rlist.append(r)
1695
+ plist.append(p)
1696
+
1697
+ rarr = np.asarray(rlist).reshape(len(dfs.columns.values),len(dfs.columns.values))
1698
+ parr = np.asarray(plist).reshape(len(dfs.columns.values),len(dfs.columns.values))
1699
+ xlist = ax1.get_xticks()
1700
+ ylist = ax1.get_yticks()
1701
+
1702
+ widthx = 0
1703
+ widthy = -0.15
1704
+
1705
+ # 星号的大小
1706
+ font_dict={'size':5}
1707
+
1708
+ for m in ax1.get_xticks():
1709
+ for n in ax1.get_yticks():
1710
+ pv = (parr[int(m),int(n)])
1711
+ rv = (rarr[int(m),int(n)])
1712
+ if mask2[int(m),int(n)]<1.:
1713
+ #if abs(rv) > 0.5:
1714
+ if rv > 0.3:
1715
+ if pv< 0.05 and pv>= 0.01:
1716
+ ax1.text(n+widthx,m+widthy,'*',ha = 'center',color = 'white',fontdict=font_dict)
1717
+ if pv< 0.01 and pv>= 0.001:
1718
+ ax1.text(n+widthx,m+widthy,'**',ha = 'center',color = 'white',fontdict=font_dict)
1719
+ if pv< 0.001:
1720
+ #print([int(m),int(n)])
1721
+ ax1.text(n+widthx,m+widthy,'***',ha = 'center',color = 'white',fontdict=font_dict)
1722
+ else:
1723
+ if pv< 0.05 and pv>= 0.01:
1724
+ ax1.text(n+widthx,m+widthy,'*',ha = 'center',color = 'k',fontdict=font_dict)
1725
+ elif pv< 0.01 and pv>= 0.001:
1726
+ ax1.text(n+widthx,m+widthy,'**',ha = 'center',color = 'k',fontdict=font_dict)
1727
+ elif pv< 0.001:
1728
+ ax1.text(n+widthx,m+widthy,'***',ha = 'center',color = 'k',fontdict=font_dict)
1729
+
1730
+ plt.title("行业板块"+info_type_cn+"之间的相关性")
1731
+ plt.tick_params(labelsize=6)
1732
+
1733
+ footnote1="\n显著性数值:***非常显著(<0.001),**很显著(<0.01),*显著(<0.05),其余为不显著"
1734
+ footnote2="\n系数绝对值:>=0.8极强相关,0.6-0.8强相关,0.4-0.6相关,0.2-0.4弱相关,否则为极弱(不)相关"
1735
+
1736
+ footnote3="\n观察期间: "+start+'至'+end
1737
+ import datetime as dt; stoday=dt.date.today()
1738
+ footnote4=";来源:Sina/EM,"+str(stoday)+";基于申万行业分类"
1739
+
1740
+ fontxlabel={'size':6}
1741
+ plt.xlabel(footnote1+footnote2+footnote3+footnote4,fontxlabel)
1742
+ plt.show()
1743
+
1744
+ return df_coor
1745
+
1746
+ #==============================================================================
1747
+ #==============================================================================
1748
+ #==============================================================================
1749
+ #==============================================================================
1750
+
1751
+
1585
1752
 
1586
1753
  #==============================================================================
1587
1754
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: siat
3
- Version: 1.7.49
3
+ Version: 1.7.51
4
4
  Summary: Securities Investment Analysis Tools (siat)
5
5
  Home-page: https://pypi.org/project/siat/
6
6
  Author: Prof. WANG Dehong, Business School, BFSU (北京外国语大学 国际商学院 王德宏 教授)
@@ -53,7 +53,7 @@ siat/holding_risk.py,sha256=108tiI7DDl8uUZkyUiq6Y-McKeim1mxYsgqgk7CcXw8,30544
53
53
  siat/holding_risk_test.py,sha256=FRlw_9wFG98BYcg_cSj95HX5WZ1TvkGaOUdXD7-V86s,474
54
54
  siat/local_debug_test.py,sha256=CDAOffW1Rvs-TcNN5giWVvHMlch1w4dp-w5SIV9jXL0,3936
55
55
  siat/market_china.py,sha256=2_ov1KQwRtHQ6PXNO1TS4-wUPhBuoWla326g0x_xUgQ,31158
56
- siat/markowitz.py,sha256=sIgfOUkD23CxKgEfBL9sidzpa36De49ufNd2XdrWdpQ,91344
56
+ siat/markowitz.py,sha256=tCeWCz_KzkTD2ho1y3IrxY9-4IAn5BxVxDA2PlLdI2g,91527
57
57
  siat/markowitz_ccb_test.py,sha256=xBkkoaNHdq9KSUrNuHGgKTdNYUvgi84kNYcf719eoyE,1593
58
58
  siat/markowitz_ef_test.py,sha256=wjNlICkgRIqnonPeSIHo4Mu2GRtb9dr21wDt2kMNEcI,4032
59
59
  siat/markowitz_old.py,sha256=Lf7O_4QWT8RsdkHiUyc_7kKY3eZjKDtFR89Fz3pwYnY,33046
@@ -73,7 +73,7 @@ siat/risk_evaluation.py,sha256=lCDqCaSEppH0MFPFg-P14IYcF3IJqILbPfDmzf_AfcY,75061
73
73
  siat/risk_evaluation_test.py,sha256=YEXM96gKzTfwN4U61AS4Rr1tV7KgUvn4rRC6f3iMw9s,3731
74
74
  siat/risk_free_rate.py,sha256=r62zCl1qbI4lJU17GsgM-OmVx9oo3dltXeZVCNd6Uxg,12304
75
75
  siat/risk_free_rate_test.py,sha256=CpmhUf8aEAEZeNu4gvWP2Mz2dLoIgBX5bI41vfUBEr8,4285
76
- siat/sector_china.py,sha256=mTMspgBgd07pesdMhGm-SpTr-rcKts-kaEsIM3kXsjk,58803
76
+ siat/sector_china.py,sha256=rpJ-HA14nb5pk6IRS7GTS3moRKhLQeC5-YlMkQJgfYo,65349
77
77
  siat/sector_china_test.py,sha256=tvFQYptmj7jq6H5kNaRJtcP5Wgb-eWvaoSl33Y47ZsM,4210
78
78
  siat/security_price.py,sha256=ibrdUJyt_n0c8oKRbVStE1_ptmWkzy4YIHjpc_fGiPQ,29148
79
79
  siat/security_prices.py,sha256=Xl7EHz16qCUIzuPGpEi-g-tLGQKk3MqHmic556-Vs7U,71984
@@ -104,7 +104,7 @@ siat/universal_test.py,sha256=CDAOffW1Rvs-TcNN5giWVvHMlch1w4dp-w5SIV9jXL0,3936
104
104
  siat/valuation_china.py,sha256=U9FQgFcbJcS-S0cwy8iJ9Z0Rf8sxCN5Pxhm1DItUUgQ,51206
105
105
  siat/valuation_market_china_test.py,sha256=gbJ0ioauuo4koTPH6WKUkqcXiQPafnbhU5eKJ6lpdLA,1571
106
106
  siat/var_model_validation.py,sha256=zB_Skk_tmzIR15l6oAW3am4HBGVIG-eZ8gJhCdXZ8Qw,14859
107
- siat-1.7.49.dist-info/METADATA,sha256=X2D3EGkVuQ5cx9rdtAx0Ipu74S_VraqWUmrUCP-bDNw,1400
108
- siat-1.7.49.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
109
- siat-1.7.49.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
110
- siat-1.7.49.dist-info/RECORD,,
107
+ siat-1.7.51.dist-info/METADATA,sha256=SNhRr3owapwRinP3mPd2OG6wmJvFWBcya99n013Ruk8,1400
108
+ siat-1.7.51.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
109
+ siat-1.7.51.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
110
+ siat-1.7.51.dist-info/RECORD,,
File without changes