siat 3.8.1__py3-none-any.whl → 3.8.10__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/beta_adjustment.py +1 -1
- siat/beta_adjustment_china.py +1 -1
- siat/bond.py +4 -2
- siat/bond_base.py +2 -1
- siat/bond_china.py +2 -1
- siat/capm_beta2.py +57 -14
- siat/common.py +38 -11
- siat/cryptocurrency.py +6 -3
- siat/economy2.py +72 -9
- siat/financials.py +4 -2
- siat/financials2.py +4 -2
- siat/financials_china.py +2 -1
- siat/fund.py +12 -12
- siat/fund_china.py +561 -2
- siat/grafix.py +66 -24
- siat/holding_risk.py +4 -2
- siat/market_china.py +4 -1
- siat/markowitz.py +7 -7
- siat/markowitz2.py +6 -5
- siat/option_china.py +3 -2
- siat/risk_adjusted_return.py +2 -2
- siat/risk_evaluation.py +10 -6
- siat/sector_china.py +52 -20
- siat/security_trend2.py +10 -2
- siat/stock.py +17 -4
- siat/stock_profile.py +2 -1
- siat/stock_technical.py +2 -1
- {siat-3.8.1.dist-info → siat-3.8.10.dist-info}/METADATA +2 -10
- {siat-3.8.1.dist-info → siat-3.8.10.dist-info}/RECORD +32 -32
- {siat-3.8.1.dist-info → siat-3.8.10.dist-info}/WHEEL +1 -1
- {siat-3.8.1.dist-info → siat-3.8.10.dist-info}/LICENSE +0 -0
- {siat-3.8.1.dist-info → siat-3.8.10.dist-info}/top_level.txt +0 -0
siat/grafix.py
CHANGED
@@ -30,7 +30,8 @@ plt.rcParams['xtick.direction'] = 'inout' # 将x轴的刻度线方向设置向
|
|
30
30
|
plt.rcParams['ytick.direction'] = 'inout' # 将y轴的刻度方向设置向内内
|
31
31
|
|
32
32
|
#统一设定绘制的图片大小:数值为英寸,1英寸=100像素
|
33
|
-
plt.rcParams['figure.figsize']=(12.8,7.2)
|
33
|
+
#plt.rcParams['figure.figsize']=(12.8,7.2)
|
34
|
+
plt.rcParams['figure.figsize']=(12.8,6.4)
|
34
35
|
plt.rcParams['figure.dpi']=300
|
35
36
|
plt.rcParams['font.size'] = 13
|
36
37
|
plt.rcParams['xtick.labelsize']=11 #横轴字体大小
|
@@ -124,7 +125,7 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
|
|
124
125
|
resample_freq='H',loc='best', \
|
125
126
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
126
127
|
mark_top=True,mark_bottom=True,mark_end=True, \
|
127
|
-
facecolor='whitesmoke',maxticks=
|
128
|
+
facecolor='whitesmoke',maxticks=15,translate=False):
|
128
129
|
"""
|
129
130
|
功能:绘制折线图。如果power=0不绘制趋势图,否则绘制多项式趋势图
|
130
131
|
假定:数据表有索引,且已经按照索引排序
|
@@ -421,7 +422,8 @@ def plot_line2(df1,ticker1,colname1,label1, \
|
|
421
422
|
yline=999,attention_value_area='', \
|
422
423
|
xline=999,attention_point_area='', \
|
423
424
|
resample_freq='H',loc1='best',loc2='best', \
|
424
|
-
color1='red',color2='blue',facecolor='whitesmoke'
|
425
|
+
color1='red',color2='blue',facecolor='whitesmoke', \
|
426
|
+
maxticks=20):
|
425
427
|
"""
|
426
428
|
功能:绘制两个证券的折线图。如果power=0不绘制趋势图,否则绘制多项式趋势图
|
427
429
|
假定:数据表有索引,且已经按照索引排序
|
@@ -456,7 +458,8 @@ def plot_line2(df1,ticker1,colname1,label1, \
|
|
456
458
|
xline=xline,attention_point_area=attention_point_area, \
|
457
459
|
resample_freq=resample_freq, \
|
458
460
|
loc1=loc1,loc2=loc2, \
|
459
|
-
color1=color1,color2=color2,facecolor=facecolor
|
461
|
+
color1=color1,color2=color2,facecolor=facecolor, \
|
462
|
+
maxticks=maxticks)
|
460
463
|
else:
|
461
464
|
plot_line2_twinx(df1,ticker1,colname1,label1, \
|
462
465
|
df2,ticker2,colname2,label2, \
|
@@ -464,7 +467,8 @@ def plot_line2(df1,ticker1,colname1,label1, \
|
|
464
467
|
resample_freq=resample_freq, \
|
465
468
|
xline=xline,attention_point_area=attention_point_area, \
|
466
469
|
loc1=loc1,loc2=loc2, \
|
467
|
-
color1=color1,color2=color2,facecolor=facecolor
|
470
|
+
color1=color1,color2=color2,facecolor=facecolor, \
|
471
|
+
maxticks=maxticks)
|
468
472
|
return
|
469
473
|
|
470
474
|
|
@@ -478,7 +482,8 @@ def plot2_line2(df1,ticker1,colname1,label1, \
|
|
478
482
|
xline=999,attention_point_area='', \
|
479
483
|
resample_freq='H',loc1='best',loc2='best', \
|
480
484
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
481
|
-
color1='red',color2='blue',facecolor='whitesmoke'
|
485
|
+
color1='red',color2='blue',facecolor='whitesmoke', \
|
486
|
+
maxticks=20):
|
482
487
|
"""
|
483
488
|
注意:可能有bug,twinx=True时左纵坐标轴和横坐标轴标记可能发生重叠!!!暂不建议使用
|
484
489
|
facecolor不起作用
|
@@ -517,7 +522,8 @@ def plot2_line2(df1,ticker1,colname1,label1, \
|
|
517
522
|
resample_freq=resample_freq, \
|
518
523
|
loc1=loc1,loc2=loc2, \
|
519
524
|
date_range=date_range,date_freq=date_freq,date_fmt=date_fmt, \
|
520
|
-
color1=color1,color2=color2,facecolor=facecolor
|
525
|
+
color1=color1,color2=color2,facecolor=facecolor, \
|
526
|
+
maxticks=maxticks)
|
521
527
|
else:
|
522
528
|
plot_line2_twinx2(df1,ticker1,colname1,label1, \
|
523
529
|
df2,ticker2,colname2,label2, \
|
@@ -526,7 +532,9 @@ def plot2_line2(df1,ticker1,colname1,label1, \
|
|
526
532
|
resample_freq=resample_freq, \
|
527
533
|
loc1=loc1,loc2=loc2, \
|
528
534
|
date_range=date_range,date_freq=date_freq,date_fmt=date_fmt, \
|
529
|
-
color1=color1,color2=color2,facecolor=facecolor
|
535
|
+
color1=color1,color2=color2,facecolor=facecolor, \
|
536
|
+
maxticks=maxticks)
|
537
|
+
|
530
538
|
return
|
531
539
|
|
532
540
|
|
@@ -542,7 +550,7 @@ def plot_line2_coaxial(df01,ticker1,colname1,label1, \
|
|
542
550
|
resample_freq='H', \
|
543
551
|
loc1='best',loc2='best', \
|
544
552
|
color1='red',color2='blue',facecolor='whitesmoke', \
|
545
|
-
ticker_type='auto'):
|
553
|
+
ticker_type='auto',maxticks=15):
|
546
554
|
"""
|
547
555
|
功能:绘制两个证券的折线图。如果power=0不绘制趋势图,否则绘制多项式趋势图
|
548
556
|
假定:数据表有索引,且已经按照索引排序
|
@@ -749,6 +757,11 @@ def plot_line2_coaxial(df01,ticker1,colname1,label1, \
|
|
749
757
|
|
750
758
|
# 同轴绘图时,loc1/loc2未用上!
|
751
759
|
plt.legend(loc=loc1,fontsize=legend_txt_size)
|
760
|
+
|
761
|
+
# 使用 AutoDateLocator 自动选择最佳间隔,目的是显示最后一个日期,亲测有效!!!
|
762
|
+
import matplotlib.dates as mdates
|
763
|
+
ax.xaxis.set_major_locator(mdates.AutoDateLocator(maxticks=maxticks))
|
764
|
+
|
752
765
|
plt.gcf().autofmt_xdate(ha="center") # 优化标注(自动倾斜)
|
753
766
|
try:
|
754
767
|
plt.gca().set_facecolor(facecolor)
|
@@ -793,7 +806,8 @@ def plot_line2_coaxial2(df01,ticker1,colname1,label1, \
|
|
793
806
|
loc1='best',loc2='best', \
|
794
807
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
795
808
|
color1='red',color2='blue',facecolor='whitesmoke', \
|
796
|
-
ticker_type='auto'
|
809
|
+
ticker_type='auto', \
|
810
|
+
maxticks=15):
|
797
811
|
"""
|
798
812
|
功能:绘制两个证券的折线图。如果power=0不绘制趋势图,否则绘制多项式趋势图
|
799
813
|
假定:数据表有索引,且已经按照索引排序
|
@@ -1022,6 +1036,11 @@ def plot_line2_coaxial2(df01,ticker1,colname1,label1, \
|
|
1022
1036
|
|
1023
1037
|
# 同轴绘图时,loc1/loc2未用上!
|
1024
1038
|
plt.legend(loc=loc1,fontsize=legend_txt_size)
|
1039
|
+
|
1040
|
+
# 使用 AutoDateLocator 自动选择最佳间隔,目的是显示最后一个日期,亲测有效!!!
|
1041
|
+
import matplotlib.dates as mdates
|
1042
|
+
ax.xaxis.set_major_locator(mdates.AutoDateLocator(maxticks=maxticks))
|
1043
|
+
|
1025
1044
|
plt.gcf().autofmt_xdate(ha="center") # 优化标注(自动倾斜)
|
1026
1045
|
try:
|
1027
1046
|
plt.gca().set_facecolor(facecolor)
|
@@ -1045,7 +1064,8 @@ def plot_line2_twinx(df01,ticker1,colname1,label1, \
|
|
1045
1064
|
xline=999,attention_point_area='', \
|
1046
1065
|
loc1='upper left',loc2='lower left', \
|
1047
1066
|
color1='red',color2='blue',facecolor='whitesmoke', \
|
1048
|
-
ticker_type='auto'
|
1067
|
+
ticker_type='auto', \
|
1068
|
+
maxticks=15):
|
1049
1069
|
"""
|
1050
1070
|
功能:绘制两个证券的折线图。如果power=0不绘制趋势图,否则绘制多项式趋势图
|
1051
1071
|
假定:数据表有索引,且已经按照索引排序
|
@@ -1234,6 +1254,11 @@ def plot_line2_twinx(df01,ticker1,colname1,label1, \
|
|
1234
1254
|
label2txt=label2+'('+ticker_name(ticker2,ticker_type_list[1])+')'
|
1235
1255
|
ax2.set_ylabel(label2txt,fontsize=ylabel_txt_size)
|
1236
1256
|
ax2.legend(loc=loc2,fontsize=legend_txt_size)
|
1257
|
+
|
1258
|
+
# 使用 AutoDateLocator 自动选择最佳间隔,目的是显示最后一个日期,亲测有效!!!
|
1259
|
+
import matplotlib.dates as mdates
|
1260
|
+
ax.xaxis.set_major_locator(mdates.AutoDateLocator(maxticks=maxticks))
|
1261
|
+
ax2.xaxis.set_major_locator(mdates.AutoDateLocator(maxticks=maxticks))
|
1237
1262
|
|
1238
1263
|
#自动优化x轴标签
|
1239
1264
|
plt.gcf().autofmt_xdate(ha="center") # 优化标注(自动倾斜)
|
@@ -1267,7 +1292,8 @@ def plot_line2_twinx2(df01,ticker1,colname1,label1, \
|
|
1267
1292
|
resample_freq='H',loc1='upper left',loc2='lower left', \
|
1268
1293
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
1269
1294
|
color1='red',color2='blue',facecolor='whitesmoke', \
|
1270
|
-
ticker_type='auto'
|
1295
|
+
ticker_type='auto', \
|
1296
|
+
maxticks=15):
|
1271
1297
|
"""
|
1272
1298
|
功能:绘制两个证券的折线图。如果power=0不绘制趋势图,否则绘制多项式趋势图
|
1273
1299
|
假定:数据表有索引,且已经按照索引排序
|
@@ -1482,6 +1508,11 @@ def plot_line2_twinx2(df01,ticker1,colname1,label1, \
|
|
1482
1508
|
label2txt=label2+'('+ticker_name(ticker2,ticker_type_list[1])+')'
|
1483
1509
|
ax2.set_ylabel(label2txt,fontsize=ylabel_txt_size)
|
1484
1510
|
ax2.legend(loc=loc2,fontsize=legend_txt_size)
|
1511
|
+
|
1512
|
+
# 使用 AutoDateLocator 自动选择最佳间隔,目的是显示最后一个日期,亲测有效!!!
|
1513
|
+
import matplotlib.dates as mdates
|
1514
|
+
ax.xaxis.set_major_locator(mdates.AutoDateLocator(maxticks=maxticks))
|
1515
|
+
ax2.xaxis.set_major_locator(mdates.AutoDateLocator(maxticks=maxticks))
|
1485
1516
|
|
1486
1517
|
#自动优化x轴标签
|
1487
1518
|
#格式化时间轴标注
|
@@ -1520,7 +1551,9 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1520
1551
|
attention_value='',attention_value_area='', \
|
1521
1552
|
attention_point='',attention_point_area='', \
|
1522
1553
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
1523
|
-
ticker_type='auto',facecolor='whitesmoke',
|
1554
|
+
ticker_type='auto',facecolor='whitesmoke', \
|
1555
|
+
maxticks_enable=True,maxticks=15, \
|
1556
|
+
translate=False):
|
1524
1557
|
"""
|
1525
1558
|
函数功能:根据df的内容绘制折线图
|
1526
1559
|
输入参数:
|
@@ -1658,7 +1691,7 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1658
1691
|
if annotate_value: #在标记曲线名称的同时标记其末端数值
|
1659
1692
|
#y1=str(int(y_end)) if y_end >= 100 else str(round(y_end,2))
|
1660
1693
|
y1=str(round(y_end,2)) if abs(y_end) >= 100 else str(round(y_end,2)) if abs(y_end) >= 1 else str(round(y_end,3))
|
1661
|
-
plt.annotate(text=' '+auto_translate2(c,translate)+':'+y1,
|
1694
|
+
plt.annotate(text=' '+auto_translate2(c,translate)+': '+y1,
|
1662
1695
|
xy=(x_end, y_end),
|
1663
1696
|
xytext=(x_end, y_end),fontsize=annotate_size,
|
1664
1697
|
color=last_line_color)
|
@@ -1838,7 +1871,11 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1838
1871
|
if axhline_label !="":
|
1839
1872
|
if '零线' in axhline_label:
|
1840
1873
|
axhline_label=''
|
1841
|
-
|
1874
|
+
|
1875
|
+
max_values = df2.max(numeric_only=True); global_max_values=max_values.max()
|
1876
|
+
min_values = df2.min(numeric_only=True); global_min_values=min_values.min()
|
1877
|
+
if global_max_values >= axhline_value and global_min_values <= axhline_value:
|
1878
|
+
plt.axhline(y=axhline_value,label=auto_translate2(axhline_label,translate),color='black',linestyle=':',linewidth=2)
|
1842
1879
|
#plt.axhline(y=axhline_value,color='purple',linestyle=':',linewidth=1.5)
|
1843
1880
|
|
1844
1881
|
#坐标轴标记
|
@@ -1851,9 +1888,10 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1851
1888
|
#图示标题
|
1852
1889
|
plt.title(auto_translate2(title_txt,translate),fontweight='bold',fontsize=title_txt_size)
|
1853
1890
|
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1891
|
+
if maxticks_enable:
|
1892
|
+
# 使用 AutoDateLocator 自动选择最佳间隔,目的是显示最后一个日期,亲测有效!!!
|
1893
|
+
import matplotlib.dates as mdates
|
1894
|
+
ax.xaxis.set_major_locator(mdates.AutoDateLocator(maxticks=maxticks))
|
1857
1895
|
|
1858
1896
|
plt.gcf().autofmt_xdate(ha="center") # 优化标注(自动倾斜)
|
1859
1897
|
try:
|
@@ -1913,7 +1951,7 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1913
1951
|
attention_point_area='', \
|
1914
1952
|
annotate=False,annotate_value=False, \
|
1915
1953
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
1916
|
-
facecolor='whitesmoke',maxticks=
|
1954
|
+
facecolor='whitesmoke',maxticks=20,translate=False):
|
1917
1955
|
"""
|
1918
1956
|
函数功能:根据df的内容绘制折线图
|
1919
1957
|
输入参数:
|
@@ -2068,7 +2106,7 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
2068
2106
|
if annotate_value: #在标记曲线名称的同时标记其末端数值
|
2069
2107
|
#y1=str(int(y_end)) if y_end >= 100 else str(round(y_end,2))
|
2070
2108
|
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,4))
|
2071
|
-
plt.annotate(text=auto_translate2(c,translate)+':'+y1,
|
2109
|
+
plt.annotate(text=auto_translate2(c,translate)+': '+y1,
|
2072
2110
|
xy=(x_end, y_end),
|
2073
2111
|
xytext=(x_end, y_end),fontsize=annotate_size,
|
2074
2112
|
color=last_line_color)
|
@@ -2359,7 +2397,8 @@ def plot_2lines(df01,colname1,label1, \
|
|
2359
2397
|
df02,colname2,label2, \
|
2360
2398
|
ylabeltxt,titletxt,footnote,hline=0,vline=0,resample_freq='H', \
|
2361
2399
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
2362
|
-
facecolor='whitesmoke'
|
2400
|
+
facecolor='whitesmoke', \
|
2401
|
+
maxticks=15):
|
2363
2402
|
"""
|
2364
2403
|
功能:绘制两个证券的折线图。如果hline=0不绘制水平虚线,vline=0不绘制垂直虚线
|
2365
2404
|
假定:数据表有日期索引,且已经按照索引排序
|
@@ -2449,6 +2488,10 @@ def plot_2lines(df01,colname1,label1, \
|
|
2449
2488
|
plt.xlabel(footnote,fontsize=xlabel_txt_size,ha='center')
|
2450
2489
|
plt.legend(loc='best',fontsize=legend_txt_size)
|
2451
2490
|
|
2491
|
+
# 使用 AutoDateLocator 自动选择最佳间隔,目的是显示最后一个日期,亲测有效!!!
|
2492
|
+
import matplotlib.dates as mdates
|
2493
|
+
ax.xaxis.set_major_locator(mdates.AutoDateLocator(maxticks=maxticks))
|
2494
|
+
|
2452
2495
|
plt.gcf().autofmt_xdate(ha="center") # 优化标注(自动倾斜)
|
2453
2496
|
try:
|
2454
2497
|
plt.gca().set_facecolor(facecolor)
|
@@ -2717,7 +2760,7 @@ if __name__=='__main__':
|
|
2717
2760
|
firstColSpecial=True
|
2718
2761
|
colWidth=0.1
|
2719
2762
|
tabScale=2
|
2720
|
-
figsize=(
|
2763
|
+
figsize=(12.8,6.4)
|
2721
2764
|
cellLoc='right'
|
2722
2765
|
fontsize=10
|
2723
2766
|
|
@@ -2729,7 +2772,7 @@ if __name__=='__main__':
|
|
2729
2772
|
pandas2plttable(df)
|
2730
2773
|
|
2731
2774
|
def pandas2plttable(df,titletxt,firstColSpecial=True,colWidth=0.1,tabScale=2,cellLoc='right', \
|
2732
|
-
figsize=(
|
2775
|
+
figsize=(12.8,6.4),fontsize=13,auto_len=False,title_x=0.5):
|
2733
2776
|
"""
|
2734
2777
|
功能:将一个df转换为matplotlib表格格式,打印图形表格,适应性广
|
2735
2778
|
firstColSpecial:第一列是否特殊处理,默认True
|
@@ -2781,7 +2824,6 @@ def pandas2plttable(df,titletxt,firstColSpecial=True,colWidth=0.1,tabScale=2,cel
|
|
2781
2824
|
for i in range(0,len(df)):
|
2782
2825
|
vals=vals+[list(df.iloc[i])]
|
2783
2826
|
|
2784
|
-
#plt.figure(figsize=figsize,dpi=figdpi)
|
2785
2827
|
plt.figure(figsize=figsize)
|
2786
2828
|
|
2787
2829
|
if not auto_len:
|
siat/holding_risk.py
CHANGED
@@ -40,7 +40,8 @@ if czxt in ['linux']: #website Jupyter
|
|
40
40
|
plt.rcParams['axes.unicode_minus'] = False
|
41
41
|
#==============================================================================
|
42
42
|
#统一设定绘制的图片大小:数值为英寸,1英寸=100像素
|
43
|
-
plt.rcParams['figure.figsize']=(12.8,7.2)
|
43
|
+
#plt.rcParams['figure.figsize']=(12.8,7.2)
|
44
|
+
plt.rcParams['figure.figsize']=(12.8,6.4)
|
44
45
|
plt.rcParams['figure.dpi']=300
|
45
46
|
plt.rcParams['font.size'] = 13
|
46
47
|
plt.rcParams['xtick.labelsize']=11 #横轴字体大小
|
@@ -821,7 +822,8 @@ def portfolio_rets_curve(portfolio,fromdate,todate):
|
|
821
822
|
import numpy as np
|
822
823
|
x=mu+sigma*np.random.randn(10000)
|
823
824
|
|
824
|
-
plt.figure(figsize=(8,4))
|
825
|
+
#plt.figure(figsize=(8,4))
|
826
|
+
plt.figure(figsize=(12.8,6.4))
|
825
827
|
import seaborn as sns
|
826
828
|
#绘制曲线:股票收益率
|
827
829
|
sns.kdeplot(data=rets,shade=True,color='blue',legend=True,label='投资组合',lw=4)
|
siat/market_china.py
CHANGED
@@ -702,7 +702,10 @@ if __name__=='__main__':
|
|
702
702
|
df1=market_detail_china(category='price')
|
703
703
|
|
704
704
|
def market_detail_china(category='price',prettytab=True,plttab=False, \
|
705
|
-
colWidth=0.3,tabScale=2,
|
705
|
+
colWidth=0.3,tabScale=2, \
|
706
|
+
#figsize=(10,6), \
|
707
|
+
figsize=(12.8,6.4), \
|
708
|
+
fontsize=13,cellLoc='center'):
|
706
709
|
"""
|
707
710
|
功能:给出中国当前最新的三大股票交易所的更多细节,合成
|
708
711
|
输出:构造表格型数据框df,直接利用Jupyter Notebook格式输出
|
siat/markowitz.py
CHANGED
@@ -30,7 +30,8 @@ import datetime
|
|
30
30
|
import seaborn as sns
|
31
31
|
import matplotlib.pyplot as plt
|
32
32
|
#统一设定绘制的图片大小:数值为英寸,1英寸=100像素
|
33
|
-
plt.rcParams['figure.figsize']=(12.8,7.2)
|
33
|
+
#plt.rcParams['figure.figsize']=(12.8,7.2)
|
34
|
+
plt.rcParams['figure.figsize']=(12.8,6.4)
|
34
35
|
plt.rcParams['figure.dpi']=300
|
35
36
|
plt.rcParams['font.size'] = 13
|
36
37
|
plt.rcParams['xtick.labelsize']=11 #横轴字体大小
|
@@ -991,7 +992,7 @@ def portfolio_es(pf_info,simulation=50000):
|
|
991
992
|
pf_volatilities = np.array(RandomPortfolios['Volatility'])
|
992
993
|
|
993
994
|
#plt.style.use('seaborn-dark') #不支持中文
|
994
|
-
#plt.figure(figsize=(
|
995
|
+
#plt.figure(figsize=(12.8,6.4))
|
995
996
|
plt.scatter(pf_volatilities, pf_returns, c=pf_ratio,cmap='RdYlGn', edgecolors='black',marker='o')
|
996
997
|
#plt.grid(True)
|
997
998
|
|
@@ -1444,7 +1445,7 @@ def RandomPortfolios_plot(RandomPortfolios,col_x,col_y,colorbartxt,title_ext, \
|
|
1444
1445
|
pf_returns = np.array(RandomPortfolios['Risk premium'])
|
1445
1446
|
pf_volatilities = np.array(RandomPortfolios['beta'])
|
1446
1447
|
|
1447
|
-
plt.figure(figsize=(
|
1448
|
+
plt.figure(figsize=(12.8,6.4))
|
1448
1449
|
plt.scatter(pf_volatilities, pf_returns, c=pf_ratio,cmap='RdYlGn', edgecolors='black',marker='o')
|
1449
1450
|
plt.colorbar(label='特雷诺比率')
|
1450
1451
|
|
@@ -1466,7 +1467,7 @@ def RandomPortfolios_plot(RandomPortfolios,col_x,col_y,colorbartxt,title_ext, \
|
|
1466
1467
|
pf_returns = np.array(RandomPortfolios[col_y])
|
1467
1468
|
pf_volatilities = np.array(RandomPortfolios[col_x])
|
1468
1469
|
|
1469
|
-
#plt.figure(figsize=(
|
1470
|
+
#plt.figure(figsize=(12.8,6.4))
|
1470
1471
|
plt.scatter(pf_volatilities, pf_returns, c=pf_ratio,cmap='RdYlGn', edgecolors='black',marker='o')
|
1471
1472
|
plt.colorbar(label=colorbartxt)
|
1472
1473
|
|
@@ -2204,9 +2205,8 @@ def security_correlation(tickers,start='L5Y',end='today',info_type='Close'):
|
|
2204
2205
|
df_coor = df.corr()
|
2205
2206
|
|
2206
2207
|
|
2207
|
-
#fig = plt.figure(figsize=(
|
2208
|
-
|
2209
|
-
fig = plt.figure(figsize=(12.8,7.2))
|
2208
|
+
#fig = plt.figure(figsize=(12.8,7.2))
|
2209
|
+
fig = plt.figure(figsize=(12.8,6.4))
|
2210
2210
|
ax1 = plt.gca()
|
2211
2211
|
|
2212
2212
|
#构造mask,去除重复数据显示
|
siat/markowitz2.py
CHANGED
@@ -30,7 +30,8 @@ import datetime
|
|
30
30
|
import seaborn as sns
|
31
31
|
import matplotlib.pyplot as plt
|
32
32
|
#统一设定绘制的图片大小:数值为英寸,1英寸=100像素
|
33
|
-
plt.rcParams['figure.figsize']=(12.8,7.2)
|
33
|
+
#plt.rcParams['figure.figsize']=(12.8,7.2)
|
34
|
+
plt.rcParams['figure.figsize']=(12.8,6.4)
|
34
35
|
plt.rcParams['figure.dpi']=300
|
35
36
|
plt.rcParams['font.size'] = 13
|
36
37
|
plt.rcParams['xtick.labelsize']=11 #横轴字体大小
|
@@ -1216,7 +1217,7 @@ def portfolio_eset(pf_info,simulation=50000,convex_hull=False,frontier="both",fa
|
|
1216
1217
|
pf_volatilities = np.array(RandomPortfolios['Volatility'])
|
1217
1218
|
|
1218
1219
|
#plt.style.use('seaborn-dark') #不支持中文
|
1219
|
-
#plt.figure(figsize=(
|
1220
|
+
#plt.figure(figsize=(12.8,6.4))
|
1220
1221
|
plt.scatter(pf_volatilities,pf_returns,c=pf_ratio,cmap='RdYlGn',edgecolors='black',marker='o')
|
1221
1222
|
#plt.grid(True)
|
1222
1223
|
|
@@ -1799,7 +1800,7 @@ def RandomPortfolios_plot(RandomPortfolios,col_x,col_y,colorbartxt,title_ext, \
|
|
1799
1800
|
pf_returns = np.array(RandomPortfolios['Risk premium'])
|
1800
1801
|
pf_volatilities = np.array(RandomPortfolios['beta'])
|
1801
1802
|
|
1802
|
-
plt.figure(figsize=(
|
1803
|
+
plt.figure(figsize=(12.8,6.4))
|
1803
1804
|
plt.scatter(pf_volatilities, pf_returns, c=pf_ratio,cmap='RdYlGn', edgecolors='black',marker='o')
|
1804
1805
|
plt.colorbar(label='特雷诺比率')
|
1805
1806
|
|
@@ -1822,7 +1823,7 @@ def RandomPortfolios_plot(RandomPortfolios,col_x,col_y,colorbartxt,title_ext, \
|
|
1822
1823
|
pf_returns = np.array(RandomPortfolios[col_y])
|
1823
1824
|
pf_volatilities = np.array(RandomPortfolios[col_x])
|
1824
1825
|
|
1825
|
-
#plt.figure(figsize=(
|
1826
|
+
#plt.figure(figsize=(12.8,6.4))
|
1826
1827
|
plt.scatter(pf_volatilities, pf_returns, c=pf_ratio,cmap='RdYlGn', edgecolors='black',marker='o')
|
1827
1828
|
plt.colorbar(label=colorbartxt)
|
1828
1829
|
|
@@ -2720,7 +2721,7 @@ def security_correlation(tickers,start='L5Y',end='today',info_type='Close', \
|
|
2720
2721
|
#fig = plt.figure(figsize=(cm2inch(16,12)))
|
2721
2722
|
#fig = plt.figure(figsize=(cm2inch(12,8)))
|
2722
2723
|
#fig = plt.figure(figsize=(12.8,7.2))
|
2723
|
-
fig = plt.figure(figsize=(12,6))
|
2724
|
+
fig = plt.figure(figsize=(12.8,6.4))
|
2724
2725
|
ax1 = plt.gca()
|
2725
2726
|
|
2726
2727
|
#构造mask,去除重复数据显示
|
siat/option_china.py
CHANGED
@@ -2273,10 +2273,11 @@ def fin_option_risk_sse2(option,maturity,exercise,trade_date, \
|
|
2273
2273
|
|
2274
2274
|
#fig = plt.figure()
|
2275
2275
|
import matplotlib.pyplot as plt
|
2276
|
-
plt.rcParams['figure.figsize']=(12.8,7.2)
|
2276
|
+
#plt.rcParams['figure.figsize']=(12.8,7.2)
|
2277
|
+
plt.rcParams['figure.figsize']=(12.8,6.4)
|
2277
2278
|
plt.rcParams['figure.dpi']=300
|
2278
2279
|
"""
|
2279
|
-
c=dfg.plot(kind='bar', y=['看涨期权','看跌期权'],figsize=(
|
2280
|
+
c=dfg.plot(kind='bar', y=['看涨期权','看跌期权'],figsize=(12.8,6.4),width=0.8,
|
2280
2281
|
color=['green','red'],fontsize=16)
|
2281
2282
|
"""
|
2282
2283
|
#柱状图填充图案
|
siat/risk_adjusted_return.py
CHANGED
@@ -476,7 +476,7 @@ def draw_rar_ratio(rars,portfolio,ratio_name):
|
|
476
476
|
rars2=rars1.interpolate(method='cubic')
|
477
477
|
"""
|
478
478
|
|
479
|
-
#plt.figure(figsize=(8,
|
479
|
+
#plt.figure(figsize=(12.8,6.4))
|
480
480
|
|
481
481
|
labeltxt=ratio_name.capitalize()+'指标'
|
482
482
|
plt.plot(rars['RAR'],label=labeltxt,color='red',lw=1)
|
@@ -510,7 +510,7 @@ def draw_rar_ratio(rars,portfolio,ratio_name):
|
|
510
510
|
"""
|
511
511
|
import seaborn as sns
|
512
512
|
with sns.axes_style("whitegrid"):
|
513
|
-
fig, ax = plt.subplots(figsize=(8,
|
513
|
+
fig, ax = plt.subplots(figsize=(12.8,6.4))
|
514
514
|
ax.plot(rars['RAR'],label=labeltxt,color='red',lw=3)
|
515
515
|
#ax.plot(rars['Mean(Ret)'],label='Stock(s) return(%)',color='blue',lw=1)
|
516
516
|
plt.axhline(y=0.0,label='Zero return',color='black',linestyle=':')
|
siat/risk_evaluation.py
CHANGED
@@ -40,7 +40,8 @@ if czxt in ['linux']: #website Jupyter
|
|
40
40
|
plt.rcParams['axes.unicode_minus'] = False
|
41
41
|
#==============================================================================
|
42
42
|
#统一设定绘制的图片大小:数值为英寸,1英寸=100像素
|
43
|
-
plt.rcParams['figure.figsize']=(12.8,7.2)
|
43
|
+
#plt.rcParams['figure.figsize']=(12.8,7.2)
|
44
|
+
plt.rcParams['figure.figsize']=(12.8,6.4)
|
44
45
|
plt.rcParams['figure.dpi']=300
|
45
46
|
plt.rcParams['font.size'] = 13
|
46
47
|
plt.rcParams['xtick.labelsize']=11 #横轴字体大小
|
@@ -742,7 +743,8 @@ def plot_rets_histogram(ticker,start,end,num_bins=20):
|
|
742
743
|
sigma=rets.std()
|
743
744
|
|
744
745
|
#绘制股票收益率直方图
|
745
|
-
plt.figure(figsize=(8,4))
|
746
|
+
#plt.figure(figsize=(8,4))
|
747
|
+
plt.figure(figsize=(12.8,6.4))
|
746
748
|
n,bins,patches=plt.hist(rets,num_bins,facecolor='blue',alpha=0.5,label=ticker_name(ticker))
|
747
749
|
|
748
750
|
#生成与直方图柱子对应的正态分布概率密度
|
@@ -789,7 +791,7 @@ def plot_rets_curve(ticker,start,end):
|
|
789
791
|
import numpy as np
|
790
792
|
x=mu+sigma*np.random.randn(1000000)
|
791
793
|
|
792
|
-
#plt.figure(figsize=(8,4))
|
794
|
+
#plt.figure(figsize=(12.8,6.4))
|
793
795
|
import seaborn as sns
|
794
796
|
#绘制曲线:股票收益率
|
795
797
|
sns.kdeplot(data=rets,shade=True,color='blue',legend=True,label=ticker_name(ticker),lw=2)
|
@@ -1435,7 +1437,7 @@ def series_VaR_tlcp(tickerlist,today,alpha=0.99,pastyears=1,model="montecarlo"):
|
|
1435
1437
|
#tlcpdf.reset_index(drop=True)
|
1436
1438
|
tlcpdf.set_index('Ticker',drop=True,inplace=True)
|
1437
1439
|
"""
|
1438
|
-
#ax=plt.figure(figsize=(8,4))
|
1440
|
+
#ax=plt.figure(figsize=(12.8,6.4))
|
1439
1441
|
tlcpdf.plot.barh(x='Ticker',y='TLCP',color='r',grid=True)
|
1440
1442
|
plt.ylabel('股票')
|
1441
1443
|
titlel1="VaR全损临界点(TLCP)"
|
@@ -1516,7 +1518,8 @@ def plot_VaR_days_changes(ticker,shares,today,dayslist,alpha=0.99, \
|
|
1516
1518
|
|
1517
1519
|
#绘图
|
1518
1520
|
if printout == True:
|
1519
|
-
plt.figure(figsize=(8,4))
|
1521
|
+
#plt.figure(figsize=(8,4))
|
1522
|
+
plt.figure(figsize=(12.8,6.4))
|
1520
1523
|
#绘制曲线:ratio
|
1521
1524
|
plt.plot(vardf['ratio%'],color='red',lw=2,label=ticker_name(ticker),marker=markertype)
|
1522
1525
|
#设置标题、图例、坐标轴标签
|
@@ -1564,7 +1567,8 @@ def compare_VaR_days_changes(tickerlist,shares,today,dayslist,alpha=0.99, \
|
|
1564
1567
|
return
|
1565
1568
|
|
1566
1569
|
#依次绘图tickerlist中的各个股票
|
1567
|
-
plt.figure(figsize=(8,4))
|
1570
|
+
#plt.figure(figsize=(8,4))
|
1571
|
+
plt.figure(figsize=(12.8,6.4))
|
1568
1572
|
|
1569
1573
|
markerlist=['.','o','s','*','+','x','1','2']
|
1570
1574
|
for t in tickerlist:
|
siat/sector_china.py
CHANGED
@@ -889,9 +889,17 @@ def display_industry_sw(sw_level='1',numberPerLine=4,colalign='left'):
|
|
889
889
|
"""
|
890
890
|
按照类别打印申万行业列表,名称(代码),每行5个, 套壳函数
|
891
891
|
"""
|
892
|
-
itype_list=['1','2','3','F','S','B','C']
|
893
|
-
|
894
|
-
|
892
|
+
#itype_list=['1','2','3','F','S','B','C']
|
893
|
+
itype_list=['1','2','3','F','S','B']
|
894
|
+
#sw_level_list=['1','2','3','F','S','B','C']
|
895
|
+
sw_level_list=['1','2','3','F','S','B']
|
896
|
+
|
897
|
+
try:
|
898
|
+
pos=sw_level_list.index(sw_level)
|
899
|
+
except:
|
900
|
+
print(f" #Warning(display_industry_sw): no such level in Shenwan system {sw_level}")
|
901
|
+
print(f" Supported Shenwan system: {sw_level_list}")
|
902
|
+
|
895
903
|
itype=itype_list[pos]
|
896
904
|
|
897
905
|
print_industry_sw(itype=itype,numberPerLine=numberPerLine,colalign=colalign)
|
@@ -2721,7 +2729,8 @@ def industry_correlation_sw(df,tickers,start,end, \
|
|
2721
2729
|
import seaborn as sns
|
2722
2730
|
sns.set(font='SimHei') # 解决Seaborn中文显示问题
|
2723
2731
|
|
2724
|
-
fig = plt.figure(figsize=(cm2inch(12,8)))
|
2732
|
+
#fig = plt.figure(figsize=(cm2inch(12,8)))
|
2733
|
+
fig = plt.figure(figsize=(12.8,6.4))
|
2725
2734
|
ax1 = plt.gca()
|
2726
2735
|
|
2727
2736
|
#构造mask,去除重复数据显示
|
@@ -2884,6 +2893,7 @@ if __name__=='__main__':
|
|
2884
2893
|
|
2885
2894
|
def find_peers_china(industry='',top=20,rank=20,sw_level='2'):
|
2886
2895
|
"""
|
2896
|
+
===========================================================================
|
2887
2897
|
功能:找出一个申万行业的上市公司排名
|
2888
2898
|
主要参数:
|
2889
2899
|
industry:申万行业名称。当industry = '',显示的内容由sw_level控制。申万二级行业分类
|
@@ -3489,10 +3499,13 @@ if __name__=='__main__':
|
|
3489
3499
|
|
3490
3500
|
def find_industry_sw(ticker,level='1',ticker_order=True,max_sleep=30):
|
3491
3501
|
"""
|
3502
|
+
===========================================================================
|
3492
3503
|
功能:寻找一只或一组股票所属的申万行业,支持股票代码和股票名称。
|
3493
|
-
level='1':默认只查找申万1
|
3494
|
-
ticker_order=True:默认输出结果按照ticker
|
3495
|
-
max_sleep
|
3504
|
+
level='1':默认只查找申万1级行业;查找2/3级行业时间较久,可能触发反爬虫机制。
|
3505
|
+
ticker_order=True:默认输出结果按照ticker中的顺序,而非按照所属行业排序。
|
3506
|
+
max_sleep:为防止触发反爬虫机制,默认每次爬虫后睡眠最多30秒钟。
|
3507
|
+
|
3508
|
+
返回值:查找结果df。
|
3496
3509
|
"""
|
3497
3510
|
print(" Searching shenwan industries for securities ... ...")
|
3498
3511
|
|
@@ -3621,21 +3634,24 @@ if __name__=='__main__':
|
|
3621
3634
|
|
3622
3635
|
peers=stock_industry_peer_em(ticker,indicator="市盈率",rank=10)
|
3623
3636
|
|
3624
|
-
def stock_peers_em(ticker='',indicator='',rank=10, \
|
3637
|
+
def stock_peers_em(ticker='',indicator='市盈率',rank=10, \
|
3625
3638
|
force_show_stock=True, \
|
3626
3639
|
font_size="16px",facecolor="papayawhip", \
|
3627
3640
|
numberPerLine=5):
|
3628
3641
|
"""
|
3629
|
-
|
3630
|
-
|
3642
|
+
===========================================================================
|
3643
|
+
功能:基于东方财富行业分类,查找股票所属的行业板块以及主要同行排名。
|
3644
|
+
特点:行业分类较粗糙,略胜于无。
|
3631
3645
|
主要参数:
|
3632
|
-
ticker:股票代码,默认''
|
3633
|
-
indicator:排名指标,默认''。例如:"股价"、"流动性"、"市净率"、"市盈率"
|
3634
|
-
rank:排名数量,默认10
|
3635
|
-
force_show_stock:是否显示股票信息,默认False
|
3636
|
-
font_size:表格字体大小,默认"16px"
|
3637
|
-
facecolor:输出表格的背景颜色,默认"papayawhip"
|
3638
|
-
numberPerLine:输出表格中的每行显示个数,默认5
|
3646
|
+
ticker:股票代码,默认''显示所有板块名称。
|
3647
|
+
indicator:排名指标,默认''。例如:"股价"、"流动性"、"市净率"、"市盈率"。
|
3648
|
+
rank:排名数量,默认10前十名。
|
3649
|
+
force_show_stock:是否显示股票信息,默认False。
|
3650
|
+
font_size:表格字体大小,默认"16px"。
|
3651
|
+
facecolor:输出表格的背景颜色,默认"papayawhip"。
|
3652
|
+
numberPerLine:输出表格中的每行显示个数,默认5。
|
3653
|
+
|
3654
|
+
注意:若结果异常,可尝试升级插件akshare。
|
3639
3655
|
|
3640
3656
|
示例:
|
3641
3657
|
industries=stock_peers_em() # 显示东方财富所有行业板块分类
|
@@ -3663,6 +3679,7 @@ def stock_peers_em(ticker='',indicator='',rank=10, \
|
|
3663
3679
|
except:
|
3664
3680
|
if not ticker=='':
|
3665
3681
|
print(" #Warning(stock_peer_em): stock info not found for",ticker)
|
3682
|
+
print(" Solution: if stock code is correct, upgrade akshare and try again")
|
3666
3683
|
|
3667
3684
|
df_em=ak.stock_board_industry_name_em()
|
3668
3685
|
#df_em.sort_values(by="板块名称",ascending=True,inplace=True)
|
@@ -3725,7 +3742,8 @@ def stock_peers_em(ticker='',indicator='',rank=10, \
|
|
3725
3742
|
df_disp=cfg[collist].tail(abs(rank))
|
3726
3743
|
|
3727
3744
|
#强制显示所选股票
|
3728
|
-
if force_show_stock and rank != 10:
|
3745
|
+
#if force_show_stock and rank != 10:
|
3746
|
+
if force_show_stock:
|
3729
3747
|
#所选股票是否在其中?
|
3730
3748
|
if not ticker[:6] in list(df_disp["代码"]):
|
3731
3749
|
ticker_seq=cfg[cfg["代码"]==ticker[:6]]["序号"].values[0]
|
@@ -3780,8 +3798,22 @@ def concept_stocks_em(concept='',ticker='',indicator="市盈率",rank=10, \
|
|
3780
3798
|
force_show_stock=False, \
|
3781
3799
|
font_size="16px",facecolor="papayawhip",numberPerLine=5):
|
3782
3800
|
"""
|
3783
|
-
|
3784
|
-
|
3801
|
+
===========================================================================
|
3802
|
+
功能:基于东方财富概念板块,查找关键字相关概念以及股票业绩。
|
3803
|
+
特点:概念板块划分细致,同一股票可能分属多个板块,与行业分类不同。
|
3804
|
+
参数:
|
3805
|
+
concept:概念板块名称,或名称中的关键字,默认''输出所有概念板块名称;
|
3806
|
+
若查找到多个名称,则优先输出查找到的名称;
|
3807
|
+
若仅仅找到一个板块,则按indicator输出该板块的股票排行。
|
3808
|
+
ticker:股票代码,默认''
|
3809
|
+
indicator:指标名称,默认"市盈率",还支持:股价,市净率,涨跌幅,流动性,换手率。
|
3810
|
+
rank:排名,支持正负数,默认10。
|
3811
|
+
force_show_stock:若ticker不为空,且不在rank范围内,是否强制显示该股票,默认False。
|
3812
|
+
font_size:显示字体大小,默认"16px"。
|
3813
|
+
facecolor:表格背景颜色,默认"papayawhip"。
|
3814
|
+
numberPerLine:当显示板块名称时,每行显示个数,默认5。
|
3815
|
+
|
3816
|
+
返回值:df
|
3785
3817
|
"""
|
3786
3818
|
if indicator in ["股价","股票价格","价格","收盘价","价位"]:
|
3787
3819
|
indicator="最新价"
|