siat 3.5.12__py3-none-any.whl → 3.6.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 +39 -11
- siat/grafix.py +276 -20
- siat/option_china.py +1 -1
- siat/risk_adjusted_return2.py +55 -7
- siat/security_trend2.py +70 -14
- siat/stock.py +58 -3
- siat/translate.py +1 -1
- siat/valuation.py +29 -12
- {siat-3.5.12.dist-info → siat-3.6.1.dist-info}/METADATA +1 -1
- {siat-3.5.12.dist-info → siat-3.6.1.dist-info}/RECORD +13 -13
- {siat-3.5.12.dist-info → siat-3.6.1.dist-info}/LICENSE +0 -0
- {siat-3.5.12.dist-info → siat-3.6.1.dist-info}/WHEEL +0 -0
- {siat-3.5.12.dist-info → siat-3.6.1.dist-info}/top_level.txt +0 -0
siat/capm_beta2.py
CHANGED
@@ -333,7 +333,10 @@ if __name__=='__main__':
|
|
333
333
|
def compare_mticker_1beta(ticker,start,end, \
|
334
334
|
adjust='', \
|
335
335
|
RF=0,regression_period=365, \
|
336
|
-
|
336
|
+
attention_value='', \
|
337
|
+
attention_point='', \
|
338
|
+
axhline_value=1,axhline_label='', \
|
339
|
+
graph=True,facecolor='whitesmoke',loc='best', \
|
337
340
|
annotate=False,annotate_value=False, \
|
338
341
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
339
342
|
mktidx='auto',source='auto',ticker_type='auto'):
|
@@ -427,9 +430,11 @@ def compare_mticker_1beta(ticker,start,end, \
|
|
427
430
|
draw_lines(df1,y_label,x_label=footnotex, \
|
428
431
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
429
432
|
title_txt=title_txt,data_label=False, \
|
433
|
+
attention_value=attention_value, \
|
434
|
+
attention_point=attention_point, \
|
430
435
|
annotate=annotate,annotate_value=annotate, \
|
431
436
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,
|
432
|
-
facecolor=facecolor)
|
437
|
+
facecolor=facecolor,loc=loc)
|
433
438
|
|
434
439
|
return df
|
435
440
|
|
@@ -456,7 +461,10 @@ def compare_1ticker_mRF(ticker,start,end, \
|
|
456
461
|
adjust='', \
|
457
462
|
RF=[0,0.02,0.05], \
|
458
463
|
regression_period=365, \
|
459
|
-
|
464
|
+
attention_value='', \
|
465
|
+
attention_point='', \
|
466
|
+
axhline_value=1,axhline_label='', \
|
467
|
+
graph=True,facecolor='whitesmoke',loc='best', \
|
460
468
|
annotate=False,annotate_value=False, \
|
461
469
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
462
470
|
mktidx='auto',source='auto', \
|
@@ -548,9 +556,11 @@ def compare_1ticker_mRF(ticker,start,end, \
|
|
548
556
|
draw_lines(df1,y_label,x_label=footnotex, \
|
549
557
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
550
558
|
title_txt=title_txt,data_label=False, \
|
559
|
+
attention_value=attention_value, \
|
560
|
+
attention_point=attention_point, \
|
551
561
|
annotate=annotate,annotate_value=annotate, \
|
552
562
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
553
|
-
facecolor=facecolor)
|
563
|
+
facecolor=facecolor,loc=loc)
|
554
564
|
|
555
565
|
return df
|
556
566
|
|
@@ -575,7 +585,10 @@ def compare_1ticker_mregression_period(ticker,start,end, \
|
|
575
585
|
adjust='', \
|
576
586
|
RF=0, \
|
577
587
|
regression_period=[183,365,730], \
|
578
|
-
|
588
|
+
attention_value='', \
|
589
|
+
attention_point='', \
|
590
|
+
axhline_value=1,axhline_label='', \
|
591
|
+
graph=True,facecolor='whitesmoke',loc='best', \
|
579
592
|
annotate=False,annotate_value=False, \
|
580
593
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
581
594
|
mktidx='auto',source='auto', \
|
@@ -662,9 +675,11 @@ def compare_1ticker_mregression_period(ticker,start,end, \
|
|
662
675
|
draw_lines(df1,y_label,x_label=footnotex, \
|
663
676
|
axhline_value=axhline_value,axhline_label=axhline_label, \
|
664
677
|
title_txt=title_txt,data_label=False, \
|
678
|
+
attention_value=attention_value, \
|
679
|
+
attention_point=attention_point, \
|
665
680
|
annotate=annotate,annotate_value=annotate, \
|
666
681
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
667
|
-
facecolor=facecolor)
|
682
|
+
facecolor=facecolor,loc=loc)
|
668
683
|
|
669
684
|
return df
|
670
685
|
|
@@ -693,11 +708,13 @@ if __name__=='__main__':
|
|
693
708
|
def compare_beta_security(ticker,start,end, \
|
694
709
|
adjust='', \
|
695
710
|
RF=0,regression_period=365, \
|
711
|
+
attention_value='', \
|
712
|
+
attention_point='', \
|
696
713
|
graph=True,facecolor='whitesmoke', \
|
697
714
|
annotate=False,annotate_value=False, \
|
698
715
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
699
716
|
mktidx='auto',source='auto', \
|
700
|
-
ticker_type='auto'):
|
717
|
+
ticker_type='auto',loc="best"):
|
701
718
|
"""
|
702
719
|
功能:组合情况,可能多只股票、多个投资组合或投资组合与股票的混合,多个无风险收益率
|
703
720
|
|
@@ -712,7 +729,9 @@ def compare_beta_security(ticker,start,end, \
|
|
712
729
|
df=compare_mticker_1beta(ticker,start,end, \
|
713
730
|
adjust=adjust, \
|
714
731
|
RF=RF,regression_period=regression_period, \
|
715
|
-
|
732
|
+
attention_value=attention_value, \
|
733
|
+
attention_point=attention_point, \
|
734
|
+
graph=graph,facecolor=facecolor,loc=loc, \
|
716
735
|
annotate=annotate,annotate_value=annotate, \
|
717
736
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
718
737
|
mktidx=mktidx,source=source, \
|
@@ -728,7 +747,10 @@ def compare_beta_security(ticker,start,end, \
|
|
728
747
|
df=compare_1ticker_mRF(ticker,start,end, \
|
729
748
|
adjust=adjust, \
|
730
749
|
RF=RF,regression_period=regression_period, \
|
731
|
-
|
750
|
+
attention_value=attention_value, \
|
751
|
+
attention_point=attention_point, \
|
752
|
+
|
753
|
+
graph=graph,facecolor=facecolor,loc=loc, \
|
732
754
|
annotate=annotate,annotate_value=annotate, \
|
733
755
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
734
756
|
mktidx=mktidx,source=source, \
|
@@ -744,7 +766,10 @@ def compare_beta_security(ticker,start,end, \
|
|
744
766
|
df=compare_1ticker_mregression_period(ticker,start,end, \
|
745
767
|
adjust=adjust, \
|
746
768
|
RF=RF,regression_period=regression_period, \
|
747
|
-
|
769
|
+
attention_value=attention_value, \
|
770
|
+
attention_point=attention_point, \
|
771
|
+
|
772
|
+
graph=graph,facecolor=facecolor,loc=loc, \
|
748
773
|
annotate=annotate,annotate_value=annotate, \
|
749
774
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
750
775
|
mktidx=mktidx,source=source, \
|
@@ -758,7 +783,10 @@ def compare_beta_security(ticker,start,end, \
|
|
758
783
|
df=compare_mticker_1beta(ticker,start,end, \
|
759
784
|
adjust=adjust, \
|
760
785
|
RF=RF,regression_period=regression_period, \
|
761
|
-
|
786
|
+
attention_value=attention_value, \
|
787
|
+
attention_point=attention_point, \
|
788
|
+
|
789
|
+
graph=graph,facecolor=facecolor,loc=loc, \
|
762
790
|
annotate=annotate,annotate_value=annotate, \
|
763
791
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
764
792
|
mktidx=mktidx,source=source, \
|
siat/grafix.py
CHANGED
@@ -24,6 +24,11 @@ import matplotlib.pyplot as plt
|
|
24
24
|
import matplotlib.dates as mdate
|
25
25
|
#import matplotlib.font_manager as fm
|
26
26
|
#==============================================================================
|
27
|
+
|
28
|
+
#设置刻度线风格:in,out,inout
|
29
|
+
plt.rcParams['xtick.direction'] = 'inout' # 将x轴的刻度线方向设置向内
|
30
|
+
plt.rcParams['ytick.direction'] = 'inout' # 将y轴的刻度方向设置向内内
|
31
|
+
|
27
32
|
#统一设定绘制的图片大小:数值为英寸,1英寸=100像素
|
28
33
|
plt.rcParams['figure.figsize']=(12.8,7.2)
|
29
34
|
plt.rcParams['figure.dpi']=300
|
@@ -55,10 +60,6 @@ plt.rcParams['axes.grid']=False
|
|
55
60
|
#plt.rcParams['grid.linewidth']=0.5
|
56
61
|
|
57
62
|
|
58
|
-
#设置刻度线风格:in,out,inout
|
59
|
-
plt.rcParams['xtick.direction'] = 'in' # 将x轴的刻度线方向设置向内
|
60
|
-
plt.rcParams['ytick.direction'] = 'in' # 将y轴的刻度方向设置向内内
|
61
|
-
|
62
63
|
#设置x,y 的主刻度定位器
|
63
64
|
#from matplotlib.pyplot import MultipleLocator
|
64
65
|
|
@@ -115,7 +116,12 @@ if __name__ =="__main__":
|
|
115
116
|
plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,mark_top=True,mark_bottom=True)
|
116
117
|
|
117
118
|
def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
|
118
|
-
power=0,zeroline=False,
|
119
|
+
power=0,zeroline=False, \
|
120
|
+
attention_value='', \
|
121
|
+
attention_point='', \
|
122
|
+
|
123
|
+
average_value=False, \
|
124
|
+
|
119
125
|
resample_freq='H',loc='best', \
|
120
126
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
121
127
|
mark_top=True,mark_bottom=True,mark_end=True, \
|
@@ -249,12 +255,51 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
|
|
249
255
|
plt.axhline(y=hline,ls=":",c="black",linewidth=2,label='')
|
250
256
|
haveLegend=False
|
251
257
|
else:
|
258
|
+
#不在必要,被attention_value的逻辑替代
|
252
259
|
if isinstance(zeroline,float) or isinstance(zeroline,int):
|
253
260
|
hline=zeroline
|
254
261
|
plt.axhline(y=hline,ls=":",c="darkorange",linewidth=3,label=text_lang("关注值","Attention"))
|
255
262
|
haveLegend=True
|
256
263
|
footnote=footnote + text_lang(",关注值",", Attention ")+str(hline)
|
257
|
-
|
264
|
+
|
265
|
+
#用于关注值的颜色列表
|
266
|
+
atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
|
267
|
+
#用于关注点的颜色列表
|
268
|
+
atp_color_list=["slateblue","lightsteelblue","lightcyan","beige","thistle"]
|
269
|
+
|
270
|
+
if not attention_value=='':
|
271
|
+
if isinstance(attention_value,int) or isinstance(attention_value,float):
|
272
|
+
atv_list=[attention_value]
|
273
|
+
elif isinstance(attention_value,list):
|
274
|
+
atv_list=attention_value
|
275
|
+
else:
|
276
|
+
atv_list=[]
|
277
|
+
if not atv_list==[] and not atv_list==['']:
|
278
|
+
for at in atv_list:
|
279
|
+
pos=atv_list.index(at)
|
280
|
+
color=atv_color_list[pos]
|
281
|
+
plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
|
282
|
+
|
283
|
+
if not attention_point=='':
|
284
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
285
|
+
atp_list=[attention_point]
|
286
|
+
elif isinstance(attention_point,list):
|
287
|
+
atp_list=attention_point
|
288
|
+
else:
|
289
|
+
atp_list=[]
|
290
|
+
if not atp_list==[] and not atp_list==['']:
|
291
|
+
import pandas as pd
|
292
|
+
for at in atp_list:
|
293
|
+
pos=atp_list.index(at)
|
294
|
+
color=atp_color_list[pos]
|
295
|
+
|
296
|
+
#判断是否日期字符串
|
297
|
+
try:
|
298
|
+
atpd=pd.to_datetime(at)
|
299
|
+
except:
|
300
|
+
atpd=at
|
301
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
302
|
+
|
258
303
|
if average_value:
|
259
304
|
av=df[colname].mean()
|
260
305
|
plt.axhline(y=av,ls="dashed",c="blueviolet",linewidth=2,label=text_lang("均值","Mean"))
|
@@ -300,6 +345,7 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
|
|
300
345
|
plt.xlabel(footnote,fontsize=xlabel_txt_size,ha='center')
|
301
346
|
plt.title(titletxt,fontweight='bold',fontsize=title_txt_size)
|
302
347
|
|
348
|
+
plt.legend()
|
303
349
|
plt.show()
|
304
350
|
plt.close()
|
305
351
|
|
@@ -322,7 +368,8 @@ def plot_line2(df1,ticker1,colname1,label1, \
|
|
322
368
|
df2,ticker2,colname2,label2, \
|
323
369
|
ylabeltxt,titletxt,footnote, \
|
324
370
|
power=0,datatag1=False,datatag2=False,yscalemax=5, \
|
325
|
-
zeroline=False,twinx=False,
|
371
|
+
zeroline=False,twinx=False, \
|
372
|
+
yline=999,xline=999, \
|
326
373
|
resample_freq='H',loc1='best',loc2='best', \
|
327
374
|
color1='red',color2='blue',facecolor='whitesmoke'):
|
328
375
|
"""
|
@@ -336,6 +383,8 @@ def plot_line2(df1,ticker1,colname1,label1, \
|
|
336
383
|
返回值:无
|
337
384
|
注意:需要日期类型作为df索引
|
338
385
|
"""
|
386
|
+
DEBUG=False
|
387
|
+
|
339
388
|
#空值判断
|
340
389
|
if len(df1) ==0:
|
341
390
|
print (" #Warning(plot_line2): no data to plot df1.")
|
@@ -344,11 +393,16 @@ def plot_line2(df1,ticker1,colname1,label1, \
|
|
344
393
|
if (len(df1) ==0) and (len(df2) ==0):
|
345
394
|
return
|
346
395
|
|
396
|
+
if DEBUG:
|
397
|
+
print("In plot_line2")
|
398
|
+
print("Going to plot_line2_coaxial")
|
399
|
+
print("yline=",yline,"; xline=",xline)
|
400
|
+
|
347
401
|
if not twinx:
|
348
402
|
plot_line2_coaxial(df1,ticker1,colname1,label1, \
|
349
403
|
df2,ticker2,colname2,label2, \
|
350
404
|
ylabeltxt,titletxt,footnote,power,datatag1,datatag2,zeroline, \
|
351
|
-
yline,xline,resample_freq=resample_freq, \
|
405
|
+
yline=yline,xline=xline,resample_freq=resample_freq, \
|
352
406
|
loc1=loc1,loc2=loc2, \
|
353
407
|
color1=color1,color2=color2,facecolor=facecolor)
|
354
408
|
else:
|
@@ -356,6 +410,7 @@ def plot_line2(df1,ticker1,colname1,label1, \
|
|
356
410
|
df2,ticker2,colname2,label2, \
|
357
411
|
titletxt,footnote,power,datatag1,datatag2, \
|
358
412
|
resample_freq=resample_freq, \
|
413
|
+
xline=xline, \
|
359
414
|
loc1=loc1,loc2=loc2, \
|
360
415
|
color1=color1,color2=color2,facecolor=facecolor)
|
361
416
|
return
|
@@ -440,6 +495,7 @@ def plot_line2_coaxial(df01,ticker1,colname1,label1, \
|
|
440
495
|
返回值:无
|
441
496
|
注意:需要日期类型作为df索引
|
442
497
|
"""
|
498
|
+
DEBUG=False
|
443
499
|
|
444
500
|
#插值平滑
|
445
501
|
try:
|
@@ -487,13 +543,61 @@ def plot_line2_coaxial(df01,ticker1,colname1,label1, \
|
|
487
543
|
if zeroline:
|
488
544
|
plt.axhline(y=0,ls=":",c="black",linewidth=2)
|
489
545
|
|
546
|
+
if DEBUG:
|
547
|
+
print("In plot_line2_coaxial:")
|
548
|
+
print("yline=",yline,"; xline=",xline)
|
549
|
+
|
490
550
|
#是否绘制水平线
|
491
551
|
if yline != 999:
|
492
|
-
|
552
|
+
attention_value=yline
|
553
|
+
|
554
|
+
#用于关注值的颜色列表
|
555
|
+
atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
|
556
|
+
|
557
|
+
if isinstance(attention_value,int) or isinstance(attention_value,float):
|
558
|
+
atv_list=[attention_value]
|
559
|
+
elif isinstance(attention_value,list):
|
560
|
+
atv_list=attention_value
|
561
|
+
else:
|
562
|
+
atv_list=[]
|
563
|
+
|
564
|
+
if DEBUG:
|
565
|
+
print("atv_list=",atv_list)
|
566
|
+
|
567
|
+
if not atv_list==[] and not atv_list==['']:
|
568
|
+
for at in atv_list:
|
569
|
+
pos=atv_list.index(at)
|
570
|
+
color=atv_color_list[pos]
|
571
|
+
plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
|
493
572
|
|
494
573
|
#是否绘制垂直线
|
495
574
|
if xline != 999:
|
496
|
-
|
575
|
+
attention_point=xline
|
576
|
+
#用于关注点的颜色列表
|
577
|
+
atp_color_list=["slateblue","thistle","lightsteelblue","lightcyan","beige"]
|
578
|
+
|
579
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
580
|
+
atp_list=[attention_point]
|
581
|
+
elif isinstance(attention_point,list):
|
582
|
+
atp_list=attention_point
|
583
|
+
else:
|
584
|
+
atp_list=[]
|
585
|
+
if not atp_list==[] and not atp_list==['']:
|
586
|
+
import pandas as pd
|
587
|
+
for at in atp_list:
|
588
|
+
pos=atp_list.index(at)
|
589
|
+
color=atp_color_list[pos]
|
590
|
+
|
591
|
+
#判断是否日期字符串
|
592
|
+
try:
|
593
|
+
atpd=pd.to_datetime(at)
|
594
|
+
except:
|
595
|
+
atpd=at
|
596
|
+
|
597
|
+
if DEBUG:
|
598
|
+
print("atpd=",atpd)
|
599
|
+
|
600
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
497
601
|
|
498
602
|
#绘证券1:制趋势线
|
499
603
|
if power > 0:
|
@@ -769,7 +873,9 @@ def plot_line2_coaxial2(df01,ticker1,colname1,label1, \
|
|
769
873
|
def plot_line2_twinx(df01,ticker1,colname1,label1, \
|
770
874
|
df02,ticker2,colname2,label2, \
|
771
875
|
titletxt,footnote,power=0,datatag1=False,datatag2=False, \
|
772
|
-
resample_freq='H',
|
876
|
+
resample_freq='H', \
|
877
|
+
xline=999, \
|
878
|
+
loc1='upper left',loc2='lower left', \
|
773
879
|
color1='red',color2='blue',facecolor='whitesmoke', \
|
774
880
|
ticker_type='auto'):
|
775
881
|
"""
|
@@ -783,6 +889,8 @@ def plot_line2_twinx(df01,ticker1,colname1,label1, \
|
|
783
889
|
返回值:无
|
784
890
|
注意:需要日期类型作为df索引
|
785
891
|
"""
|
892
|
+
DEBUG=False
|
893
|
+
|
786
894
|
#plt.rcParams['axes.grid']=False
|
787
895
|
|
788
896
|
#插值平滑
|
@@ -825,6 +933,37 @@ def plot_line2_twinx(df01,ticker1,colname1,label1, \
|
|
825
933
|
for x, y in zip(df1.index, df1[colname1]):
|
826
934
|
ax.text(x,y+0.1,'%.2f' % y,ha='center',va='bottom',color='black')
|
827
935
|
|
936
|
+
#绘制关注点
|
937
|
+
if xline != 999:
|
938
|
+
attention_point=xline
|
939
|
+
|
940
|
+
#用于关注点的颜色列表
|
941
|
+
atp_color_list=["slateblue","thistle","lightsteelblue","lightcyan","beige"]
|
942
|
+
|
943
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
944
|
+
atp_list=[attention_point]
|
945
|
+
elif isinstance(attention_point,list):
|
946
|
+
atp_list=attention_point
|
947
|
+
else:
|
948
|
+
atp_list=[]
|
949
|
+
|
950
|
+
if DEBUG:
|
951
|
+
print("In plot_line2_twinx")
|
952
|
+
print("atp_list=",atp_list)
|
953
|
+
|
954
|
+
if not atp_list==[] and not atp_list==['']:
|
955
|
+
import pandas as pd
|
956
|
+
for at in atp_list:
|
957
|
+
pos=atp_list.index(at)
|
958
|
+
color=atp_color_list[pos]
|
959
|
+
|
960
|
+
#判断是否日期字符串
|
961
|
+
try:
|
962
|
+
atpd=pd.to_datetime(at)
|
963
|
+
except:
|
964
|
+
atpd=at
|
965
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
966
|
+
|
828
967
|
#绘证券1:制趋势线
|
829
968
|
if power > 0:
|
830
969
|
lang=check_language()
|
@@ -1117,6 +1256,8 @@ def plot_line2_twinx2(df01,ticker1,colname1,label1, \
|
|
1117
1256
|
def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
1118
1257
|
data_label=True,resample_freq='H',smooth=True,linewidth=1.5, \
|
1119
1258
|
loc='best',annotate=False,annotate_value=False,plus_sign=False, \
|
1259
|
+
attention_value='', \
|
1260
|
+
attention_point='', \
|
1120
1261
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
1121
1262
|
ticker_type='auto',facecolor='whitesmoke'):
|
1122
1263
|
"""
|
@@ -1229,7 +1370,15 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1229
1370
|
#plt.plot(dfg,label=codetranslate(c),linewidth=linewidth,ls=lsc,marker=mkc,markersize=3)
|
1230
1371
|
plt.plot(dfg,label=c,linewidth=lwadjust,ls=lsc,marker=mkc,markersize=3)
|
1231
1372
|
"""
|
1232
|
-
|
1373
|
+
if not annotate or c in ["平均值","中位数"]:
|
1374
|
+
if c in ["平均值","中位数"]:
|
1375
|
+
clabel=c+str(round(dfg[c].values[0],2))
|
1376
|
+
else:
|
1377
|
+
clabel=c
|
1378
|
+
plt.plot(dfg,label=clabel,linewidth=lwadjust,ls=lsc,marker=mkc,markersize=3)
|
1379
|
+
else:
|
1380
|
+
plt.plot(dfg,linewidth=lwadjust,ls=lsc,marker=mkc,markersize=3)
|
1381
|
+
|
1233
1382
|
lines = plt.gca().lines
|
1234
1383
|
last_line_color = lines[-1].get_color()
|
1235
1384
|
|
@@ -1303,6 +1452,63 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1303
1452
|
xytext=(x_end, y_end),fontsize=annotate_size,
|
1304
1453
|
color=last_line_color)
|
1305
1454
|
|
1455
|
+
#用于关注值的颜色列表
|
1456
|
+
atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
|
1457
|
+
#用于关注点的颜色列表
|
1458
|
+
atp_color_list=["slateblue","thistle","lightsteelblue","lightcyan","beige"]
|
1459
|
+
|
1460
|
+
if not attention_value=='':
|
1461
|
+
if isinstance(attention_value,int) or isinstance(attention_value,float):
|
1462
|
+
atv_list=[attention_value]
|
1463
|
+
elif isinstance(attention_value,list):
|
1464
|
+
atv_list=attention_value
|
1465
|
+
else:
|
1466
|
+
atv_list=[]
|
1467
|
+
if not atv_list==[] and not atv_list==['']:
|
1468
|
+
for at in atv_list:
|
1469
|
+
pos=atv_list.index(at)
|
1470
|
+
color=atv_color_list[pos]
|
1471
|
+
plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
|
1472
|
+
|
1473
|
+
if not attention_point=='':
|
1474
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
1475
|
+
atp_list=[attention_point]
|
1476
|
+
elif isinstance(attention_point,list):
|
1477
|
+
atp_list=attention_point
|
1478
|
+
else:
|
1479
|
+
atp_list=[]
|
1480
|
+
if not atp_list==[] and not atp_list==['']:
|
1481
|
+
import pandas as pd
|
1482
|
+
for at in atp_list:
|
1483
|
+
pos=atp_list.index(at)
|
1484
|
+
color=atp_color_list[pos]
|
1485
|
+
|
1486
|
+
#判断是否日期字符串
|
1487
|
+
try:
|
1488
|
+
atpd=pd.to_datetime(at)
|
1489
|
+
except:
|
1490
|
+
atpd=at
|
1491
|
+
|
1492
|
+
"""
|
1493
|
+
#纵轴最小值
|
1494
|
+
yaxis_min=plt.ylim()[0]
|
1495
|
+
arrow_dx=0
|
1496
|
+
#各曲线在关注点的最大值
|
1497
|
+
point_max=dfg.loc[atpd].max()
|
1498
|
+
arrow_dy=point_max - yaxis_min
|
1499
|
+
|
1500
|
+
if DEBUG:
|
1501
|
+
print("*** In draw_lines:")
|
1502
|
+
print("dfg.loc[atpd]",dfg.loc[atpd].values)
|
1503
|
+
print("yaxis_min=",yaxis_min)
|
1504
|
+
print("point_max=",point_max)
|
1505
|
+
print("arrow_dy=",arrow_dy)
|
1506
|
+
|
1507
|
+
plt.arrow(atpd,yaxis_min,arrow_dx,arrow_dy,ls=':',lw=2,fc=color,ec=color,alpha=0.5,shape='full', \
|
1508
|
+
width=0.05,length_includes_head=True)
|
1509
|
+
"""
|
1510
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
1511
|
+
|
1306
1512
|
#绘制水平辅助线
|
1307
1513
|
if axhline_label !="":
|
1308
1514
|
if '零线' in axhline_label:
|
@@ -1328,8 +1534,8 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1328
1534
|
plt.gca().set_facecolor("whitesmoke")
|
1329
1535
|
|
1330
1536
|
# 若不绘制annotate,则绘制图例
|
1331
|
-
if not annotate:
|
1332
|
-
|
1537
|
+
#if not annotate:
|
1538
|
+
plt.legend(loc=loc,fontsize=legend_txt_size)
|
1333
1539
|
|
1334
1540
|
if plus_sign:
|
1335
1541
|
# 尝试改变纵轴刻度格式:给正数添加正号+,以便突出显示增减幅度
|
@@ -1352,7 +1558,10 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1352
1558
|
data_label=False,resample_freq='6H',smooth=True, \
|
1353
1559
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
1354
1560
|
colorlist=[],lslist=[],lwlist=[], \
|
1355
|
-
band_area='',loc='best',
|
1561
|
+
band_area='',loc='best', \
|
1562
|
+
attention_value='', \
|
1563
|
+
attention_point='', \
|
1564
|
+
annotate=False,annotate_value=False, \
|
1356
1565
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
1357
1566
|
facecolor='whitesmoke'):
|
1358
1567
|
"""
|
@@ -1444,11 +1653,20 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1444
1653
|
llw=linewidth_adjust(df)
|
1445
1654
|
|
1446
1655
|
if (lcolor !='') and (lls !=''):
|
1447
|
-
|
1656
|
+
if not annotate:
|
1657
|
+
plt.plot(df[c],label=c,linewidth=llw,ls=lls,color=lcolor)
|
1658
|
+
else:
|
1659
|
+
plt.plot(df[c],linewidth=llw,ls=lls,color=lcolor)
|
1448
1660
|
elif (lcolor !=''):
|
1449
|
-
|
1661
|
+
if not annotate:
|
1662
|
+
plt.plot(df[c],label=c,linewidth=llw,color=lcolor)
|
1663
|
+
else:
|
1664
|
+
plt.plot(df[c],linewidth=llw,color=lcolor)
|
1450
1665
|
else:
|
1451
|
-
|
1666
|
+
if not annotate:
|
1667
|
+
plt.plot(df[c],label=c,linewidth=llw)
|
1668
|
+
else:
|
1669
|
+
plt.plot(df[c],linewidth=llw)
|
1452
1670
|
|
1453
1671
|
lines = plt.gca().lines; last_line_color = lines[-1].get_color()
|
1454
1672
|
|
@@ -1551,6 +1769,44 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1551
1769
|
plt.axhline(y=axhline_value,color='black',linestyle='--',linewidth=2)
|
1552
1770
|
else:
|
1553
1771
|
plt.axhline(y=axhline_value,label=axhline_label,color='black',linestyle='--',linewidth=2)
|
1772
|
+
|
1773
|
+
#用于关注值的颜色列表
|
1774
|
+
atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
|
1775
|
+
#用于关注点的颜色列表
|
1776
|
+
atp_color_list=["slateblue","thistle","lightsteelblue","lightcyan","beige"]
|
1777
|
+
|
1778
|
+
if not attention_value=='':
|
1779
|
+
if isinstance(attention_value,int) or isinstance(attention_value,float):
|
1780
|
+
atv_list=[attention_value]
|
1781
|
+
elif isinstance(attention_value,list):
|
1782
|
+
atv_list=attention_value
|
1783
|
+
else:
|
1784
|
+
atv_list=[]
|
1785
|
+
if not atv_list==[] and not atv_list==['']:
|
1786
|
+
for at in atv_list:
|
1787
|
+
pos=atv_list.index(at)
|
1788
|
+
color=atv_color_list[pos]
|
1789
|
+
plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
|
1790
|
+
|
1791
|
+
if not attention_point=='':
|
1792
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
1793
|
+
atp_list=[attention_point]
|
1794
|
+
elif isinstance(attention_point,list):
|
1795
|
+
atp_list=attention_point
|
1796
|
+
else:
|
1797
|
+
atp_list=[]
|
1798
|
+
if not atp_list==[] and not atp_list==['']:
|
1799
|
+
import pandas as pd
|
1800
|
+
for at in atp_list:
|
1801
|
+
pos=atp_list.index(at)
|
1802
|
+
color=atp_color_list[pos]
|
1803
|
+
|
1804
|
+
#判断是否日期字符串
|
1805
|
+
try:
|
1806
|
+
atpd=pd.to_datetime(at)
|
1807
|
+
except:
|
1808
|
+
atpd=at
|
1809
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
1554
1810
|
|
1555
1811
|
#坐标轴标记
|
1556
1812
|
plt.ylabel(y_label,fontweight='bold',fontsize=ylabel_txt_size)
|
@@ -1565,8 +1821,8 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1565
1821
|
print(" #Warning(draw_lines2): color",facecolor,"is unsupported, changed to default setting")
|
1566
1822
|
plt.gca().set_facecolor("whitesmoke")
|
1567
1823
|
|
1568
|
-
if not annotate:
|
1569
|
-
|
1824
|
+
#if not annotate:
|
1825
|
+
plt.legend(loc=loc,fontsize=legend_txt_size)
|
1570
1826
|
|
1571
1827
|
#设置绘图风格:关闭网格虚线
|
1572
1828
|
plt.rcParams['axes.grid']=False
|
siat/option_china.py
CHANGED
@@ -2457,7 +2457,7 @@ def fin_option_maturity_risk_sse(option,exercise,trade_date, \
|
|
2457
2457
|
#label2=measure
|
2458
2458
|
#ylabeltxt="风险指标"
|
2459
2459
|
ylabeltxt=ectranslate(measure)
|
2460
|
-
titletxt='希腊值风险趋势:'+option+'
|
2460
|
+
titletxt='希腊值风险趋势:'+option+'期权,到期期限对'+ylabeltxt+"的影响"
|
2461
2461
|
|
2462
2462
|
footnote0="到期时间(不同期权)\n"
|
2463
2463
|
footnote1=option+"期权"+",行权股指点位"+str(exercise)+",交易日"+trade_date
|