siat 3.2.1__py3-none-any.whl → 3.2.3__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/fund_china.py +3 -3
- siat/markowitz2.py +11 -4
- siat/stock_technical.py +81 -50
- {siat-3.2.1.dist-info → siat-3.2.3.dist-info}/METADATA +1 -1
- {siat-3.2.1.dist-info → siat-3.2.3.dist-info}/RECORD +7 -7
- {siat-3.2.1.dist-info → siat-3.2.3.dist-info}/WHEEL +0 -0
- {siat-3.2.1.dist-info → siat-3.2.3.dist-info}/top_level.txt +0 -0
siat/fund_china.py
CHANGED
@@ -2375,14 +2375,14 @@ def compare_metf_china(fund_list,start,end,ftype='单位净值',graph=True):
|
|
2375
2375
|
|
2376
2376
|
#绘图
|
2377
2377
|
y_label=ftype
|
2378
|
-
import datetime;
|
2378
|
+
import datetime; todaydt = datetime.date.today()
|
2379
2379
|
|
2380
2380
|
lang=check_language()
|
2381
2381
|
if lang == 'English':
|
2382
|
-
x_label="Source: eastmoney/tiantian funds, "+str(
|
2382
|
+
x_label="Source: eastmoney/tiantian funds, "+str(todaydt)
|
2383
2383
|
title_txt="Compare Multiple ETF Fund Performance"
|
2384
2384
|
else:
|
2385
|
-
x_label="数据来源: 东方财富/天天基金,"+str(
|
2385
|
+
x_label="数据来源: 东方财富/天天基金,"+str(todaydt)
|
2386
2386
|
title_txt="比较多只ETF基金的净值指标"
|
2387
2387
|
|
2388
2388
|
draw_lines(fdf,y_label,x_label,axhline_value=0,axhline_label='',title_txt=title_txt, \
|
siat/markowitz2.py
CHANGED
@@ -1442,6 +1442,9 @@ def portfolio_es_alpha(pf_info,simulation=1000,RF=0):
|
|
1442
1442
|
mkt1=pd.DataFrame(mkt['Mkt'])
|
1443
1443
|
|
1444
1444
|
stock_return0m=pd.merge(stock_return0,mkt1,how='left',left_index=True,right_index=True)
|
1445
|
+
#必须舍弃空值,否则下面的回归将得不到系数!!!
|
1446
|
+
stock_return0m.dropna(inplace=True)
|
1447
|
+
|
1445
1448
|
#处理期间内无风险利率
|
1446
1449
|
"""
|
1447
1450
|
if RF:
|
@@ -1492,8 +1495,7 @@ def portfolio_es_alpha(pf_info,simulation=1000,RF=0):
|
|
1492
1495
|
stock_return['pReta']=(1+stock_return['pRet'])**252 - 1
|
1493
1496
|
stock_return['Mkta']=(1+stock_return['Mkt'])**252 - 1
|
1494
1497
|
"""
|
1495
|
-
|
1496
|
-
|
1498
|
+
#回归求截距项作为阿尔法指数:参与回归的变量不能有空值,否则回归系数将为空值!!!
|
1497
1499
|
(beta,alpha,_,_,_)=stats.linregress(stock_return['Mkt'],stock_return['pRet'])
|
1498
1500
|
"""
|
1499
1501
|
mean_return=stock_return[tickerlist].mul(random_weight,axis=1).sum(axis=1).mean(axis=0)
|
@@ -1938,7 +1940,9 @@ if __name__=='__main__':
|
|
1938
1940
|
|
1939
1941
|
|
1940
1942
|
#==============================================================================
|
1941
|
-
|
1943
|
+
if __name__=='__main__':
|
1944
|
+
graph=True; convex_hull=False
|
1945
|
+
|
1942
1946
|
def portfolio_optimize_alpha(es_info,graph=True,convex_hull=False):
|
1943
1947
|
"""
|
1944
1948
|
功能:计算投资组合的最高詹森阿尔法组合,并绘图
|
@@ -2020,7 +2024,9 @@ def portfolio_optimize_treynor(es_info,graph=True,convex_hull=False):
|
|
2020
2024
|
return name_hiret,hiret_weights,name_lorisk,lorisk_weights,portfolio_returns
|
2021
2025
|
|
2022
2026
|
#==============================================================================
|
2023
|
-
|
2027
|
+
if __name__=='__main__':
|
2028
|
+
col_ratio,col_y,col_x,name_hiret,name_lorisk,colorbartxt,title_ext,ylabeltxt,x_axis_name= \
|
2029
|
+
('Sharpe', 'alpha', 'beta', 'MAR', 'GMBA', '阿尔法指数', '阿尔法指数', '阿尔法指数', '贝塔系数')
|
2024
2030
|
|
2025
2031
|
def portfolio_optimize_rar(es_info,col_ratio,col_y,col_x,name_hiret,name_lorisk, \
|
2026
2032
|
colorbartxt,title_ext,ylabeltxt,x_axis_name,graph=True, \
|
@@ -2132,6 +2138,7 @@ if __name__=='__main__':
|
|
2132
2138
|
|
2133
2139
|
RF=0
|
2134
2140
|
graph=True;hirar_return=False;lorisk=True
|
2141
|
+
convex_hull=False
|
2135
2142
|
|
2136
2143
|
def portfolio_optimize(pf_info,ratio='sharpe',simulation=10000,RF=0, \
|
2137
2144
|
graph=True,hirar_return=False,lorisk=True,convex_hull=False):
|
siat/stock_technical.py
CHANGED
@@ -2438,6 +2438,7 @@ if __name__ =="__main__":
|
|
2438
2438
|
technical='EMV'; indicator='Close'
|
2439
2439
|
|
2440
2440
|
attention_values=[0,25,50,75]
|
2441
|
+
more_details=False
|
2441
2442
|
ticker_type='auto'; source='auto'
|
2442
2443
|
ahead_days=30*4
|
2443
2444
|
resample_freq='6H'; smooth=True;linewidth=1.5
|
@@ -2449,8 +2450,7 @@ if __name__ =="__main__":
|
|
2449
2450
|
price_line_style='dotted'; price_line_color='red'; price_line_width=5; price_line_marker='.'
|
2450
2451
|
|
2451
2452
|
|
2452
|
-
df=security_technical2(ticker,start,end,technical=technical,
|
2453
|
-
loc1='lower left',loc2='lower right')
|
2453
|
+
df=security_technical2(ticker,start,end,technical=technical,marker_sizes=[20,150,300])
|
2454
2454
|
|
2455
2455
|
tlist=['RSI','OBV','MACD','KDJ','VOL','PSY','ARBR','CR','EMV','Bollinger', \
|
2456
2456
|
'TRIX','DMA','BIAS','CCI','W%R','ROC','DMI']
|
@@ -2459,50 +2459,55 @@ if __name__ =="__main__":
|
|
2459
2459
|
|
2460
2460
|
def security_technical2(ticker,start='default',end='default', \
|
2461
2461
|
technical=['MACD'],indicator='Close', \
|
2462
|
-
|
2462
|
+
more_details=False, \
|
2463
2463
|
attention_values=[0,25,50,75,100], \
|
2464
2464
|
|
2465
|
-
|
2466
|
-
|
2467
|
-
|
2468
|
-
|
2469
|
-
|
2470
|
-
|
2471
|
-
|
2472
|
-
|
2473
|
-
|
2474
|
-
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2479
|
-
|
2480
|
-
|
2481
|
-
|
2482
|
-
|
2483
|
-
|
2484
|
-
|
2485
|
-
|
2486
|
-
|
2487
|
-
|
2488
|
-
|
2489
|
-
|
2490
|
-
|
2491
|
-
|
2492
|
-
|
2493
|
-
|
2494
|
-
|
2495
|
-
|
2496
|
-
|
2497
|
-
|
2498
|
-
|
2499
|
-
|
2500
|
-
|
2501
|
-
|
2502
|
-
|
2503
|
-
|
2504
|
-
|
2505
|
-
|
2465
|
+
ticker_type='auto',source='auto', \
|
2466
|
+
|
2467
|
+
#指标的默认参数
|
2468
|
+
RSI_days=[6,24], \
|
2469
|
+
OBV_days=5, \
|
2470
|
+
|
2471
|
+
MA_days=[5,20], \
|
2472
|
+
MACD_fastperiod=12,MACD_slowperiod=26,MACD_signalperiod=9, \
|
2473
|
+
|
2474
|
+
KDJ_fastk_period=9,KDJ_slowk_period=5,KDJ_slowk_matype=1, \
|
2475
|
+
KDJ_slowd_period=5,KDJ_slowd_matype=1, \
|
2476
|
+
|
2477
|
+
VOL_fastperiod=5,VOL_slowperiod=10, \
|
2478
|
+
PSY_days=12, \
|
2479
|
+
ARBR_days=26, \
|
2480
|
+
CR_day=16,CR_madays=[5,20], \
|
2481
|
+
EMV_day=14,EMV_madays=9, \
|
2482
|
+
|
2483
|
+
BULL_days=20,BULL_nbdevup=2,BULL_nbdevdn=2,BULL_matype=0, \
|
2484
|
+
|
2485
|
+
DMA_fastperiod=10,DMA_slowperiod=50,DMA_madays=10, \
|
2486
|
+
|
2487
|
+
TRIX_day=12,TRIX_madays=20, \
|
2488
|
+
BIAS_days=[6,24], \
|
2489
|
+
CCI_days=14, \
|
2490
|
+
WR_days=[10,6], \
|
2491
|
+
ROC_day=12,ROC_madays=6, \
|
2492
|
+
DMI_DIdays=14,DMI_ADXdays=6, \
|
2493
|
+
|
2494
|
+
#数据提前量
|
2495
|
+
ahead_days=30*4, \
|
2496
|
+
|
2497
|
+
#绘图参数
|
2498
|
+
resample_freq='6H',smooth=True,linewidth=1.5, \
|
2499
|
+
date_range=False,date_freq=False,annotate=False, \
|
2500
|
+
|
2501
|
+
graph=['ALL'],printout=False, \
|
2502
|
+
loc1='best',loc2='best', \
|
2503
|
+
|
2504
|
+
facecolor=['whitesmoke','papayawhip'], \
|
2505
|
+
#price_line_style=(0,(1,1)), \
|
2506
|
+
price_line_style='dotted', \
|
2507
|
+
price_line_color=['red','green'], \
|
2508
|
+
price_line_width=5,price_line_marker='o', \
|
2509
|
+
marker_sizes=[30,120,250], \
|
2510
|
+
):
|
2506
2511
|
"""
|
2507
2512
|
功能:计算和绘制证券技术分析指标的简易图,仅供进一步探索使用,仅用于单个证券(股债基)
|
2508
2513
|
|
@@ -2520,7 +2525,7 @@ def security_technical2(ticker,start='default',end='default', \
|
|
2520
2525
|
return None
|
2521
2526
|
|
2522
2527
|
#检查indicator
|
2523
|
-
if indicator not in ['Open','Close','High','Low']:
|
2528
|
+
if indicator not in ['Open','Close','High','Low','Adj Close']:
|
2524
2529
|
print(" #Warning(security_technical2): not a valid price type for",indicator)
|
2525
2530
|
return None
|
2526
2531
|
|
@@ -2555,7 +2560,21 @@ def security_technical2(ticker,start='default',end='default', \
|
|
2555
2560
|
print(" #Warning(security_technical2): no prices found for",ticker,'as type',ticker_type)
|
2556
2561
|
return None
|
2557
2562
|
|
2563
|
+
#当日涨跌
|
2558
2564
|
price['up_down']=price['Close']-price['Open']
|
2565
|
+
price['up_down_abs']=abs(price['up_down'])
|
2566
|
+
|
2567
|
+
#分位数
|
2568
|
+
import numpy as np
|
2569
|
+
"""
|
2570
|
+
max(price['up_down_abs'])
|
2571
|
+
min(price['up_down_abs'])
|
2572
|
+
"""
|
2573
|
+
q70=np.percentile(price['up_down_abs'],70)
|
2574
|
+
q30=np.percentile(price['up_down_abs'],30)
|
2575
|
+
|
2576
|
+
small_size=marker_sizes[0]; mid_size=marker_sizes[1]; big_size=marker_sizes[2]
|
2577
|
+
price['marker_size']=price['up_down_abs'].apply(lambda x: big_size if x>=q70 else mid_size if x>=q30 else small_size)
|
2559
2578
|
|
2560
2579
|
#计算技术指标
|
2561
2580
|
df=calc_technical(price,fromdate,todate, \
|
@@ -2673,7 +2692,7 @@ def security_technical2(ticker,start='default',end='default', \
|
|
2673
2692
|
|
2674
2693
|
#字段排序
|
2675
2694
|
tech_line_collist.sort()
|
2676
|
-
df1=df[tech_line_collist+[indicator,'Volume','up_down']]
|
2695
|
+
df1=df[tech_line_collist+[indicator,'Volume','up_down','marker_size']]
|
2677
2696
|
|
2678
2697
|
#绘图----------------------------------------------------------------------
|
2679
2698
|
import matplotlib.pyplot as plt
|
@@ -2802,12 +2821,12 @@ def security_technical2(ticker,start='default',end='default', \
|
|
2802
2821
|
seg_list=list(set(list(df1['segment'])))
|
2803
2822
|
|
2804
2823
|
ax2 = ax.twinx()
|
2805
|
-
ylabeltxt2=
|
2824
|
+
ylabeltxt2=ectranslate(indicator)
|
2806
2825
|
ax2.set_ylabel(ylabeltxt2,fontsize=ylabel_txt_size)
|
2807
2826
|
|
2808
2827
|
#细灰线先画出轮廓
|
2809
2828
|
ax2.plot(df1.index,df1[indicator],label='', \
|
2810
|
-
linestyle=price_line_style,color='grey',lw=
|
2829
|
+
linestyle=price_line_style,color='grey',lw=2)
|
2811
2830
|
|
2812
2831
|
#不同颜色绘制涨跌价格线
|
2813
2832
|
first_time=True; second_time=False
|
@@ -2834,8 +2853,10 @@ def security_technical2(ticker,start='default',end='default', \
|
|
2834
2853
|
ax2.plot(df1seg.index,df1seg[indicator],label=labeltxt, \
|
2835
2854
|
linestyle=':',color=seg_color,lw=price_line_width,marker=price_line_marker)
|
2836
2855
|
"""
|
2837
|
-
ax2.scatter(df1seg.index,df1seg[indicator],
|
2838
|
-
|
2856
|
+
ax2.scatter(df1seg.index,df1seg[indicator], \
|
2857
|
+
s=df1seg['marker_size'], \
|
2858
|
+
label=labeltxt, \
|
2859
|
+
linestyle=':',color=seg_color,lw=price_line_width,marker=price_line_marker)
|
2839
2860
|
|
2840
2861
|
|
2841
2862
|
"""
|
@@ -2853,6 +2874,16 @@ def security_technical2(ticker,start='default',end='default', \
|
|
2853
2874
|
|
2854
2875
|
ax3.set_ylabel("交易量(百万)",fontsize=ylabel_txt_size -4)
|
2855
2876
|
|
2877
|
+
footnote1="\n注:快线自下而上穿过慢线为金叉,自上而下穿过慢线为死叉。"
|
2878
|
+
footnote2="价格曲线上端点的大中小对应当日涨跌幅度三分位数的高中低部分。\n"
|
2879
|
+
footnote3="横轴日期上的空白处为非交易日(周末或公共节假日)。"
|
2880
|
+
|
2881
|
+
import datetime; todaydt = str(datetime.date.today())
|
2882
|
+
footnote4="数据来源:新浪/雅虎/stooq/东方财富等,"+todaydt+"统计"
|
2883
|
+
|
2884
|
+
footnote=footnote1+footnote2+footnote3+footnote4
|
2885
|
+
ax3.set_xlabel(footnote,fontsize=ylabel_txt_size -2)
|
2886
|
+
|
2856
2887
|
#fig.text(0.5, 0.04, 'x', ha='center')
|
2857
2888
|
plt.subplots_adjust(hspace=0.2)
|
2858
2889
|
|
@@ -52,7 +52,7 @@ siat/financials_test.py,sha256=HJ3CPo_Xckz2wXi3AEP6ZNWCF1Duc1pLi0Y10USiImc,23829
|
|
52
52
|
siat/fred_test.py,sha256=KF50ssSbsfpa_kT6iuomD0vG4eXztAcOasZxg1OGX5w,1201
|
53
53
|
siat/fund.py,sha256=wMDORsCBV8ZXfgwbtq-0bu3qqWY66dHnbqgllW0gWCo,24637
|
54
54
|
siat/fund_china.pickle,sha256=wJIIvEjWuZylcaQ3c5kvIdKedpFF5T53cJlG-1LVoms,2410657
|
55
|
-
siat/fund_china.py,sha256=
|
55
|
+
siat/fund_china.py,sha256=rPGnYSPkbZUqtBoJnxLZLIQ8MjD8vD3TovCMfletBP4,111839
|
56
56
|
siat/fund_china_test.py,sha256=-Bh6m0J0GPpIbYXx-H2vpzJoNFI6pE2C2jVPa8DazgE,6649
|
57
57
|
siat/fund_test.py,sha256=V4ADb8Gsp8gyeFTwcgRsJBpnUih_O-Q2V1ILc5oKjK8,1116
|
58
58
|
siat/future_china.py,sha256=F-HsIf2Op8Z22RzTjet1g8COzldgnMjFNSXsAkeGyWo,17595
|
@@ -67,7 +67,7 @@ siat/local_debug_test.py,sha256=CDAOffW1Rvs-TcNN5giWVvHMlch1w4dp-w5SIV9jXL0,3936
|
|
67
67
|
siat/market_china.py,sha256=nabx24qm7N51OafTrwUw542pNeFJ3JaQ1wqyv-nLN5I,37883
|
68
68
|
siat/markowitz.py,sha256=c06gCRhMABnrb30F-npJsKVv8nFfEoNNR3bzrkMCyGg,97406
|
69
69
|
siat/markowitz2-20240620.py,sha256=irZAPnjaatFsKQmFRMENP-cO6bEUl2narYtkU5NKTWI,108019
|
70
|
-
siat/markowitz2.py,sha256=
|
70
|
+
siat/markowitz2.py,sha256=yu3I90RQUxk8k8D7kCa7b0wNfckOjKWHQZNTUq8512o,110060
|
71
71
|
siat/markowitz_ccb_test.py,sha256=xBkkoaNHdq9KSUrNuHGgKTdNYUvgi84kNYcf719eoyE,1593
|
72
72
|
siat/markowitz_ef_test.py,sha256=wjNlICkgRIqnonPeSIHo4Mu2GRtb9dr21wDt2kMNEcI,4032
|
73
73
|
siat/markowitz_old.py,sha256=Lf7O_4QWT8RsdkHiUyc_7kKY3eZjKDtFR89Fz3pwYnY,33046
|
@@ -115,7 +115,7 @@ siat/stock_prices_kneighbors.py,sha256=WfZvo5EyeBsm-T37zDj7Sl9dPSRq5Bx4JxIJ9IUum
|
|
115
115
|
siat/stock_prices_linear.py,sha256=-OUKRr27L2aStQgJSlJOrJ4gay_G7P-m-7t7cU2Yoqk,13991
|
116
116
|
siat/stock_profile.py,sha256=B3eIwzEmiCqiCaxIlhfdEPsQBoW1PFOe1hkiY3mVF6Y,26038
|
117
117
|
siat/stock_technical-20240620.py,sha256=A4x18mZgYSA8SSiDz4u_O3gd5oVRgbI6JIiBfFY0tVw,116013
|
118
|
-
siat/stock_technical.py,sha256=
|
118
|
+
siat/stock_technical.py,sha256=I7AeesRFKAK_8MZcqtV1ppvnqsTZfQYgxU3iTAUzMiQ,122806
|
119
119
|
siat/stock_test.py,sha256=E9YJAvOw1VEGJSDI4IZuEjl0tGoisOIlN-g9UqA_IZE,19475
|
120
120
|
siat/stooq.py,sha256=dOc_S5HLrYg48YAKTCs1eX8UTJOOkPM8qLL2KupqlLY,2470
|
121
121
|
siat/temp.py,sha256=gbJ0ioauuo4koTPH6WKUkqcXiQPafnbhU5eKJ6lpdLA,1571
|
@@ -136,7 +136,7 @@ siat/valuation.py,sha256=NKfeZMdDJOW42oLVHob6eSVBXUqlN1OCnnzwyGAst8c,48855
|
|
136
136
|
siat/valuation_china.py,sha256=EkZQaVkoBjM0c4MCNbaX-bMnlG0e3FXeaWczZDnkptU,67784
|
137
137
|
siat/valuation_market_china_test.py,sha256=gbJ0ioauuo4koTPH6WKUkqcXiQPafnbhU5eKJ6lpdLA,1571
|
138
138
|
siat/var_model_validation.py,sha256=f-oDewg7bPzyNanz_Y_jLH68NowAA3gXFehW_weKGG0,14898
|
139
|
-
siat-3.2.
|
140
|
-
siat-3.2.
|
141
|
-
siat-3.2.
|
142
|
-
siat-3.2.
|
139
|
+
siat-3.2.3.dist-info/METADATA,sha256=GB36cl3udD6IE5Vaaah6WH_nNbjjruc60CRXLHwliB8,1447
|
140
|
+
siat-3.2.3.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
141
|
+
siat-3.2.3.dist-info/top_level.txt,sha256=r1cVyL7AIKqeAmEJjNR8FMT20OmEzufDstC2gv3NvEY,5
|
142
|
+
siat-3.2.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|