siat 2.14.2__py3-none-any.whl → 3.0.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/allin.py +1 -0
- siat/assets_liquidity.py +16 -16
- siat/beta_adjustment.py +6 -6
- siat/beta_adjustment_china.py +9 -9
- siat/bond.py +71 -67
- siat/capm_beta.py +11 -11
- siat/capm_beta2.py +49 -23
- siat/common.py +427 -60
- siat/compare_cross.py +15 -82
- siat/exchange_bond_china.pickle +0 -0
- siat/fama_french.py +3 -3
- siat/financials.py +15 -15
- siat/financials2.py +8 -8
- siat/financials_china.py +20 -20
- siat/financials_china2.py +25 -25
- siat/fund_china.pickle +0 -0
- siat/fund_china.py +5 -4
- siat/grafix.py +195 -132
- siat/markowitz.py +6 -5
- siat/option_china.py +1 -1
- siat/option_pricing.py +6 -6
- siat/risk_adjusted_return.py +14 -14
- siat/risk_adjusted_return2.py +64 -42
- siat/risk_evaluation.py +32 -32
- siat/risk_free_rate.py +0 -0
- siat/sector_china.py +3 -195
- siat/security_price2.py +616 -0
- siat/security_prices.py +935 -308
- siat/security_trend2.py +28 -47
- siat/stock.py +225 -437
- siat/stock_china.py +19 -19
- siat/stock_info.pickle +0 -0
- siat/stock_technical.py +547 -144
- siat/transaction.py +3 -3
- siat/translate.py +781 -24
- siat/valuation.py +6 -6
- siat/var_model_validation.py +2 -2
- {siat-2.14.2.dist-info → siat-3.0.1.dist-info}/METADATA +1 -1
- {siat-2.14.2.dist-info → siat-3.0.1.dist-info}/RECORD +41 -40
- {siat-2.14.2.dist-info → siat-3.0.1.dist-info}/WHEEL +0 -0
- {siat-2.14.2.dist-info → siat-3.0.1.dist-info}/top_level.txt +0 -0
siat/capm_beta2.py
CHANGED
@@ -34,7 +34,7 @@ def get_market_index_code(ticker):
|
|
34
34
|
"""
|
35
35
|
功能:基于股票ticker确定其所在市场的大盘指数代码
|
36
36
|
"""
|
37
|
-
|
37
|
+
ticker=ticker1_cvt2yahoo(ticker)
|
38
38
|
_,_,suffix=split_prefix_suffix(ticker.upper())
|
39
39
|
|
40
40
|
if suffix in ['SS']:
|
@@ -86,7 +86,7 @@ if __name__=='__main__':
|
|
86
86
|
reg_result,dretdf3=regression_capm(ticker,start2,end,ret_type,RF,regtrddays)
|
87
87
|
|
88
88
|
def regression_capm(ticker,start2,end,ret_type='Annual Ret%',RF=0,regtrddays=252, \
|
89
|
-
mktidx='auto',source='auto'):
|
89
|
+
mktidx='auto',source='auto',ticker_type='auto'):
|
90
90
|
"""
|
91
91
|
功能:进行CAPM回归,R-Rf=beta*(Rm-Rf),无截距项回归
|
92
92
|
x为(Rm-Rf),y为R-Rf,均为日收益率,默认回归样本长度一年(365日历日或252交易日)
|
@@ -99,9 +99,12 @@ def regression_capm(ticker,start2,end,ret_type='Annual Ret%',RF=0,regtrddays=252
|
|
99
99
|
if DEBUG:
|
100
100
|
print("*** DEBUG:",ticker,start2,end)
|
101
101
|
#pricedf=get_price(ticker,start2,end,source=source)
|
102
|
-
pricedf=get_price_security(ticker,start2,end,source=source)
|
102
|
+
#pricedf=get_price_security(ticker,start2,end,source=source)
|
103
|
+
pricedf,found=get_price_1ticker_mixed(ticker=ticker,fromdate=start2, \
|
104
|
+
todate=end,source=source,ticker_type=ticker_type)
|
105
|
+
|
103
106
|
if pricedf is None:
|
104
|
-
print(" #Error(regression_capm): info of security",ticker_name(ticker),"not found or inaccessible")
|
107
|
+
print(" #Error(regression_capm): info of security",ticker_name(ticker,ticker_type),"not found or inaccessible")
|
105
108
|
return None,None
|
106
109
|
|
107
110
|
#计算股票滚动收益率
|
@@ -120,7 +123,10 @@ def regression_capm(ticker,start2,end,ret_type='Annual Ret%',RF=0,regtrddays=252
|
|
120
123
|
if 'auto' in mktidx.lower():
|
121
124
|
mktidx=get_market_index_code(ticker)
|
122
125
|
|
123
|
-
marketdf=get_price(mktidx,start2,end,source=source)
|
126
|
+
#marketdf=get_price(mktidx,start2,end,source=source)
|
127
|
+
marketdf,found=get_price_1ticker_mixed(ticker=mktidx,fromdate=start2, \
|
128
|
+
todate=end,source=source,ticker_type=ticker_type)
|
129
|
+
|
124
130
|
if marketdf is None:
|
125
131
|
print(" #Error(regression_capm): info of market index",mktidx,"not found or inaccessible")
|
126
132
|
return None,None
|
@@ -203,7 +209,8 @@ if __name__=='__main__':
|
|
203
209
|
beta1=get_capm_beta(ticker,start,end,RF,regtrddays)
|
204
210
|
beta1.plot()
|
205
211
|
|
206
|
-
def get_capm_beta(ticker,start,end,RF=0,regtrddays=252,mktidx='auto',
|
212
|
+
def get_capm_beta(ticker,start,end,RF=0,regtrddays=252,mktidx='auto', \
|
213
|
+
source='auto',ticker_type='auto'):
|
207
214
|
"""
|
208
215
|
功能:套壳函数regression_capm,仅返回滚动的贝塔系数,基于日收益率
|
209
216
|
滚动窗口长度为regtrddays,默认为一年的交易日
|
@@ -213,7 +220,8 @@ def get_capm_beta(ticker,start,end,RF=0,regtrddays=252,mktidx='auto',source='aut
|
|
213
220
|
|
214
221
|
reg_result,_=regression_capm(ticker=ticker,start2=start2,end=end, \
|
215
222
|
ret_type="Annual Ret%",RF=RF, \
|
216
|
-
regtrddays=regtrddays,mktidx=mktidx,
|
223
|
+
regtrddays=regtrddays,mktidx=mktidx, \
|
224
|
+
source=source,ticker_type=ticker_type)
|
217
225
|
|
218
226
|
startpd=pd.to_datetime(date_adjust(start,adjust=-7))
|
219
227
|
endpd=pd.to_datetime(end)
|
@@ -243,7 +251,7 @@ if __name__=='__main__':
|
|
243
251
|
def compare_mticker_1beta(ticker,start,end, \
|
244
252
|
RF=0,regression_period=365, \
|
245
253
|
graph=True,axhline_value=1,axhline_label='', \
|
246
|
-
annotate=False,mktidx='auto',source='auto'):
|
254
|
+
annotate=False,mktidx='auto',source='auto',ticker_type='auto'):
|
247
255
|
"""
|
248
256
|
功能:多只股票,对比其贝塔系数
|
249
257
|
"""
|
@@ -269,18 +277,24 @@ def compare_mticker_1beta(ticker,start,end, \
|
|
269
277
|
|
270
278
|
#计算日历日regression_period对应的交易日数
|
271
279
|
regtrddays=int(252 / 365 * regression_period)
|
280
|
+
|
281
|
+
#预处理ticker_type
|
282
|
+
ticker_type_list=ticker_type_preprocess_mticker_mixed(ticker,ticker_type)
|
272
283
|
|
273
284
|
df=pd.DataFrame()
|
274
285
|
for t in ticker:
|
286
|
+
pos=ticker.index(t)
|
287
|
+
tt=ticker_type_list[pos]
|
288
|
+
|
275
289
|
#关闭print输出
|
276
290
|
with HiddenPrints():
|
277
|
-
df_tmp=get_capm_beta(t,start,end,RF,regtrddays,mktidx,source)
|
291
|
+
df_tmp=get_capm_beta(t,start,end,RF,regtrddays,mktidx,source,ticker_type=tt)
|
278
292
|
|
279
293
|
if df_tmp is None:
|
280
294
|
break
|
281
295
|
else:
|
282
296
|
dft=df_tmp[['beta']]
|
283
|
-
dft.rename(columns={'beta':ticker_name(t)},inplace=True)
|
297
|
+
dft.rename(columns={'beta':ticker_name(t,tt)},inplace=True)
|
284
298
|
|
285
299
|
if len(df)==0: #第一个
|
286
300
|
df=dft
|
@@ -297,7 +311,7 @@ def compare_mticker_1beta(ticker,start,end, \
|
|
297
311
|
#是否绘制水平线
|
298
312
|
if df1[c].max() > axhline_value and df1[c].min() < axhline_value:
|
299
313
|
axhline_label='零线'
|
300
|
-
#df1.rename(columns={c:
|
314
|
+
#df1.rename(columns={c:ticker_name(c)},inplace=True)
|
301
315
|
|
302
316
|
#共同脚注
|
303
317
|
footnote1="注:"
|
@@ -348,7 +362,7 @@ def compare_1ticker_mRF(ticker,start,end, \
|
|
348
362
|
RF=[0,0.02,0.05], \
|
349
363
|
regression_period=365, \
|
350
364
|
graph=True,axhline_value=1,axhline_label='', \
|
351
|
-
annotate=False,mktidx='auto',source='auto'):
|
365
|
+
annotate=False,mktidx='auto',source='auto',ticker_type='auto'):
|
352
366
|
"""
|
353
367
|
功能:一只股票,不同的无风险收益率
|
354
368
|
"""
|
@@ -374,12 +388,15 @@ def compare_1ticker_mRF(ticker,start,end, \
|
|
374
388
|
|
375
389
|
#计算日历日regression_period对应的交易日数
|
376
390
|
regtrddays=int(252 / 365 * regression_period)
|
391
|
+
|
392
|
+
#预处理ticker_type
|
393
|
+
ticker_type=ticker_type_preprocess_mticker_mixed(ticker,ticker_type)
|
377
394
|
|
378
395
|
df=pd.DataFrame()
|
379
396
|
for t in RF:
|
380
397
|
#关闭print输出
|
381
398
|
with HiddenPrints():
|
382
|
-
df_tmp=get_capm_beta(ticker,start,end,t,regtrddays,mktidx,source)
|
399
|
+
df_tmp=get_capm_beta(ticker,start,end,t,regtrddays,mktidx,source,ticker_type=ticker_type)
|
383
400
|
|
384
401
|
if df_tmp is None:
|
385
402
|
break
|
@@ -423,7 +440,7 @@ def compare_1ticker_mRF(ticker,start,end, \
|
|
423
440
|
|
424
441
|
#绘图
|
425
442
|
if graph:
|
426
|
-
title_txt="CAPM贝塔系数:"+ticker_name(ticker)
|
443
|
+
title_txt="CAPM贝塔系数:"+ticker_name(ticker,ticker_type)
|
427
444
|
y_label="贝塔系数"
|
428
445
|
|
429
446
|
draw_lines(df1,y_label,x_label=footnotex, \
|
@@ -453,7 +470,7 @@ def compare_1ticker_mregression_period(ticker,start,end, \
|
|
453
470
|
RF=0, \
|
454
471
|
regression_period=[183,365,730], \
|
455
472
|
graph=True,axhline_value=1,axhline_label='', \
|
456
|
-
annotate=False,mktidx='auto',source='auto'):
|
473
|
+
annotate=False,mktidx='auto',source='auto',ticker_type='auto'):
|
457
474
|
"""
|
458
475
|
功能:一只股票或一个投资组合,不同的回归期间
|
459
476
|
"""
|
@@ -476,6 +493,9 @@ def compare_1ticker_mregression_period(ticker,start,end, \
|
|
476
493
|
if isinstance(regression_period,int):
|
477
494
|
regression_period=[regression_period]
|
478
495
|
print(" Starting to retrive and calculate capm beta on different regression period, please wait ......")
|
496
|
+
|
497
|
+
#预处理ticker_type
|
498
|
+
ticker_type=ticker_type_preprocess_mticker_mixed(ticker,ticker_type)
|
479
499
|
|
480
500
|
df=pd.DataFrame()
|
481
501
|
for t in regression_period:
|
@@ -484,7 +504,7 @@ def compare_1ticker_mregression_period(ticker,start,end, \
|
|
484
504
|
|
485
505
|
#关闭print输出
|
486
506
|
with HiddenPrints():
|
487
|
-
df_tmp=get_capm_beta(ticker,start,end,RF,regtrddays,mktidx,source)
|
507
|
+
df_tmp=get_capm_beta(ticker,start,end,RF,regtrddays,mktidx,source,ticker_type=ticker_type)
|
488
508
|
|
489
509
|
if df_tmp is None:
|
490
510
|
break
|
@@ -524,7 +544,7 @@ def compare_1ticker_mregression_period(ticker,start,end, \
|
|
524
544
|
|
525
545
|
#绘图
|
526
546
|
if graph:
|
527
|
-
title_txt="CAPM贝塔系数:"+ticker_name(ticker)
|
547
|
+
title_txt="CAPM贝塔系数:"+ticker_name(ticker,ticker_type)
|
528
548
|
y_label="贝塔系数"
|
529
549
|
|
530
550
|
draw_lines(df1,y_label,x_label=footnotex, \
|
@@ -556,7 +576,8 @@ if __name__=='__main__':
|
|
556
576
|
betas=compare_beta_security(ticker,start,end,RF)
|
557
577
|
|
558
578
|
def compare_beta_security(ticker,start,end,RF=0,regression_period=365, \
|
559
|
-
graph=True,annotate=False,mktidx='auto',source='auto'
|
579
|
+
graph=True,annotate=False,mktidx='auto',source='auto', \
|
580
|
+
ticker_type='auto'):
|
560
581
|
"""
|
561
582
|
功能:组合情况,可能多只股票、多个投资组合或投资组合与股票的混合,多个无风险收益率
|
562
583
|
|
@@ -570,7 +591,8 @@ def compare_beta_security(ticker,start,end,RF=0,regression_period=365, \
|
|
570
591
|
|
571
592
|
df=compare_mticker_1beta(ticker,start,end,RF,regression_period, \
|
572
593
|
graph, \
|
573
|
-
annotate=annotate,mktidx=mktidx,source=source
|
594
|
+
annotate=annotate,mktidx=mktidx,source=source, \
|
595
|
+
ticker_type=ticker_type)
|
574
596
|
return df
|
575
597
|
else:
|
576
598
|
#实际上是单个证券
|
@@ -581,7 +603,8 @@ def compare_beta_security(ticker,start,end,RF=0,regression_period=365, \
|
|
581
603
|
if len(RF) > 1:
|
582
604
|
df=compare_1ticker_mRF(ticker,start,end,RF,regression_period, \
|
583
605
|
graph, \
|
584
|
-
annotate=annotate,mktidx=mktidx,source=source
|
606
|
+
annotate=annotate,mktidx=mktidx,source=source, \
|
607
|
+
ticker_type=ticker_type)
|
585
608
|
return df
|
586
609
|
else:
|
587
610
|
#实际上是单个RF
|
@@ -593,15 +616,18 @@ def compare_beta_security(ticker,start,end,RF=0,regression_period=365, \
|
|
593
616
|
df=compare_1ticker_mregression_period(ticker,start,end, \
|
594
617
|
RF,regression_period, \
|
595
618
|
graph, \
|
596
|
-
annotate=annotate,mktidx=mktidx,source=source
|
619
|
+
annotate=annotate,mktidx=mktidx,source=source, \
|
620
|
+
ticker_type=ticker_type)
|
597
621
|
return df
|
598
622
|
else:
|
599
623
|
#实际上是单个regression_period
|
600
624
|
regression_period=regression_period[0]
|
601
625
|
|
602
|
-
#情形4:1只证券,1个RF,1
|
626
|
+
#情形4:1只证券,1个RF,1个回归天数?
|
603
627
|
df=compare_mticker_1beta(ticker,start,end,RF,regression_period, \
|
604
|
-
graph,annotate=annotate,mktidx=mktidx,source=source
|
628
|
+
graph,annotate=annotate,mktidx=mktidx,source=source, \
|
629
|
+
ticker_type=ticker_type)
|
630
|
+
|
605
631
|
return df
|
606
632
|
|
607
633
|
|