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/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
|
@@ -4972,6 +4972,33 @@ if __name__ == '__main__':
|
|
4972
4972
|
#await jupyter2pdf2(notebook_dir, notebook_file)
|
4973
4973
|
# 注意:上面的await命令会导致编译失败,测试后要注释掉
|
4974
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
|
4975
5002
|
#==============================================================================
|
4976
5003
|
#==============================================================================
|
4977
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)+"次)"
|
siat/economy2.py
CHANGED
@@ -53,7 +53,7 @@ def find_economic_indicator(key_words='GDP',top=10, \
|
|
53
53
|
def indicator_wb(key_words='GDP',top=20,note=False,translate=False):
|
54
54
|
"""
|
55
55
|
============================================================================
|
56
|
-
|
56
|
+
功能:在WB/IMF/FRED数据库中查找宏观经济指标的代码
|
57
57
|
参数:
|
58
58
|
key_words:可包括多个关键词,使用空格隔开,不区分大小写
|
59
59
|
top:输出相似度最高的,默认5个
|
@@ -73,7 +73,7 @@ def indicator_wb(key_words='GDP',top=20,note=False,translate=False):
|
|
73
73
|
try:
|
74
74
|
df_tmp=wb.search(word)
|
75
75
|
except:
|
76
|
-
print(" Sorry,
|
76
|
+
print(" Sorry, data source rejected connection, try again later")
|
77
77
|
return None
|
78
78
|
|
79
79
|
# 合并
|
@@ -94,6 +94,10 @@ def indicator_wb(key_words='GDP',top=20,note=False,translate=False):
|
|
94
94
|
df2=fuzzy_search_wb(df,key_words=key_words,column='name2',top=top)
|
95
95
|
|
96
96
|
# 遍历输出
|
97
|
+
if len(df2)==0:
|
98
|
+
print(f"Sorry, no indicator found with key words: {key_words}")
|
99
|
+
return None
|
100
|
+
|
97
101
|
#print('') #空一行
|
98
102
|
for row in df2.itertuples():
|
99
103
|
|
@@ -189,6 +193,50 @@ def indicator_name_wb(indicator='NY.GDP.MKTP.KN'):
|
|
189
193
|
return indicator_name
|
190
194
|
|
191
195
|
|
196
|
+
#==============================================================================
|
197
|
+
if __name__ =="__main__":
|
198
|
+
ticker='CN'; show_name=True
|
199
|
+
check_country_code('ZWE',show_name=True)
|
200
|
+
check_country_code('ZAF',show_name=True)
|
201
|
+
check_country_code('cn',show_name=True)
|
202
|
+
|
203
|
+
def check_country_code(ticker='CN',show_name=False):
|
204
|
+
"""
|
205
|
+
===========================================================================
|
206
|
+
功能:检查国家代码是否支持
|
207
|
+
ticker:国家代码
|
208
|
+
show_name:是否显示国家名称,默认否False
|
209
|
+
|
210
|
+
返回值:若国家代码在列表中,True;否则,False
|
211
|
+
"""
|
212
|
+
country_codes=wb.country_codes
|
213
|
+
|
214
|
+
elements_to_remove = ['all','ALL','All']
|
215
|
+
country_code_list = [x for x in country_codes if x not in elements_to_remove]
|
216
|
+
|
217
|
+
result=False
|
218
|
+
if ticker in country_code_list:
|
219
|
+
result=True
|
220
|
+
|
221
|
+
if show_name:
|
222
|
+
if result:
|
223
|
+
indicator='NY.GDP.MKTP.KN'
|
224
|
+
df=economy_indicator_wb(ticker=ticker,indicator=indicator, \
|
225
|
+
start='2000',graph=False)
|
226
|
+
if not (df is None):
|
227
|
+
if len(df) >= 1:
|
228
|
+
country_name=df['country'].values[0]
|
229
|
+
print(f"Country code {ticker} refers to {country_name}")
|
230
|
+
else:
|
231
|
+
print(f"Country code {ticker} found, but its name not found")
|
232
|
+
else:
|
233
|
+
print(f"Found country code {ticker}, but its name not found")
|
234
|
+
else:
|
235
|
+
print(f"Country code {ticker} not found")
|
236
|
+
|
237
|
+
return result
|
238
|
+
|
239
|
+
|
192
240
|
#==============================================================================
|
193
241
|
if __name__ =="__main__":
|
194
242
|
ticker='CN'
|
@@ -318,7 +366,7 @@ def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
|
|
318
366
|
titletxt=titletxt+', '+unit
|
319
367
|
|
320
368
|
import datetime; todaydt = datetime.date.today()
|
321
|
-
sourcetxt=text_lang("
|
369
|
+
sourcetxt=text_lang("数据来源:WB/IMF/FRED","Data source: World Bank")
|
322
370
|
footnote=sourcetxt+', '+str(todaydt)
|
323
371
|
collabel=indicator_name
|
324
372
|
|
@@ -486,7 +534,7 @@ def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.
|
|
486
534
|
|
487
535
|
y_label=text_lang('经济指标',"Economic Indicator")
|
488
536
|
import datetime; todaydt = datetime.date.today()
|
489
|
-
footnote2=text_lang("
|
537
|
+
footnote2=text_lang("数据来源:WB/IMF/FRED","Data source: World Bank")+', '+str(todaydt)
|
490
538
|
|
491
539
|
one_unit=False
|
492
540
|
if len(set(unit_list)) == 1: one_unit=True
|
@@ -696,7 +744,7 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
|
|
696
744
|
y_label=indicator_name
|
697
745
|
|
698
746
|
import datetime; todaydt = datetime.date.today()
|
699
|
-
footnote2=text_lang("
|
747
|
+
footnote2=text_lang("数据来源:WB/IMF/FRED","Data source: World Bank")+', '+str(todaydt)
|
700
748
|
|
701
749
|
one_unit=False
|
702
750
|
if len(set(unit_list)) == 1: one_unit=True
|
@@ -721,7 +769,7 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
|
|
721
769
|
axhline_value=0
|
722
770
|
axhline_label="零线"
|
723
771
|
else:
|
724
|
-
if one_unit and unit != '':
|
772
|
+
if one_unit and unit != '' and preprocess == 'none':
|
725
773
|
titletxt=titletxt+', '+unit
|
726
774
|
|
727
775
|
# 为避免出错,对空值进行插值
|
@@ -760,7 +808,8 @@ def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
|
|
760
808
|
attention_point=attention_point,attention_point_area=attention_point_area, \
|
761
809
|
annotate=annotate,annotate_value=annotate_value,plus_sign=plus_sign, \
|
762
810
|
mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end,facecolor=facecolor, \
|
763
|
-
maxticks=
|
811
|
+
maxticks_enable=False,maxticks=10, \
|
812
|
+
translate=translate)
|
764
813
|
|
765
814
|
return dfs2
|
766
815
|
|
@@ -789,7 +838,7 @@ def economy_trend2(ticker='CN',indicator='NY.GDP.MKTP.KN', \
|
|
789
838
|
"""
|
790
839
|
功能:分析宏观经济指标,支持单国家单指标、多国家单指标、单国家多指标
|
791
840
|
主要公共参数:
|
792
|
-
ticker
|
841
|
+
ticker:国家编码,两位或三位ISO编码,默认'CN'
|
793
842
|
indicator:宏观经济指标,默认GDP (constant LCU),即本币不变价格GDP
|
794
843
|
start:开始日期,默认近十年
|
795
844
|
end:结束日期,默认当前日期
|
@@ -831,8 +880,22 @@ def economy_trend2(ticker='CN',indicator='NY.GDP.MKTP.KN', \
|
|
831
880
|
"""
|
832
881
|
# 判断ticker个数
|
833
882
|
ticker_num=0
|
834
|
-
if isinstance(ticker,str):
|
883
|
+
if isinstance(ticker,str):
|
884
|
+
ticker_num=1
|
885
|
+
ticker=ticker.upper()
|
886
|
+
if not check_country_code(ticker=ticker,show_name=False):
|
887
|
+
print(f" #Warning(economy_trend2): country code {ticker} not found")
|
888
|
+
return None
|
889
|
+
|
835
890
|
if isinstance(ticker,list):
|
891
|
+
ticker=[x.upper() for x in ticker]
|
892
|
+
for t in ticker:
|
893
|
+
if not check_country_code(ticker=t,show_name=False):
|
894
|
+
ticker.remove(t)
|
895
|
+
print(f" #Warning(economy_trend2): country code {t} not found")
|
896
|
+
if len(ticker)==0:
|
897
|
+
return None
|
898
|
+
|
836
899
|
if len(ticker)==1:
|
837
900
|
ticker_num=1
|
838
901
|
ticker=ticker[0]
|
siat/financials.py
CHANGED
@@ -24,7 +24,8 @@ from siat.grafix import *
|
|
24
24
|
#==============================================================================
|
25
25
|
import matplotlib.pyplot as plt
|
26
26
|
|
27
|
-
plt.rcParams['figure.figsize']=(12.8,7.2)
|
27
|
+
#plt.rcParams['figure.figsize']=(12.8,7.2)
|
28
|
+
plt.rcParams['figure.figsize']=(12.8,6.4)
|
28
29
|
plt.rcParams['figure.dpi']=300
|
29
30
|
plt.rcParams['font.size'] = 13
|
30
31
|
plt.rcParams['xtick.labelsize']=11 #横轴字体大小
|
@@ -1936,7 +1937,8 @@ def compare_dupont(tickerlist,fsdate='latest',scale1 = 10,scale2 = 10,hatchlist=
|
|
1936
1937
|
code=df.loc[i,'公司']
|
1937
1938
|
df.loc[i,'公司']=ticker_name(code)
|
1938
1939
|
|
1939
|
-
f,ax1 = plt.subplots(1,figsize=(10,5))
|
1940
|
+
#f,ax1 = plt.subplots(1,figsize=(10,5))
|
1941
|
+
f,ax1 = plt.subplots(1,figsize=(12.8,6.4))
|
1940
1942
|
w = 0.75
|
1941
1943
|
x = [i+1 for i in range(len(df[name1]))]
|
1942
1944
|
#tick_pos = [i+(w/2.) for i in x]
|
siat/financials2.py
CHANGED
@@ -26,7 +26,8 @@ from siat.grafix import *
|
|
26
26
|
#==============================================================================
|
27
27
|
import matplotlib.pyplot as plt
|
28
28
|
|
29
|
-
plt.rcParams['figure.figsize']=(12.8,7.2)
|
29
|
+
#plt.rcParams['figure.figsize']=(12.8,7.2)
|
30
|
+
plt.rcParams['figure.figsize']=(12.8,6.4)
|
30
31
|
plt.rcParams['figure.dpi']=300
|
31
32
|
plt.rcParams['font.size'] = 13
|
32
33
|
plt.rcParams['xtick.labelsize']=11 #横轴字体大小
|
@@ -1009,7 +1010,8 @@ def fs_analysis(tickers,fsdates=[],analysis_type='balance sheet', \
|
|
1009
1010
|
|
1010
1011
|
fin_period=df2['endDate'].values[0]
|
1011
1012
|
|
1012
|
-
f,ax1 = plt.subplots(1,figsize=(10,5))
|
1013
|
+
#f,ax1 = plt.subplots(1,figsize=(10,5))
|
1014
|
+
f,ax1 = plt.subplots(1,figsize=(12.8,6.4))
|
1013
1015
|
w = 0.75
|
1014
1016
|
x = [i+1 for i in range(len(df2[name1]))]
|
1015
1017
|
tick_pos = [i for i in x]
|
siat/financials_china.py
CHANGED
@@ -770,7 +770,8 @@ def compare_dupont_china(tickerlist,fsdate='latest',scale1 = 10,scale2 = 10, \
|
|
770
770
|
code=df.loc[i,'公司']
|
771
771
|
df.loc[i,'公司']=ticker_name(code,'stock').replace("(A股)",'')
|
772
772
|
|
773
|
-
f,ax1 = plt.subplots(1,figsize=(10,5))
|
773
|
+
#f,ax1 = plt.subplots(1,figsize=(10,5))
|
774
|
+
f,ax1 = plt.subplots(1,figsize=(12.8,6.4))
|
774
775
|
w = 0.75
|
775
776
|
x = [i+1 for i in range(len(df[name1]))]
|
776
777
|
#tick_pos = [i+(w/2.) for i in x]
|