siat 3.2.5__py3-none-any.whl → 3.2.15__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 +14 -8
- siat/assets_liquidity.py +8 -8
- siat/capm_beta2.py +1 -1
- siat/common.py +116 -20
- siat/esg.py +2 -2
- siat/holding_risk.py +5 -5
- siat/markowitz.py +10 -10
- siat/markowitz2.py +73 -46
- siat/risk_adjusted_return.py +13 -13
- siat/security_price2.py +6 -6
- siat/security_prices.py +29 -10
- siat/stock.py +1 -1
- siat/stock_technical.py +569 -372
- siat/translate.py +1 -1
- siat/var_model_validation.py +1 -1
- {siat-3.2.5.dist-info → siat-3.2.15.dist-info}/METADATA +2 -1
- {siat-3.2.5.dist-info → siat-3.2.15.dist-info}/RECORD +19 -19
- {siat-3.2.5.dist-info → siat-3.2.15.dist-info}/WHEEL +0 -0
- {siat-3.2.5.dist-info → siat-3.2.15.dist-info}/top_level.txt +0 -0
siat/__init__.py
CHANGED
@@ -28,15 +28,12 @@ try:
|
|
28
28
|
latest_list=latest_version.split('.')
|
29
29
|
|
30
30
|
newest=True
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
elif current_list[2] < latest_list[2]:
|
36
|
-
newest=False
|
37
|
-
else:
|
38
|
-
pass
|
31
|
+
for i in range(3):
|
32
|
+
#print(i)
|
33
|
+
if int(current_list[i]) < int(latest_list[i]):
|
34
|
+
newest=False
|
39
35
|
|
36
|
+
"""
|
40
37
|
if not newest:
|
41
38
|
print("The latest version of siat is",latest_version,'\n')
|
42
39
|
print("*** If you expect to upgrade siat in Anaconda Prompt, use the instruction below:")
|
@@ -52,6 +49,15 @@ try:
|
|
52
49
|
|
53
50
|
print("If you have done any of the above, restart the Python (eg. restarting the kernel)")
|
54
51
|
print("Provided you still need additional help, please contact wdehong2000@163.com")
|
52
|
+
"""
|
53
|
+
if not newest:
|
54
|
+
#print("The latest version of siat is",latest_version,'\n')
|
55
|
+
print("Now there is a newer version of siat",latest_version,'\n')
|
56
|
+
print("*** How to upgrade siat?")
|
57
|
+
print("Upgrade directly from official source? use command: upgrade_siat()")
|
58
|
+
print("Upgrade from Tsinghua? use command: upgrade_siat(alternative='tsinghua')")
|
59
|
+
print("Upgrade from Alibaba? use command: upgrade_siat(alternative='alibaba')")
|
60
|
+
|
55
61
|
except:
|
56
62
|
pass
|
57
63
|
|
siat/assets_liquidity.py
CHANGED
@@ -111,7 +111,7 @@ def roll_spread_portfolio(portfolio,start,end,printout=True):
|
|
111
111
|
'-'+str(sp.index[-1].day)
|
112
112
|
print("\n===== 投资组合的流动性风险 =====")
|
113
113
|
|
114
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
114
|
+
_,_,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
115
115
|
if len(tickerlist)==1:
|
116
116
|
product=str(ticker_name(tickerlist,'bond'))
|
117
117
|
else:
|
@@ -192,7 +192,7 @@ def amihud_illiquidity_portfolio(portfolio,start,end,printout=True):
|
|
192
192
|
'-'+str(sp.index[-1].day)
|
193
193
|
print("\n===== 投资组合的流动性风险 =====")
|
194
194
|
|
195
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
195
|
+
_,_,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
196
196
|
if len(tickerlist)==1:
|
197
197
|
product=str(ticker_name(tickerlist,'bond'))
|
198
198
|
else:
|
@@ -338,7 +338,7 @@ def ps_liquidity_portfolio(portfolio,start,end,printout=True):
|
|
338
338
|
'-'+str(sp.index[-1].day)
|
339
339
|
print("\n===== 投资组合的流动性风险 =====")
|
340
340
|
|
341
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
341
|
+
_,_,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
342
342
|
if len(tickerlist)==1:
|
343
343
|
product=str(ticker_name(tickerlist,'bond'))
|
344
344
|
else:
|
@@ -423,7 +423,7 @@ def plot_liquidity_monthly(portfolio,start,end,liquidity_type):
|
|
423
423
|
ylabeltxt=ectranslate(liquidity_type)
|
424
424
|
titletxt="证券流动性风险的月度指标"
|
425
425
|
|
426
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
426
|
+
_,_,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
427
427
|
if len(tickerlist)==1:
|
428
428
|
product=str(ticker_name(tickerlist,'bond'))
|
429
429
|
else:
|
@@ -521,7 +521,7 @@ def plot_liquidity_annual(portfolio,start,end,liquidity_type):
|
|
521
521
|
ylabeltxt=ectranslate(liquidity_type)
|
522
522
|
titletxt="证券流动性风险的年度指标"
|
523
523
|
|
524
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
524
|
+
_,_,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
525
525
|
if len(tickerlist)==1:
|
526
526
|
product=str(ticker_name(tickerlist,'bond'))
|
527
527
|
else:
|
@@ -565,7 +565,7 @@ def draw_liquidity(liqs):
|
|
565
565
|
ylabeltxt=ectranslate(liqs['Type'][0])
|
566
566
|
titletxt="证券流动性风险的滚动趋势"
|
567
567
|
|
568
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
568
|
+
_,_,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
569
569
|
if len(tickerlist)==1:
|
570
570
|
product=str(ticker_name(tickerlist))
|
571
571
|
else:
|
@@ -721,12 +721,12 @@ def compare_liquidity_rolling(portfolio1,portfolio2,start,end,liquidity_type,win
|
|
721
721
|
ylabeltxt=ectranslate(liquidity_type)
|
722
722
|
titletxt="证券流动性风险走势比较"
|
723
723
|
|
724
|
-
_,_,tickerlist1,sharelist1=decompose_portfolio(portfolio1)
|
724
|
+
_,_,tickerlist1,sharelist1,ticker_type1=decompose_portfolio(portfolio1)
|
725
725
|
if len(tickerlist1)==1:
|
726
726
|
product1=str(ticker_name(tickerlist1,'bond'))
|
727
727
|
else:
|
728
728
|
product1=str(ticker_name(tickerlist1,'bond'))+',持仓'+str(sharelist1)
|
729
|
-
_,_,tickerlist2,sharelist2=decompose_portfolio(portfolio2)
|
729
|
+
_,_,tickerlist2,sharelist2,ticker_type2=decompose_portfolio(portfolio2)
|
730
730
|
if len(tickerlist2)==1:
|
731
731
|
product2=str(ticker_name(tickerlist2,'bond'))
|
732
732
|
else:
|
siat/capm_beta2.py
CHANGED
@@ -119,7 +119,7 @@ def regression_capm(ticker,start2,end, \
|
|
119
119
|
mktidx=get_market_index_code(ticker)
|
120
120
|
"""
|
121
121
|
if isinstance(ticker,dict):
|
122
|
-
_,mktidx,pftickerlist,_=decompose_portfolio(ticker)
|
122
|
+
_,mktidx,pftickerlist,_,ticker_type=decompose_portfolio(ticker)
|
123
123
|
if 'auto' in mktidx.lower():
|
124
124
|
mktidx=get_market_index_code(pftickerlist[0])
|
125
125
|
else:
|
siat/common.py
CHANGED
@@ -432,6 +432,15 @@ if __name__ =="__main__":
|
|
432
432
|
portfolio={'Market':('US','^GSPC'),'EDU':0.4,'TAL':0.3,'TEDU':0.2}
|
433
433
|
|
434
434
|
portfolio={'Market':('China','000001.SS','股债基组合'),'600519.SS':50,'sh010504':150,'sh010504':300}
|
435
|
+
|
436
|
+
Market={'Market':('China','000300.SS','股债基组合')}
|
437
|
+
Stocks={'600519.SS':0.4,#股票:贵州茅台
|
438
|
+
'sh010504':[0.3,'bond'],#05国债⑷
|
439
|
+
'010504':('fund',0.2),#招商稳兴混合C基金
|
440
|
+
}
|
441
|
+
portfolio=dict(Market,**Stocks)
|
442
|
+
|
443
|
+
decompose_portfolio(portfolio)
|
435
444
|
|
436
445
|
def decompose_portfolio(portfolio):
|
437
446
|
"""
|
@@ -439,6 +448,9 @@ def decompose_portfolio(portfolio):
|
|
439
448
|
投资组合的结构:{'Market':('US','^GSPC'),'AAPL':0.5,'MSFT':0.3,'IBM':0.2}
|
440
449
|
输入:投资组合
|
441
450
|
输出:市场,市场指数,股票代码列表和份额列表
|
451
|
+
|
452
|
+
注意:字典中相同的键会被合并为一个
|
453
|
+
新功能:分辨股票、债券和基金
|
442
454
|
"""
|
443
455
|
#从字典中提取信息
|
444
456
|
keylist=list(portfolio.keys()) #注意:字典中相同的键会被合并为一个
|
@@ -452,13 +464,49 @@ def decompose_portfolio(portfolio):
|
|
452
464
|
plist=plist+[value]
|
453
465
|
stocklist=slist[1:]
|
454
466
|
portionlist=plist[1:]
|
467
|
+
|
468
|
+
#识别证券类别
|
469
|
+
stype_list=['auto','stock','bond','fund']
|
470
|
+
ticker_type=[]
|
471
|
+
new_portionlist=[]
|
472
|
+
for p in portionlist:
|
473
|
+
if isinstance(p,int) or isinstance(p,float):
|
474
|
+
ticker_type=ticker_type+['auto']
|
475
|
+
new_portionlist=new_portionlist+[p]
|
476
|
+
elif isinstance(p,list) or isinstance(p,tuple):
|
477
|
+
ptype=False; pportion=False
|
478
|
+
p0=p[0]; p1=p[1]
|
479
|
+
|
480
|
+
if isinstance(p0,int) or isinstance(p0,float):
|
481
|
+
pportion=True
|
482
|
+
new_portionlist=new_portionlist+[p0]
|
483
|
+
elif isinstance(p0,str):
|
484
|
+
ptype=True
|
485
|
+
if p0 not in stype_list:
|
486
|
+
p0='auto'
|
487
|
+
ticker_type=ticker_type+[p0]
|
488
|
+
|
489
|
+
if isinstance(p1,int) or isinstance(p1,float):
|
490
|
+
pportion=True
|
491
|
+
new_portionlist=new_portionlist+[p1]
|
492
|
+
elif isinstance(p1,str):
|
493
|
+
ptype=True
|
494
|
+
if p1 not in stype_list:
|
495
|
+
p1='auto'
|
496
|
+
ticker_type=ticker_type+[p1]
|
497
|
+
|
498
|
+
#未能确定
|
499
|
+
if ptype==False:
|
500
|
+
ticker_type=ticker_type+['auto']
|
501
|
+
if pportion==False:
|
502
|
+
new_portionlist=new_portionlist+[0]
|
503
|
+
|
455
504
|
|
456
|
-
return scope,mktidx,stocklist,
|
505
|
+
return scope,mktidx,stocklist,new_portionlist,ticker_type
|
457
506
|
|
458
507
|
if __name__=='__main__':
|
459
508
|
portfolio1={'Market':('US','^GSPC'),'EDU':0.4,'TAL':0.3,'TEDU':0.2}
|
460
|
-
|
461
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio1)
|
509
|
+
decompose_portfolio(portfolio1)
|
462
510
|
|
463
511
|
def portfolio_name(portfolio):
|
464
512
|
"""
|
@@ -497,7 +545,7 @@ def isinstance_portfolio(portfolio):
|
|
497
545
|
result=True
|
498
546
|
|
499
547
|
try:
|
500
|
-
scope,mktidx,tickerlist,sharelist=decompose_portfolio(portfolio)
|
548
|
+
scope,mktidx,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
501
549
|
except:
|
502
550
|
result=False
|
503
551
|
|
@@ -634,7 +682,7 @@ def sample_selection(df,start,end):
|
|
634
682
|
|
635
683
|
if __name__=='__main__':
|
636
684
|
portfolio={'Market':('US','^GSPC'),'AAPL':1.0}
|
637
|
-
market,mktidx,tickerlist,sharelist=decompose_portfolio(portfolio)
|
685
|
+
market,mktidx,tickerlist,sharelist,_=decompose_portfolio(portfolio)
|
638
686
|
start='2020-1-1'; end='2020-3-31'
|
639
687
|
pfdf=get_portfolio_prices(tickerlist,sharelist,start,end)
|
640
688
|
start2='2020-1-10'; end2='2020-3-18'
|
@@ -3560,7 +3608,7 @@ def ticker_type_preprocess_1portfolio(ticker,ticker_type='auto'):
|
|
3560
3608
|
功能:根据ticker情况(单个投资组合)处理ticker_type,使之与ticker对应
|
3561
3609
|
"""
|
3562
3610
|
if isinstance(ticker,dict):
|
3563
|
-
_,_,tickerlist,_=decompose_portfolio(ticker)
|
3611
|
+
_,_,tickerlist,_,ticker_type=decompose_portfolio(ticker)
|
3564
3612
|
if len(tickerlist)==1:
|
3565
3613
|
ticker_type9=ticker_type_preprocess_1str(tickerlist[0],ticker_type)
|
3566
3614
|
else:
|
@@ -3718,7 +3766,7 @@ if __name__=='__main__':
|
|
3718
3766
|
|
3719
3767
|
def upgrade_siat(module_list=['siat','akshare','pandas','pandas_datareader', \
|
3720
3768
|
'yfinance','yahooquery','urllib3','tabulate','twine','mplfinance','openpyxl'], \
|
3721
|
-
pipcmd="pip install --upgrade"):
|
3769
|
+
pipcmd="pip install --upgrade",alternative=""):
|
3722
3770
|
"""
|
3723
3771
|
功能:一次性升级siat及其相关插件
|
3724
3772
|
|
@@ -3727,7 +3775,8 @@ def upgrade_siat(module_list=['siat','akshare','pandas','pandas_datareader', \
|
|
3727
3775
|
或python -m pip install --upgrade pip
|
3728
3776
|
如果上述方法不适用,您可能需要重新安装Python,并确保在安装过程中选中了“Add Python to PATH”
|
3729
3777
|
"""
|
3730
|
-
print("
|
3778
|
+
print("Upgrading siat and related modules, please wait ... ...")
|
3779
|
+
|
3731
3780
|
#获取系统目录
|
3732
3781
|
import sys
|
3733
3782
|
syspath=sys.path
|
@@ -3757,34 +3806,56 @@ def upgrade_siat(module_list=['siat','akshare','pandas','pandas_datareader', \
|
|
3757
3806
|
#生成pip命令字符串前半段,仅缺插件名
|
3758
3807
|
cmdstr=sp+sep_flag+'Scripts'+sep_flag+pipcmd+' '
|
3759
3808
|
|
3809
|
+
#检查是否使用镜像源
|
3810
|
+
if alternative == "":
|
3811
|
+
alter_source=''
|
3812
|
+
elif alternative == "tsinghua":
|
3813
|
+
alter_source="-i https://pypi.tuna.tsinghua.edu.cn/simple/"
|
3814
|
+
elif alternative in ["alibaba","ali","aliyun"]:
|
3815
|
+
alter_source="-i https://mirrors.aliyun.com/pypi/simple/"
|
3816
|
+
elif alternative == "bfsu":
|
3817
|
+
alter_source="-i https://mirrors.bfsu.edu.cn/pypi/"
|
3818
|
+
elif alternative == "baidu":
|
3819
|
+
alter_source="-i https://mirror.baidu.com/pypi/simple/"
|
3820
|
+
elif alternative == "tencent":
|
3821
|
+
alter_source="-i https://mirrors.cloud.tencent.com/pypi/simple/"
|
3822
|
+
else:
|
3823
|
+
alter_source="-i https://mirrors.aliyun.com/pypi/simple/"
|
3824
|
+
|
3760
3825
|
#逐个升级插件
|
3761
3826
|
import subprocess
|
3762
3827
|
fail_list=[]
|
3763
|
-
|
3828
|
+
|
3829
|
+
"""
|
3830
|
+
tqdm进度条:
|
3831
|
+
100%|██████████| 9/11 [02:18<02:30, 12.59s/it]
|
3832
|
+
9/11:一共11项,正在进行第9项
|
3833
|
+
02:18<02:30:已经花费时间02:18,预计花费时间02:30
|
3834
|
+
12.59s/it:平均每项花费时间12.59秒
|
3835
|
+
"""
|
3836
|
+
from tqdm import tqdm
|
3837
|
+
for m in tqdm(module_list):
|
3764
3838
|
#print("Upgrading",m,"... ...",end='')
|
3765
|
-
print_progress_percent2(m,module_list,steps=5,leading_blanks=2)
|
3839
|
+
#print_progress_percent2(m,module_list,steps=5,leading_blanks=2)
|
3766
3840
|
|
3767
|
-
|
3841
|
+
if alternative == "":
|
3842
|
+
cmdstr1=cmdstr+m
|
3843
|
+
else:
|
3844
|
+
cmdstr1=cmdstr+m+' '+alter_source
|
3768
3845
|
#print(cmdstr1)
|
3846
|
+
|
3769
3847
|
#proc=subprocess.run(cmdstr1.split(' '),stdout=subprocess.PIPE)
|
3770
3848
|
proc=subprocess.run(cmdstr1.split(' '))
|
3771
3849
|
rcode=proc.returncode
|
3772
3850
|
if rcode !=0: fail_list=fail_list+[m]
|
3773
|
-
|
3774
|
-
"""
|
3775
|
-
if rcode==0: result='done✓'
|
3776
|
-
else: result='FAILed❌, try again manually'
|
3777
|
-
print(result)
|
3778
|
-
"""
|
3779
3851
|
|
3780
3852
|
if len(fail_list) == 0:
|
3781
|
-
print("
|
3853
|
+
print("All specified modules are successfully upgraded!")
|
3782
3854
|
else:
|
3783
|
-
print("
|
3855
|
+
print("All specified modules are successfully upgraded except",end='')
|
3784
3856
|
print_list(fail_list,leading_blanks=1)
|
3785
3857
|
|
3786
3858
|
return
|
3787
|
-
#==============================================================================
|
3788
3859
|
|
3789
3860
|
def df_index_timezone_remove(df):
|
3790
3861
|
"""
|
@@ -3824,6 +3895,31 @@ def is_weekend(adate):
|
|
3824
3895
|
|
3825
3896
|
|
3826
3897
|
#==============================================================================
|
3898
|
+
if __name__=='__main__':
|
3899
|
+
alist=['EMA40','EMA5','EMA','EMA20']
|
3900
|
+
alist=['EMA20','EMA5']
|
3901
|
+
sort_list_by_len(alist)
|
3902
|
+
|
3903
|
+
def sort_list_by_len(alist,reverse=False):
|
3904
|
+
"""
|
3905
|
+
功能:基于字符串列表中元素的长度和大小排序
|
3906
|
+
"""
|
3907
|
+
import pandas as pd
|
3908
|
+
adf=pd.DataFrame(columns=('item','len'))
|
3909
|
+
for a in alist:
|
3910
|
+
row=pd.Series({'item':a,'len':len(a)})
|
3911
|
+
try:
|
3912
|
+
adf=v.append(row,ignore_index=True)
|
3913
|
+
except:
|
3914
|
+
adf=adf._append(row,ignore_index=True)
|
3915
|
+
if not reverse:
|
3916
|
+
adf.sort_values(by=['len','item'],ascending=True,inplace=True)
|
3917
|
+
else:
|
3918
|
+
adf.sort_values(by=['len','item'],ascending=False,inplace=True)
|
3919
|
+
|
3920
|
+
alist_sorted=list(adf['item'])
|
3921
|
+
|
3922
|
+
return alist_sorted
|
3827
3923
|
#==============================================================================
|
3828
3924
|
#==============================================================================
|
3829
3925
|
#==============================================================================
|
siat/esg.py
CHANGED
@@ -297,7 +297,7 @@ def portfolio_esg(portfolio):
|
|
297
297
|
企业最新的可持续性发展数据,数据框
|
298
298
|
"""
|
299
299
|
#解构投资组合
|
300
|
-
_,_,stocklist,_=decompose_portfolio(portfolio)
|
300
|
+
_,_,stocklist,_,ticker_type=decompose_portfolio(portfolio)
|
301
301
|
|
302
302
|
#抓取数据
|
303
303
|
try:
|
@@ -439,7 +439,7 @@ def portfolio_esg2(portfolio):
|
|
439
439
|
企业最新的可持续性发展数据,数据框
|
440
440
|
"""
|
441
441
|
#解构投资组合
|
442
|
-
_,_,stocklist,_=decompose_portfolio(portfolio)
|
442
|
+
_,_,stocklist,_,ticker_type=decompose_portfolio(portfolio)
|
443
443
|
|
444
444
|
#抓取数据
|
445
445
|
try:
|
siat/holding_risk.py
CHANGED
@@ -87,7 +87,7 @@ def get_portfolio_prices0(portfolio,fromdate,todate):
|
|
87
87
|
"""
|
88
88
|
|
89
89
|
#解构投资组合
|
90
|
-
_,mktidx,tickerlist,sharelist=decompose_portfolio(portfolio)
|
90
|
+
_,mktidx,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
91
91
|
|
92
92
|
#检查股票列表个数与份额列表个数是否一致
|
93
93
|
if len(tickerlist) != len(sharelist):
|
@@ -562,7 +562,7 @@ def get_VaR_portfolio(portfolio,today,future_days=1,alpha=0.99, \
|
|
562
562
|
|
563
563
|
#输出VaR金额和比率
|
564
564
|
print("\n===== 投资组合的在险价值VaR =====")
|
565
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
565
|
+
_,_,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
566
566
|
print("成分股列表 :",tickerlist)
|
567
567
|
print("成分股的配置:",sharelist)
|
568
568
|
print("当前日期 :",today)
|
@@ -686,7 +686,7 @@ def get_ES_portfolio(portfolio,today,future_days=1,alpha=0.99, \
|
|
686
686
|
|
687
687
|
#输出ES金额和比率
|
688
688
|
print("\n===== 投资组合的预期不足ES =====")
|
689
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
689
|
+
_,_,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
690
690
|
print("成分股列表 :",tickerlist)
|
691
691
|
print("成分股配置 :",sharelist)
|
692
692
|
print("当前日期 :",today)
|
@@ -770,7 +770,7 @@ def portfolio_ret_Normality_SW(portfolio,fromdate,todate, \
|
|
770
770
|
|
771
771
|
if not printout: return W,p_value,S,K
|
772
772
|
|
773
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
773
|
+
_,_,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
774
774
|
print("*** Shapiro-Wilk Normality Test ***")
|
775
775
|
print(" Stock(s):",tickerlist)
|
776
776
|
print(" Holding proportion:",sharelist)
|
@@ -812,7 +812,7 @@ def portfolio_rets_curve(portfolio,fromdate,todate):
|
|
812
812
|
num=len(prices)
|
813
813
|
rets=prices['Ret']
|
814
814
|
W,p_value,S,K=ret_Normality_SW(rets)
|
815
|
-
_,_,tickerlist,sharelist=decompose_portfolio(portfolio)
|
815
|
+
_,_,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
816
816
|
#计算收益率的均值和标准差
|
817
817
|
mu=rets.mean()
|
818
818
|
sigma=rets.std()
|
siat/markowitz.py
CHANGED
@@ -250,7 +250,7 @@ def portfolio_cumret(portfolio,thedate,pastyears=1, \
|
|
250
250
|
"""
|
251
251
|
print("\n Searching for portfolio info, which may take time ...")
|
252
252
|
# 解构投资组合
|
253
|
-
scope,_,tickerlist,sharelist0=decompose_portfolio(portfolio)
|
253
|
+
scope,_,tickerlist,sharelist0,ticker_type=decompose_portfolio(portfolio)
|
254
254
|
pname=portfolio_name(portfolio)
|
255
255
|
|
256
256
|
#如果持仓份额总数不为1,则将其转换为总份额为1
|
@@ -934,7 +934,7 @@ def portfolio_es(pf_info,simulation=50000):
|
|
934
934
|
"""
|
935
935
|
[[portfolio,thedate,stock_return,_,_],_]=pf_info
|
936
936
|
pname=portfolio_name(portfolio)
|
937
|
-
_,_,tickerlist,_=decompose_portfolio(portfolio)
|
937
|
+
_,_,tickerlist,_,ticker_type=decompose_portfolio(portfolio)
|
938
938
|
|
939
939
|
#取出观察期
|
940
940
|
hstart0=stock_return.index[0]; hstart=str(hstart0.date())
|
@@ -1050,7 +1050,7 @@ def portfolio_es_sharpe(pf_info,simulation=1000,rate_period='1Y',rate_type='trea
|
|
1050
1050
|
|
1051
1051
|
[[portfolio,thedate,stock_return0,rf_df,_],_]=pf_info
|
1052
1052
|
pname=portfolio_name(portfolio)
|
1053
|
-
scope,_,tickerlist,_=decompose_portfolio(portfolio)
|
1053
|
+
scope,_,tickerlist,_,ticker_type=decompose_portfolio(portfolio)
|
1054
1054
|
|
1055
1055
|
#取出观察期
|
1056
1056
|
hstart0=stock_return0.index[0]; hstart=str(hstart0.date())
|
@@ -1137,7 +1137,7 @@ def portfolio_es_sortino(pf_info,simulation=1000,rate_period='1Y',rate_type='tre
|
|
1137
1137
|
|
1138
1138
|
[[portfolio,thedate,stock_return0,rf_df,_],_]=pf_info
|
1139
1139
|
pname=portfolio_name(portfolio)
|
1140
|
-
scope,_,tickerlist,_=decompose_portfolio(portfolio)
|
1140
|
+
scope,_,tickerlist,_,ticker_type=decompose_portfolio(portfolio)
|
1141
1141
|
|
1142
1142
|
#取出观察期
|
1143
1143
|
hstart0=stock_return0.index[0]; hstart=str(hstart0.date())
|
@@ -1230,7 +1230,7 @@ def portfolio_es_alpha(pf_info,simulation=1000,rate_period='1Y',rate_type='treas
|
|
1230
1230
|
|
1231
1231
|
[[portfolio,thedate,stock_return0,rf_df,_],_]=pf_info
|
1232
1232
|
pname=portfolio_name(portfolio)
|
1233
|
-
scope,mktidx,tickerlist,_=decompose_portfolio(portfolio)
|
1233
|
+
scope,mktidx,tickerlist,_,ticker_type=decompose_portfolio(portfolio)
|
1234
1234
|
|
1235
1235
|
#取出观察期
|
1236
1236
|
hstart0=stock_return0.index[0]; hstart=str(hstart0.date())
|
@@ -1338,7 +1338,7 @@ def portfolio_es_treynor(pf_info,simulation=1000,rate_period='1Y',rate_type='tre
|
|
1338
1338
|
|
1339
1339
|
[[portfolio,_,stock_return0,rf_df,_],_]=pf_info
|
1340
1340
|
pname=portfolio_name(portfolio)
|
1341
|
-
scope,mktidx,tickerlist,_=decompose_portfolio(portfolio)
|
1341
|
+
scope,mktidx,tickerlist,_,ticker_type=decompose_portfolio(portfolio)
|
1342
1342
|
|
1343
1343
|
#取出观察期
|
1344
1344
|
hstart0=stock_return0.index[0]; hstart=str(hstart0.date())
|
@@ -1754,7 +1754,7 @@ def portfolio_optimize_rar(es_info,col_ratio,col_y,col_x,name_hiret,name_lorisk,
|
|
1754
1754
|
"""
|
1755
1755
|
#解析传入的数据
|
1756
1756
|
[[[portfolio,thedate,stock_return,_,_],[StockReturns,_,_,_]],RandomPortfolios]=es_info
|
1757
|
-
_,_,tickerlist,_=decompose_portfolio(portfolio)
|
1757
|
+
_,_,tickerlist,_,ticker_type=decompose_portfolio(portfolio)
|
1758
1758
|
numstocks=len(tickerlist)
|
1759
1759
|
pname=portfolio_name(portfolio)
|
1760
1760
|
|
@@ -1887,7 +1887,7 @@ def portfolio_optimize_strategy(pf_info,ratio='sharpe',simulation=50000,RF=False
|
|
1887
1887
|
portfolio_expectation(hi_name,pf_info,hiret_weights)
|
1888
1888
|
|
1889
1889
|
if MSR_return:
|
1890
|
-
scope,mktidx,tickerlist,_=decompose_portfolio(portfolio)
|
1890
|
+
scope,mktidx,tickerlist,_,ticker_type=decompose_portfolio(portfolio)
|
1891
1891
|
hwdf=pd.DataFrame(hiret_weights)
|
1892
1892
|
hwdft=hwdf.T
|
1893
1893
|
hwdft.columns=tickerlist
|
@@ -2289,7 +2289,7 @@ def describe_portfolio(portfolio):
|
|
2289
2289
|
输出:市场,市场指数,股票代码列表和份额列表
|
2290
2290
|
"""
|
2291
2291
|
|
2292
|
-
scope,mktidx,tickerlist,sharelist=decompose_portfolio(portfolio)
|
2292
|
+
scope,mktidx,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
2293
2293
|
pname=portfolio_name(portfolio)
|
2294
2294
|
|
2295
2295
|
print("*** 投资组合信息:",pname)
|
@@ -2321,7 +2321,7 @@ def portfolio_drop(portfolio,last=0,droplist=[],new_name=''):
|
|
2321
2321
|
"""
|
2322
2322
|
功能:删除最后几个成分股
|
2323
2323
|
"""
|
2324
|
-
scope,mktidx,tickerlist,sharelist=decompose_portfolio(portfolio)
|
2324
|
+
scope,mktidx,tickerlist,sharelist,ticker_type=decompose_portfolio(portfolio)
|
2325
2325
|
pname=portfolio_name(portfolio)
|
2326
2326
|
|
2327
2327
|
if not (last ==0):
|