siat 3.7.28__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/__init__.py +27 -5
- siat/allin.py +2 -0
- 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 +57 -12
- siat/cryptocurrency.py +6 -3
- siat/economy2.py +977 -0
- 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 +185 -50
- 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 +62 -28
- siat/security_trend2.py +10 -2
- siat/stock.py +18 -5
- siat/stock_profile.py +2 -1
- siat/stock_technical.py +2 -1
- siat/translate.py +280 -5
- {siat-3.7.28.dist-info → siat-3.8.10.dist-info}/METADATA +2 -10
- {siat-3.7.28.dist-info → siat-3.8.10.dist-info}/RECORD +35 -34
- {siat-3.7.28.dist-info → siat-3.8.10.dist-info}/WHEEL +1 -1
- {siat-3.7.28.dist-info → siat-3.8.10.dist-info}/LICENSE +0 -0
- {siat-3.7.28.dist-info → siat-3.8.10.dist-info}/top_level.txt +0 -0
siat/__init__.py
CHANGED
@@ -19,17 +19,39 @@ current_version=pkg_resources.get_distribution("siat").version
|
|
19
19
|
#==============================================================================
|
20
20
|
# 处理stooq.py修复问题
|
21
21
|
restart=False
|
22
|
+
tagfile='fix_package.pkl'
|
23
|
+
|
24
|
+
#判断操作系统
|
25
|
+
import sys; czxt=sys.platform
|
26
|
+
if czxt in ['win32','win64']:
|
27
|
+
os='windows'
|
28
|
+
elif czxt in ['darwin']: #MacOSX
|
29
|
+
os='mac'
|
30
|
+
elif czxt in ['linux']: #linux
|
31
|
+
os='linux'
|
32
|
+
else:
|
33
|
+
os='windows'
|
34
|
+
|
35
|
+
# 确定标记文件存放地址
|
36
|
+
import pandas
|
37
|
+
srcpath=pandas.__path__[0]
|
38
|
+
if os == 'windows':
|
39
|
+
srcpath1=srcpath.replace("\\",'/')
|
40
|
+
srcfile=srcpath1+'/'+tagfile
|
41
|
+
else:
|
42
|
+
srcpath1=srcpath
|
43
|
+
srcfile=srcpath1+'/'+file
|
44
|
+
|
22
45
|
try:
|
23
|
-
with open(
|
46
|
+
with open(srcfile,'rb') as file:
|
24
47
|
siat_ver=pickle.load(file)
|
25
48
|
if siat_ver != current_version:
|
26
49
|
restart=True
|
27
|
-
with open(
|
50
|
+
with open(srcfile,'wb') as file:
|
28
51
|
pickle.dump(current_version,file)
|
29
|
-
|
30
52
|
except:
|
31
53
|
restart=True
|
32
|
-
with open(
|
54
|
+
with open(srcfile,'wb') as file:
|
33
55
|
pickle.dump(current_version,file)
|
34
56
|
|
35
57
|
#屏蔽函数内print信息输出的类
|
@@ -48,6 +70,6 @@ if not restart:
|
|
48
70
|
else:
|
49
71
|
with HiddenPrints():
|
50
72
|
fix_package()
|
51
|
-
print("Please RESTART Python kernel and run this command again
|
73
|
+
print("Please RESTART Python kernel and run this command again")
|
52
74
|
|
53
75
|
#==============================================================================
|
siat/allin.py
CHANGED
siat/beta_adjustment.py
CHANGED
@@ -727,7 +727,7 @@ def draw_hamada_factors(stkcd,mktidx,betas):
|
|
727
727
|
#计算资产负债率:由 D/E到 D/(A=D+E)
|
728
728
|
betas['Debt/Assets%']=1/(1+1/(betas['Debt Ratio%']/100))*100
|
729
729
|
|
730
|
-
#fig=plt.figure(figsize=(8,6))
|
730
|
+
#fig=plt.figure(figsize=(12.8,6.4))
|
731
731
|
fig=plt.figure()
|
732
732
|
ax1=fig.add_subplot(111)
|
733
733
|
ax1.plot(betas['CFLB%'],marker='o',color='green',lw=3,label='CFLB%')
|
siat/beta_adjustment_china.py
CHANGED
@@ -345,7 +345,7 @@ def draw_hamada_factors_china(stkcd,mktidx,betas):
|
|
345
345
|
#计算资产负债率:由 D/E到 D/(A=D+E)
|
346
346
|
betas['Debt/Assets%']=1/(1+1/(betas['lev ratio']/100))*100
|
347
347
|
|
348
|
-
#fig=plt.figure(figsize=(8,6))
|
348
|
+
#fig=plt.figure(figsize=(12.8,6.4))
|
349
349
|
fig=plt.figure()
|
350
350
|
ax1=fig.add_subplot(111)
|
351
351
|
ax1.plot(betas['CFLB%'],marker='o',color='green',lw=3,label='CFLB%')
|
siat/bond.py
CHANGED
@@ -22,7 +22,8 @@ from siat.bond_base import *
|
|
22
22
|
|
23
23
|
#==============================================================================
|
24
24
|
import matplotlib.pyplot as plt
|
25
|
-
plt.rcParams['figure.figsize']=(12.8,7.2)
|
25
|
+
#plt.rcParams['figure.figsize']=(12.8,7.2)
|
26
|
+
plt.rcParams['figure.figsize']=(12.8,6.4)
|
26
27
|
plt.rcParams['figure.dpi']=300
|
27
28
|
plt.rcParams['font.size'] = 13
|
28
29
|
plt.rcParams['xtick.labelsize']=11 #横轴字体大小
|
@@ -2357,7 +2358,8 @@ def kpmg_rnpm1_rrd(k1,theta,i1, \
|
|
2357
2358
|
df.reset_index(drop=True,inplace=True)
|
2358
2359
|
|
2359
2360
|
#绘图
|
2360
|
-
fig = plt.figure(figsize=(12.8,7.2),dpi=300)
|
2361
|
+
#fig = plt.figure(figsize=(12.8,7.2),dpi=300)
|
2362
|
+
fig = plt.figure(figsize=(12.8,6.4),dpi=300)
|
2361
2363
|
#plt.rcParams['figure.dpi']=300
|
2362
2364
|
|
2363
2365
|
ax = fig.add_subplot(111)
|
siat/bond_base.py
CHANGED
@@ -19,7 +19,8 @@ from siat.common import *
|
|
19
19
|
from siat.translate import *
|
20
20
|
#==============================================================================
|
21
21
|
import matplotlib.pyplot as plt
|
22
|
-
plt.rcParams['figure.figsize']=(12.8,7.2)
|
22
|
+
#plt.rcParams['figure.figsize']=(12.8,7.2)
|
23
|
+
plt.rcParams['figure.figsize']=(12.8,6.4)
|
23
24
|
plt.rcParams['figure.dpi']=300
|
24
25
|
plt.rcParams['font.size'] = 13
|
25
26
|
plt.rcParams['xtick.labelsize']=11 #横轴字体大小
|
siat/bond_china.py
CHANGED
@@ -28,7 +28,8 @@ from siat.security_prices import *
|
|
28
28
|
from siat.security_price2 import *
|
29
29
|
#==============================================================================
|
30
30
|
import matplotlib.pyplot as plt
|
31
|
-
plt.rcParams['figure.figsize']=(12.8,7.2)
|
31
|
+
#plt.rcParams['figure.figsize']=(12.8,7.2)
|
32
|
+
plt.rcParams['figure.figsize']=(12.8,6.4)
|
32
33
|
plt.rcParams['figure.dpi']=300
|
33
34
|
plt.rcParams['font.size'] = 13
|
34
35
|
plt.rcParams['xtick.labelsize']=11 #横轴字体大小
|
siat/capm_beta2.py
CHANGED
@@ -86,7 +86,7 @@ if __name__=='__main__':
|
|
86
86
|
reg_result,dretdf3=regression_capm(ticker,start2,end,RF,regtrddays)
|
87
87
|
|
88
88
|
def regression_capm(ticker,start2,end, \
|
89
|
-
adjust='', \
|
89
|
+
adjust='qfq', \
|
90
90
|
RF=0,regtrddays=252, \
|
91
91
|
mktidx='auto',source='auto',ticker_type='auto'):
|
92
92
|
"""
|
@@ -203,7 +203,7 @@ def regression_capm(ticker,start2,end, \
|
|
203
203
|
return reg_result,dretdf3
|
204
204
|
|
205
205
|
|
206
|
-
def regression_capm_df(marketdf,pricedf,mktidx,adjust='',RF=0,regtrddays=252):
|
206
|
+
def regression_capm_df(marketdf,pricedf,mktidx,adjust='qfq',RF=0,regtrddays=252):
|
207
207
|
"""
|
208
208
|
功能:进行CAPM回归,R-Rf=beta*(Rm-Rf),无截距项回归
|
209
209
|
x为(Rm-Rf),y为R-Rf,均为日收益率,默认回归样本长度一年(365日历日或252交易日)
|
@@ -289,7 +289,7 @@ if __name__=='__main__':
|
|
289
289
|
beta1=get_capm_beta(ticker,start,end,RF,regtrddays)
|
290
290
|
beta1.plot()
|
291
291
|
|
292
|
-
def get_capm_beta(ticker,start,end,adjust='',RF=0,regtrddays=252,mktidx='auto', \
|
292
|
+
def get_capm_beta(ticker,start,end,adjust='qfq',RF=0,regtrddays=252,mktidx='auto', \
|
293
293
|
source='auto',ticker_type='auto'):
|
294
294
|
"""
|
295
295
|
功能:套壳函数regression_capm,仅返回滚动的贝塔系数,基于日收益率
|
@@ -306,7 +306,11 @@ def get_capm_beta(ticker,start,end,adjust='',RF=0,regtrddays=252,mktidx='auto',
|
|
306
306
|
|
307
307
|
startpd=pd.to_datetime(date_adjust(start,adjust=-7))
|
308
308
|
endpd=pd.to_datetime(end)
|
309
|
-
|
309
|
+
|
310
|
+
try:
|
311
|
+
reg_result2=reg_result[(reg_result.index >= startpd) & (reg_result.index <= endpd)]
|
312
|
+
except:
|
313
|
+
print(" #Error(get_capm_beta): none obtained from capm regression")
|
310
314
|
|
311
315
|
return reg_result2
|
312
316
|
|
@@ -335,7 +339,8 @@ def compare_mticker_1beta(ticker,start,end, \
|
|
335
339
|
RF=0,regression_period=365, \
|
336
340
|
attention_value='',attention_value_area='', \
|
337
341
|
attention_point='',attention_point_area='', \
|
338
|
-
axhline_value=1,axhline_label='', \
|
342
|
+
axhline_value=1,axhline_label='零线', \
|
343
|
+
band_area='', \
|
339
344
|
graph=True,facecolor='whitesmoke',loc='best', \
|
340
345
|
annotate=False,annotate_value=False, \
|
341
346
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
@@ -361,7 +366,7 @@ def compare_mticker_1beta(ticker,start,end, \
|
|
361
366
|
RF=RF[0]
|
362
367
|
if isinstance(regression_period,list):
|
363
368
|
regression_period=regression_period[0]
|
364
|
-
print("
|
369
|
+
print(" Working on capm beta, please wait ......")
|
365
370
|
|
366
371
|
#计算日历日regression_period对应的交易日数
|
367
372
|
regtrddays=int(252 / 365 * regression_period)
|
@@ -382,8 +387,17 @@ def compare_mticker_1beta(ticker,start,end, \
|
|
382
387
|
break
|
383
388
|
else:
|
384
389
|
dft=df_tmp[['beta']]
|
385
|
-
|
390
|
+
|
391
|
+
tname=ticker_name(t,tt)
|
392
|
+
dft.rename(columns={'beta':tname},inplace=True)
|
386
393
|
mktidx_name=ticker_name(df_tmp['mktidx'].values[0])
|
394
|
+
|
395
|
+
# 将band_area中的ticker替换为tname
|
396
|
+
if band_area != '':
|
397
|
+
for index, item in enumerate(band_area):
|
398
|
+
if item == t:
|
399
|
+
band_area[index] = tname
|
400
|
+
|
387
401
|
if len(df)==0: #第一个
|
388
402
|
df=dft
|
389
403
|
else:
|
@@ -432,6 +446,7 @@ def compare_mticker_1beta(ticker,start,end, \
|
|
432
446
|
title_txt=title_txt,data_label=False, \
|
433
447
|
attention_value=attention_value,attention_value_area=attention_value_area, \
|
434
448
|
attention_point=attention_point,attention_point_area=attention_point_area, \
|
449
|
+
band_area=band_area, \
|
435
450
|
annotate=annotate,annotate_value=annotate, \
|
436
451
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,
|
437
452
|
facecolor=facecolor,loc=loc)
|
@@ -463,7 +478,8 @@ def compare_1ticker_mRF(ticker,start,end, \
|
|
463
478
|
regression_period=365, \
|
464
479
|
attention_value='',attention_value_area='', \
|
465
480
|
attention_point='',attention_point_area='', \
|
466
|
-
axhline_value=1,axhline_label='', \
|
481
|
+
axhline_value=1,axhline_label='零线', \
|
482
|
+
band_area='', \
|
467
483
|
graph=True,facecolor='whitesmoke',loc='best', \
|
468
484
|
annotate=False,annotate_value=False, \
|
469
485
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
@@ -490,7 +506,7 @@ def compare_1ticker_mRF(ticker,start,end, \
|
|
490
506
|
RF=[RF]
|
491
507
|
if isinstance(regression_period,list):
|
492
508
|
regression_period=regression_period[0]
|
493
|
-
print("
|
509
|
+
print(" Working on capm beta with different RFs, please wait ......")
|
494
510
|
|
495
511
|
#计算日历日regression_period对应的交易日数
|
496
512
|
regtrddays=int(252 / 365 * regression_period)
|
@@ -508,8 +524,17 @@ def compare_1ticker_mRF(ticker,start,end, \
|
|
508
524
|
break
|
509
525
|
else:
|
510
526
|
dft=df_tmp[['beta']]
|
511
|
-
|
527
|
+
|
528
|
+
#tname="基于无风险利率"+str(round(t*100,4))+'%'
|
529
|
+
tname="RF="+str(round(t*100,4))+'%'
|
530
|
+
dft.rename(columns={'beta':tname},inplace=True)
|
512
531
|
mktidx_name=ticker_name(df_tmp['mktidx'].values[0])
|
532
|
+
|
533
|
+
# 将band_area中的ticker替换为tname
|
534
|
+
if band_area != '':
|
535
|
+
for index, item in enumerate(band_area):
|
536
|
+
if item == t:
|
537
|
+
band_area[index] = tname
|
513
538
|
|
514
539
|
if len(df)==0: #第一个
|
515
540
|
df=dft
|
@@ -558,6 +583,7 @@ def compare_1ticker_mRF(ticker,start,end, \
|
|
558
583
|
title_txt=title_txt,data_label=False, \
|
559
584
|
attention_value=attention_value,attention_value_area=attention_value_area, \
|
560
585
|
attention_point=attention_point,attention_point_area=attention_point_area, \
|
586
|
+
band_area=band_area, \
|
561
587
|
annotate=annotate,annotate_value=annotate, \
|
562
588
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
563
589
|
facecolor=facecolor,loc=loc)
|
@@ -587,7 +613,8 @@ def compare_1ticker_mregression_period(ticker,start,end, \
|
|
587
613
|
regression_period=[183,365,730], \
|
588
614
|
attention_value='',attention_value_area='', \
|
589
615
|
attention_point='',attention_point_area='', \
|
590
|
-
axhline_value=1,axhline_label='', \
|
616
|
+
axhline_value=1,axhline_label='零线', \
|
617
|
+
band_area='', \
|
591
618
|
graph=True,facecolor='whitesmoke',loc='best', \
|
592
619
|
annotate=False,annotate_value=False, \
|
593
620
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
@@ -614,7 +641,7 @@ def compare_1ticker_mregression_period(ticker,start,end, \
|
|
614
641
|
RF=RF[0]
|
615
642
|
if isinstance(regression_period,int):
|
616
643
|
regression_period=[regression_period]
|
617
|
-
print("
|
644
|
+
print(" Working on capm beta with different regression periods ......")
|
618
645
|
|
619
646
|
#预处理ticker_type
|
620
647
|
ticker_type=ticker_type_preprocess_mticker_mixed(ticker,ticker_type)
|
@@ -632,8 +659,18 @@ def compare_1ticker_mregression_period(ticker,start,end, \
|
|
632
659
|
break
|
633
660
|
else:
|
634
661
|
dft=df_tmp[['beta']]
|
635
|
-
|
662
|
+
|
663
|
+
#tname="基于"+str(t)+"自然日回归"
|
664
|
+
tname="基于"+str(t)+"自然日回归"
|
665
|
+
dft.rename(columns={'beta':tname},inplace=True)
|
636
666
|
mktidx_name=ticker_name(df_tmp['mktidx'].values[0])
|
667
|
+
|
668
|
+
# 将band_area中的ticker替换为tname
|
669
|
+
if band_area != '':
|
670
|
+
for index, item in enumerate(band_area):
|
671
|
+
if item == t:
|
672
|
+
band_area[index] = tname
|
673
|
+
|
637
674
|
if len(df)==0: #第一个
|
638
675
|
df=dft
|
639
676
|
else:
|
@@ -677,6 +714,7 @@ def compare_1ticker_mregression_period(ticker,start,end, \
|
|
677
714
|
title_txt=title_txt,data_label=False, \
|
678
715
|
attention_value=attention_value,attention_value_area=attention_value_area, \
|
679
716
|
attention_point=attention_point,attention_point_area=attention_point_area, \
|
717
|
+
band_area=band_area, \
|
680
718
|
annotate=annotate,annotate_value=annotate, \
|
681
719
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
682
720
|
facecolor=facecolor,loc=loc)
|
@@ -706,10 +744,11 @@ if __name__=='__main__':
|
|
706
744
|
betas=compare_beta_security(ticker,start,end,RF)
|
707
745
|
|
708
746
|
def compare_beta_security(ticker,start,end, \
|
709
|
-
adjust='', \
|
747
|
+
adjust='qfq', \
|
710
748
|
RF=0,regression_period=365, \
|
711
749
|
attention_value='',attention_value_area='', \
|
712
750
|
attention_point='',attention_point_area='', \
|
751
|
+
band_area='', \
|
713
752
|
graph=True,facecolor='whitesmoke', \
|
714
753
|
annotate=False,annotate_value=False, \
|
715
754
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
@@ -731,6 +770,7 @@ def compare_beta_security(ticker,start,end, \
|
|
731
770
|
RF=RF,regression_period=regression_period, \
|
732
771
|
attention_value=attention_value,attention_value_area=attention_value_area, \
|
733
772
|
attention_point=attention_point,attention_point_area=attention_point_area, \
|
773
|
+
band_area=band_area, \
|
734
774
|
graph=graph,facecolor=facecolor,loc=loc, \
|
735
775
|
annotate=annotate,annotate_value=annotate, \
|
736
776
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
@@ -749,6 +789,7 @@ def compare_beta_security(ticker,start,end, \
|
|
749
789
|
RF=RF,regression_period=regression_period, \
|
750
790
|
attention_value=attention_value,attention_value_area=attention_value_area, \
|
751
791
|
attention_point=attention_point,attention_point_area=attention_point_area, \
|
792
|
+
band_area=band_area, \
|
752
793
|
graph=graph,facecolor=facecolor,loc=loc, \
|
753
794
|
annotate=annotate,annotate_value=annotate, \
|
754
795
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
@@ -767,6 +808,7 @@ def compare_beta_security(ticker,start,end, \
|
|
767
808
|
RF=RF,regression_period=regression_period, \
|
768
809
|
attention_value=attention_value,attention_value_area=attention_value_area, \
|
769
810
|
attention_point=attention_point,attention_point_area=attention_point_area, \
|
811
|
+
band_area=band_area, \
|
770
812
|
graph=graph,facecolor=facecolor,loc=loc, \
|
771
813
|
annotate=annotate,annotate_value=annotate, \
|
772
814
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
@@ -783,6 +825,7 @@ def compare_beta_security(ticker,start,end, \
|
|
783
825
|
RF=RF,regression_period=regression_period, \
|
784
826
|
attention_value=attention_value,attention_value_area=attention_value_area, \
|
785
827
|
attention_point=attention_point,attention_point_area=attention_point_area, \
|
828
|
+
band_area=band_area, \
|
786
829
|
graph=graph,facecolor=facecolor,loc=loc, \
|
787
830
|
annotate=annotate,annotate_value=annotate, \
|
788
831
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
siat/common.py
CHANGED
@@ -3125,29 +3125,29 @@ def df_preprocess(dfs,measure,axhline_label,x_label,y_label, \
|
|
3125
3125
|
measure_suffix='(change %)'
|
3126
3126
|
else:
|
3127
3127
|
if preprocess1 == 'standardize':
|
3128
|
-
std_notes="
|
3128
|
+
std_notes="注意:为突出变化趋势,对数据进行了标准化处理,非原值"
|
3129
3129
|
measure_suffix='(标准化处理后)'
|
3130
3130
|
if preprocess1 == 'normalize':
|
3131
|
-
std_notes="
|
3131
|
+
std_notes="注意:为突出变化趋势,对数据进行了归一化处理,非原值"
|
3132
3132
|
measure_suffix='(归一化处理后)'
|
3133
3133
|
if preprocess1 == 'logarithm':
|
3134
|
-
std_notes="
|
3134
|
+
std_notes="注意:为突出变化趋势,对数据进行了对数处理,非原值"
|
3135
3135
|
measure_suffix='(对数处理后)'
|
3136
3136
|
if preprocess1 == 'scaling':
|
3137
3137
|
if scaling_option == 'mean':
|
3138
|
-
std_notes="
|
3139
|
-
measure_suffix='(
|
3138
|
+
std_notes="注意:为突出变化趋势,按均值对原始数据进行了比例缩放,非原值"
|
3139
|
+
measure_suffix='(按均值比例缩放后)'
|
3140
3140
|
elif scaling_option == 'min':
|
3141
|
-
std_notes="
|
3142
|
-
measure_suffix='(
|
3141
|
+
std_notes="注意:为突出变化趋势,按最小值对原始数据进行了比例缩放,非原值"
|
3142
|
+
measure_suffix='(按最小值比例缩放后)'
|
3143
3143
|
elif scaling_option == 'start':
|
3144
|
-
std_notes="
|
3145
|
-
measure_suffix='(
|
3144
|
+
std_notes="注意:为突出变化趋势,按起点值对原始数据进行了比例缩放,非原值"
|
3145
|
+
measure_suffix='(按起点值比例缩放后)'
|
3146
3146
|
elif scaling_option == 'percentage':
|
3147
|
-
std_notes="注释:为突出变化趋势,期间起点数值=100
|
3147
|
+
std_notes="注释:为突出变化趋势,期间起点数值=100%,其他数值为相对百分比,非原值"
|
3148
3148
|
measure_suffix='(相对百分数%)'
|
3149
3149
|
elif scaling_option == 'change%':
|
3150
|
-
std_notes="
|
3150
|
+
std_notes="注释:为突出变化趋势,图中数值为相对期间起点的增减百分比,非原值"
|
3151
3151
|
#measure_suffix='(增/减%)'
|
3152
3152
|
measure_suffix='(涨跌幅度%)'
|
3153
3153
|
axhline_label='零线' #可以在security_trend中使用critical_value选项指定水平线位置,默认0
|
@@ -3371,16 +3371,34 @@ def start_end_preprocess(start,end='today'):
|
|
3371
3371
|
fromdate=date_adjust2(todate,adjust_year=-2,to_prev_month_end=True)
|
3372
3372
|
elif start in ['l3y']: # 近三年以来
|
3373
3373
|
fromdate=date_adjust2(todate,adjust_year=-3,to_prev_month_end=True)
|
3374
|
+
elif start in ['l4y']: # 近三年以来
|
3375
|
+
fromdate=date_adjust2(todate,adjust_year=-4,to_prev_month_end=True)
|
3376
|
+
|
3374
3377
|
elif start in ['l5y']: # 近五年以来
|
3375
3378
|
fromdate=date_adjust2(todate,adjust_year=-5,to_prev_year_end=True)
|
3379
|
+
elif start in ['l6y']: # 近五年以来
|
3380
|
+
fromdate=date_adjust2(todate,adjust_year=-6,to_prev_year_end=True)
|
3381
|
+
elif start in ['l7y']: # 近五年以来
|
3382
|
+
fromdate=date_adjust2(todate,adjust_year=-7,to_prev_year_end=True)
|
3383
|
+
|
3376
3384
|
elif start in ['l8y']: # 近八年以来
|
3377
3385
|
fromdate=date_adjust2(todate,adjust_year=-8,to_prev_year_end=True)
|
3378
3386
|
elif start in ['l10y']: # 近十年以来
|
3379
3387
|
fromdate=date_adjust2(todate,adjust_year=-10,to_prev_year_end=True)
|
3380
3388
|
elif start in ['l20y']: # 近20年以来
|
3381
3389
|
fromdate=date_adjust2(todate,adjust_year=-20,to_prev_year_end=True)
|
3390
|
+
elif start in ['l15y']: # 近五年以来
|
3391
|
+
fromdate=date_adjust2(todate,adjust_year=-15,to_prev_year_end=True)
|
3392
|
+
elif start in ['l25y']: # 近五年以来
|
3393
|
+
fromdate=date_adjust2(todate,adjust_year=-25,to_prev_year_end=True)
|
3394
|
+
|
3382
3395
|
elif start in ['l30y']: # 近30年以来
|
3383
|
-
fromdate=date_adjust2(todate,adjust_year=-30,to_prev_year_end=True)
|
3396
|
+
fromdate=date_adjust2(todate,adjust_year=-30,to_prev_year_end=True)
|
3397
|
+
elif start in ['l40y']: # 近五年以来
|
3398
|
+
fromdate=date_adjust2(todate,adjust_year=-40,to_prev_year_end=True)
|
3399
|
+
elif start in ['l50y']: # 近五年以来
|
3400
|
+
fromdate=date_adjust2(todate,adjust_year=-50,to_prev_year_end=True)
|
3401
|
+
|
3384
3402
|
elif start in ['ytd']: # 今年以来
|
3385
3403
|
fromdate=str(todaydt.year-1)+'-12-31'
|
3386
3404
|
else:
|
@@ -4954,6 +4972,33 @@ if __name__ == '__main__':
|
|
4954
4972
|
#await jupyter2pdf2(notebook_dir, notebook_file)
|
4955
4973
|
# 注意:上面的await命令会导致编译失败,测试后要注释掉
|
4956
4974
|
#==============================================================================
|
4975
|
+
if __name__ == '__main__':
|
4976
|
+
df=security_trend("600519.SS",indicator=['Close','Open','High','Low'],graph=False)
|
4977
|
+
col_name='持股总数'; position=3
|
4978
|
+
|
4979
|
+
df=shift_column_position(df,col_name='Low',position=0)
|
4980
|
+
|
4981
|
+
def shift_column_position(df,col_name,position=1):
|
4982
|
+
"""
|
4983
|
+
功能:将df中的字段col_name挪动到位置position,其余字段不动。
|
4984
|
+
注意:位置顺序从0开始。
|
4985
|
+
"""
|
4986
|
+
# 获取所有列名
|
4987
|
+
columns = df.columns.tolist()
|
4988
|
+
if col_name not in columns:
|
4989
|
+
raise ValueError(f" #Warning: column '{col_name}' does not exist in the DataFrame.")
|
4990
|
+
return df
|
4991
|
+
|
4992
|
+
# 移除要移动的列
|
4993
|
+
columns.remove(col_name)
|
4994
|
+
|
4995
|
+
# 插入到指定位置
|
4996
|
+
columns.insert(position, col_name)
|
4997
|
+
|
4998
|
+
# 重新排列 DataFrame
|
4999
|
+
df = df[columns]
|
5000
|
+
|
5001
|
+
return df
|
4957
5002
|
#==============================================================================
|
4958
5003
|
#==============================================================================
|
4959
5004
|
#==============================================================================
|
siat/cryptocurrency.py
CHANGED
@@ -385,7 +385,8 @@ def evalSpread_in2Markets(fsym,tsym,market1,market2,begdate,enddate):
|
|
385
385
|
df12=pd.merge(df1,df2,how='inner',left_index=True,right_index=True)
|
386
386
|
df12['spread']=df12['close_x'] - df12['close_y']
|
387
387
|
|
388
|
-
plt.figure(figsize=(12,6))
|
388
|
+
#plt.figure(figsize=(12,6))
|
389
|
+
plt.figure(figsize=(12.8,6.4))
|
389
390
|
labeltxt=market1+"与"+market2+"的价差"
|
390
391
|
plt.plot(df12.spread, '.-', label=labeltxt)
|
391
392
|
#plt.plot(df2.close, '.-', label=market2)
|
@@ -531,7 +532,8 @@ def eval_Position(market1,market2,investment,ac1,ac2,money):
|
|
531
532
|
|
532
533
|
|
533
534
|
ymax=(round(max(money)/1000)+1)*1000
|
534
|
-
plt.figure(figsize=(18,9))
|
535
|
+
#plt.figure(figsize=(18,9))
|
536
|
+
plt.figure(figsize=(12.8,6.4))
|
535
537
|
# market1的账户ac1变化图
|
536
538
|
plt.subplot(2,3,1)
|
537
539
|
plt.plot(ac1)
|
@@ -564,7 +566,8 @@ def eval_Roi(fsym,tsym,market1,market2,roi,begdate,enddate):
|
|
564
566
|
ymax=round(10*roi[-1])*10+10
|
565
567
|
product=fsym+"/"+tsym+":"
|
566
568
|
mktpair="市场配对("+market1+","+market2+")"
|
567
|
-
plt.figure(figsize=(8,5))
|
569
|
+
#plt.figure(figsize=(8,5))
|
570
|
+
plt.figure(figsize=(12.8,6.4))
|
568
571
|
plt.plot(np.array(roi)*100, 'r')
|
569
572
|
|
570
573
|
footnote1="交易序列(总计"+str(ttltrdnum)+"次)"
|