siat 3.10.132__py3-none-any.whl → 3.11.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/__init__.py +0 -0
- siat/allin.py +8 -0
- siat/assets_liquidity.py +0 -0
- siat/beta_adjustment.py +0 -0
- siat/beta_adjustment_china.py +0 -0
- siat/blockchain.py +0 -0
- siat/bond.py +0 -0
- siat/bond_base.py +0 -0
- siat/bond_china.py +0 -0
- siat/bond_zh_sina.py +0 -0
- siat/capm_beta.py +0 -0
- siat/capm_beta2.py +4 -4
- siat/common.py +9 -6
- siat/compare_cross.py +0 -0
- siat/copyrights.py +0 -0
- siat/cryptocurrency.py +0 -0
- siat/economy.py +0 -0
- siat/economy2.py +0 -0
- siat/esg.py +0 -0
- siat/event_study.py +0 -0
- siat/exchange_bond_china.pickle +0 -0
- siat/fama_french.py +0 -0
- siat/fin_stmt2_yahoo.py +0 -0
- siat/financial_base.py +0 -0
- siat/financial_statements.py +0 -0
- siat/financials.py +0 -0
- siat/financials2.py +0 -0
- siat/financials_china.py +0 -0
- siat/financials_china2.py +0 -0
- siat/fund.py +0 -0
- siat/fund_china.pickle +0 -0
- siat/fund_china.py +0 -0
- siat/future_china.py +0 -0
- siat/google_authenticator.py +0 -0
- siat/grafix.py +55 -4
- siat/holding_risk.py +0 -0
- siat/luchy_draw.py +0 -0
- siat/market_china.py +0 -0
- siat/markowitz.py +0 -0
- siat/markowitz2.py +1 -0
- siat/markowitz2_20250704.py +0 -0
- siat/markowitz2_20250705.py +0 -0
- siat/markowitz_simple.py +0 -0
- siat/ml_cases.py +0 -0
- siat/ml_cases_example.py +0 -0
- siat/option_china.py +0 -0
- siat/option_pricing.py +0 -0
- siat/other_indexes.py +0 -0
- siat/risk_adjusted_return.py +0 -0
- siat/risk_adjusted_return2.py +8 -4
- siat/risk_evaluation.py +0 -0
- siat/risk_free_rate.py +0 -0
- siat/save2docx.py +345 -0
- siat/save2pdf.py +145 -0
- siat/sector_china.py +0 -0
- siat/security_price2.py +0 -0
- siat/security_prices.py +168 -6
- siat/security_trend.py +0 -0
- siat/security_trend2.py +2 -2
- siat/stock.py +11 -1
- siat/stock_advice_linear.py +0 -0
- siat/stock_base.py +0 -0
- siat/stock_china.py +0 -0
- siat/stock_info.pickle +0 -0
- siat/stock_prices_kneighbors.py +0 -0
- siat/stock_prices_linear.py +0 -0
- siat/stock_profile.py +0 -0
- siat/stock_technical.py +0 -0
- siat/stooq.py +0 -0
- siat/transaction.py +0 -0
- siat/translate.py +0 -0
- siat/valuation.py +0 -0
- siat/valuation_china.py +0 -0
- siat/var_model_validation.py +0 -0
- siat/yf_name.py +0 -0
- {siat-3.10.132.dist-info/licenses → siat-3.11.1.dist-info}/LICENSE +0 -0
- {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/METADATA +234 -235
- siat-3.11.1.dist-info/RECORD +80 -0
- {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/WHEEL +1 -1
- {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/top_level.txt +0 -1
- build/lib/build/lib/siat/__init__.py +0 -75
- build/lib/build/lib/siat/allin.py +0 -137
- build/lib/build/lib/siat/assets_liquidity.py +0 -915
- build/lib/build/lib/siat/beta_adjustment.py +0 -1058
- build/lib/build/lib/siat/beta_adjustment_china.py +0 -548
- build/lib/build/lib/siat/blockchain.py +0 -143
- build/lib/build/lib/siat/bond.py +0 -2900
- build/lib/build/lib/siat/bond_base.py +0 -992
- build/lib/build/lib/siat/bond_china.py +0 -100
- build/lib/build/lib/siat/bond_zh_sina.py +0 -143
- build/lib/build/lib/siat/capm_beta.py +0 -783
- build/lib/build/lib/siat/capm_beta2.py +0 -887
- build/lib/build/lib/siat/common.py +0 -5360
- build/lib/build/lib/siat/compare_cross.py +0 -642
- build/lib/build/lib/siat/copyrights.py +0 -18
- build/lib/build/lib/siat/cryptocurrency.py +0 -667
- build/lib/build/lib/siat/economy.py +0 -1471
- build/lib/build/lib/siat/economy2.py +0 -1853
- build/lib/build/lib/siat/esg.py +0 -536
- build/lib/build/lib/siat/event_study.py +0 -815
- build/lib/build/lib/siat/fama_french.py +0 -1521
- build/lib/build/lib/siat/fin_stmt2_yahoo.py +0 -982
- build/lib/build/lib/siat/financial_base.py +0 -1160
- build/lib/build/lib/siat/financial_statements.py +0 -598
- build/lib/build/lib/siat/financials.py +0 -2339
- build/lib/build/lib/siat/financials2.py +0 -1278
- build/lib/build/lib/siat/financials_china.py +0 -4433
- build/lib/build/lib/siat/financials_china2.py +0 -2212
- build/lib/build/lib/siat/fund.py +0 -629
- build/lib/build/lib/siat/fund_china.py +0 -3307
- build/lib/build/lib/siat/future_china.py +0 -551
- build/lib/build/lib/siat/google_authenticator.py +0 -47
- build/lib/build/lib/siat/grafix.py +0 -3636
- build/lib/build/lib/siat/holding_risk.py +0 -867
- build/lib/build/lib/siat/luchy_draw.py +0 -638
- build/lib/build/lib/siat/market_china.py +0 -1168
- build/lib/build/lib/siat/markowitz.py +0 -2363
- build/lib/build/lib/siat/markowitz2.py +0 -3150
- build/lib/build/lib/siat/markowitz2_20250704.py +0 -2969
- build/lib/build/lib/siat/markowitz2_20250705.py +0 -3158
- build/lib/build/lib/siat/markowitz_simple.py +0 -373
- build/lib/build/lib/siat/ml_cases.py +0 -2291
- build/lib/build/lib/siat/ml_cases_example.py +0 -60
- build/lib/build/lib/siat/option_china.py +0 -3069
- build/lib/build/lib/siat/option_pricing.py +0 -1925
- build/lib/build/lib/siat/other_indexes.py +0 -409
- build/lib/build/lib/siat/risk_adjusted_return.py +0 -1576
- build/lib/build/lib/siat/risk_adjusted_return2.py +0 -1900
- build/lib/build/lib/siat/risk_evaluation.py +0 -2218
- build/lib/build/lib/siat/risk_free_rate.py +0 -351
- build/lib/build/lib/siat/sector_china.py +0 -4140
- build/lib/build/lib/siat/security_price2.py +0 -727
- build/lib/build/lib/siat/security_prices.py +0 -3408
- build/lib/build/lib/siat/security_trend.py +0 -402
- build/lib/build/lib/siat/security_trend2.py +0 -646
- build/lib/build/lib/siat/stock.py +0 -4284
- build/lib/build/lib/siat/stock_advice_linear.py +0 -934
- build/lib/build/lib/siat/stock_base.py +0 -26
- build/lib/build/lib/siat/stock_china.py +0 -2095
- build/lib/build/lib/siat/stock_prices_kneighbors.py +0 -910
- build/lib/build/lib/siat/stock_prices_linear.py +0 -386
- build/lib/build/lib/siat/stock_profile.py +0 -707
- build/lib/build/lib/siat/stock_technical.py +0 -3305
- build/lib/build/lib/siat/stooq.py +0 -74
- build/lib/build/lib/siat/transaction.py +0 -347
- build/lib/build/lib/siat/translate.py +0 -5183
- build/lib/build/lib/siat/valuation.py +0 -1378
- build/lib/build/lib/siat/valuation_china.py +0 -2076
- build/lib/build/lib/siat/var_model_validation.py +0 -444
- build/lib/build/lib/siat/yf_name.py +0 -811
- build/lib/siat/__init__.py +0 -75
- build/lib/siat/allin.py +0 -137
- build/lib/siat/assets_liquidity.py +0 -915
- build/lib/siat/beta_adjustment.py +0 -1058
- build/lib/siat/beta_adjustment_china.py +0 -548
- build/lib/siat/blockchain.py +0 -143
- build/lib/siat/bond.py +0 -2900
- build/lib/siat/bond_base.py +0 -992
- build/lib/siat/bond_china.py +0 -100
- build/lib/siat/bond_zh_sina.py +0 -143
- build/lib/siat/capm_beta.py +0 -783
- build/lib/siat/capm_beta2.py +0 -887
- build/lib/siat/common.py +0 -5360
- build/lib/siat/compare_cross.py +0 -642
- build/lib/siat/copyrights.py +0 -18
- build/lib/siat/cryptocurrency.py +0 -667
- build/lib/siat/economy.py +0 -1471
- build/lib/siat/economy2.py +0 -1853
- build/lib/siat/esg.py +0 -536
- build/lib/siat/event_study.py +0 -815
- build/lib/siat/fama_french.py +0 -1521
- build/lib/siat/fin_stmt2_yahoo.py +0 -982
- build/lib/siat/financial_base.py +0 -1160
- build/lib/siat/financial_statements.py +0 -598
- build/lib/siat/financials.py +0 -2339
- build/lib/siat/financials2.py +0 -1278
- build/lib/siat/financials_china.py +0 -4433
- build/lib/siat/financials_china2.py +0 -2212
- build/lib/siat/fund.py +0 -629
- build/lib/siat/fund_china.py +0 -3307
- build/lib/siat/future_china.py +0 -551
- build/lib/siat/google_authenticator.py +0 -47
- build/lib/siat/grafix.py +0 -3636
- build/lib/siat/holding_risk.py +0 -867
- build/lib/siat/luchy_draw.py +0 -638
- build/lib/siat/market_china.py +0 -1168
- build/lib/siat/markowitz.py +0 -2363
- build/lib/siat/markowitz2.py +0 -3150
- build/lib/siat/markowitz2_20250704.py +0 -2969
- build/lib/siat/markowitz2_20250705.py +0 -3158
- build/lib/siat/markowitz_simple.py +0 -373
- build/lib/siat/ml_cases.py +0 -2291
- build/lib/siat/ml_cases_example.py +0 -60
- build/lib/siat/option_china.py +0 -3069
- build/lib/siat/option_pricing.py +0 -1925
- build/lib/siat/other_indexes.py +0 -409
- build/lib/siat/risk_adjusted_return.py +0 -1576
- build/lib/siat/risk_adjusted_return2.py +0 -1900
- build/lib/siat/risk_evaluation.py +0 -2218
- build/lib/siat/risk_free_rate.py +0 -351
- build/lib/siat/sector_china.py +0 -4140
- build/lib/siat/security_price2.py +0 -727
- build/lib/siat/security_prices.py +0 -3408
- build/lib/siat/security_trend.py +0 -402
- build/lib/siat/security_trend2.py +0 -646
- build/lib/siat/stock.py +0 -4284
- build/lib/siat/stock_advice_linear.py +0 -934
- build/lib/siat/stock_base.py +0 -26
- build/lib/siat/stock_china.py +0 -2095
- build/lib/siat/stock_prices_kneighbors.py +0 -910
- build/lib/siat/stock_prices_linear.py +0 -386
- build/lib/siat/stock_profile.py +0 -707
- build/lib/siat/stock_technical.py +0 -3305
- build/lib/siat/stooq.py +0 -74
- build/lib/siat/transaction.py +0 -347
- build/lib/siat/translate.py +0 -5183
- build/lib/siat/valuation.py +0 -1378
- build/lib/siat/valuation_china.py +0 -2076
- build/lib/siat/var_model_validation.py +0 -444
- build/lib/siat/yf_name.py +0 -811
- siat-3.10.132.dist-info/RECORD +0 -218
siat/security_prices.py
CHANGED
@@ -571,7 +571,45 @@ if __name__=='__main__':
|
|
571
571
|
|
572
572
|
#有问题
|
573
573
|
cvt_stooq_ticker('002504.SZ')
|
574
|
-
|
574
|
+
#==============================================================================
|
575
|
+
if __name__=='__main__':
|
576
|
+
ticker='1YCNY.B'
|
577
|
+
|
578
|
+
market_RF("1YCNY.B")
|
579
|
+
|
580
|
+
def market_RF(ticker='1YCNY.B',start='MRW',end='today',printout=True):
|
581
|
+
"""
|
582
|
+
功能:获取一个经济体市场的无风险收益率,以国债收益率替代。
|
583
|
+
默认1年期国债收益率最近一周的均值
|
584
|
+
"""
|
585
|
+
start,end=start_end_preprocess(start,end)
|
586
|
+
|
587
|
+
#屏蔽函数内print信息输出的类
|
588
|
+
import os, sys
|
589
|
+
class HiddenPrints:
|
590
|
+
def __enter__(self):
|
591
|
+
self._original_stdout = sys.stdout
|
592
|
+
sys.stdout = open(os.devnull, 'w')
|
593
|
+
|
594
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
595
|
+
sys.stdout.close()
|
596
|
+
sys.stdout = self._original_stdout
|
597
|
+
|
598
|
+
with HiddenPrints():
|
599
|
+
RFdf=get_price_stooq(ticker,start=start,end=end)
|
600
|
+
|
601
|
+
if RFdf is None:
|
602
|
+
print(f" #Error(market_RF): yield {ticker} not found or unavailable in the period")
|
603
|
+
return None
|
604
|
+
|
605
|
+
RF=round(RFdf['Close'].mean()/100,6)
|
606
|
+
|
607
|
+
if printout:
|
608
|
+
print(f" {round(RF*100,4)}% in average from {start} to {end}")
|
609
|
+
|
610
|
+
return RF
|
611
|
+
|
612
|
+
#==============================================================================
|
575
613
|
|
576
614
|
if __name__=='__main__':
|
577
615
|
ticker='AAPL'
|
@@ -604,7 +642,7 @@ if __name__=='__main__':
|
|
604
642
|
|
605
643
|
p=get_price_stooq(ticker,start,end)
|
606
644
|
|
607
|
-
def get_price_stooq(ticker,start,end='today'):
|
645
|
+
def get_price_stooq(ticker,start='MRM',end='today'):
|
608
646
|
"""
|
609
647
|
从stooq抓取单个股价
|
610
648
|
"""
|
@@ -2451,12 +2489,14 @@ if __name__ =="__main__":
|
|
2451
2489
|
vdf=rolling_ret_volatility(retdf, period)
|
2452
2490
|
|
2453
2491
|
#==============================================================================
|
2454
|
-
def
|
2492
|
+
def expanding_ret_volatility_x(df0,basedate):
|
2455
2493
|
"""
|
2456
2494
|
功能:基于日收益率数据集,从起始日期basedate开始的收益率波动风险扩展窗口序列。
|
2457
2495
|
输入:
|
2458
2496
|
日收益率数据集df。
|
2459
2497
|
输出:扩展调整收益率波动风险序列,按照日期升序排列。
|
2498
|
+
|
2499
|
+
注意:可能存在计算错误,暂时废弃!!!
|
2460
2500
|
"""
|
2461
2501
|
df0["Daily Ret"]=df0['Close'].pct_change()
|
2462
2502
|
df0["Daily Adj Ret"]=df0['Adj Close'].pct_change()
|
@@ -2485,6 +2525,59 @@ def expanding_ret_volatility(df0,basedate):
|
|
2485
2525
|
|
2486
2526
|
return df
|
2487
2527
|
|
2528
|
+
#==============================================================================
|
2529
|
+
def expanding_ret_volatility(df0,basedate,min_periods=1):
|
2530
|
+
"""
|
2531
|
+
功能:基于日收益率数据集,从起始日期basedate开始的收益率波动风险扩展窗口序列。
|
2532
|
+
输入:
|
2533
|
+
日收益率数据集df。
|
2534
|
+
输出:扩展调整收益率波动风险序列,按照日期升序排列。
|
2535
|
+
|
2536
|
+
新算法:解决开始部分过度波动问题
|
2537
|
+
"""
|
2538
|
+
collist=list(df0)
|
2539
|
+
|
2540
|
+
if not ("Daily Ret" in collist):
|
2541
|
+
df0["Daily Ret"]=df0['Close'].pct_change()
|
2542
|
+
#df0["Daily Ret"]=df0["Daily Ret"].fillna(method='bfill', axis=1)
|
2543
|
+
df0["Daily Ret"]=df0["Daily Ret"].interpolate()
|
2544
|
+
|
2545
|
+
if not ("Daily Adj Ret" in collist):
|
2546
|
+
df0["Daily Adj Ret"]=df0['Adj Close'].pct_change()
|
2547
|
+
#df0["Daily Adj Ret"]=df0["Daily Adj Ret"].fillna(method='bfill', axis=1)
|
2548
|
+
df0["Daily Adj Ret"]=df0["Daily Adj Ret"].interpolate()
|
2549
|
+
|
2550
|
+
import pandas as pd
|
2551
|
+
basedate_pd=pd.to_datetime(basedate)
|
2552
|
+
df=df0[df0.index >= basedate_pd]
|
2553
|
+
|
2554
|
+
# 计算Exp Ret和Exp Adj Ret
|
2555
|
+
if not ('Exp Ret' in collist):
|
2556
|
+
df['Exp Ret'] = (1 + df['Daily Ret']).cumprod() - 1
|
2557
|
+
df['Exp Ret%'] = df['Exp Ret'] * 100.0
|
2558
|
+
|
2559
|
+
if not ('Exp Adj Ret' in collist):
|
2560
|
+
df['Exp Adj Ret'] = (1 + df['Daily Adj Ret']).cumprod() - 1
|
2561
|
+
df['Exp Adj Ret%'] = df['Exp Adj Ret'] * 100.0
|
2562
|
+
|
2563
|
+
#计算扩展窗口调整收益率波动风险:基于普通收益率
|
2564
|
+
retname1="Exp Ret Volatility"
|
2565
|
+
retname2="Exp Ret Volatility%"
|
2566
|
+
#import numpy as np
|
2567
|
+
|
2568
|
+
#df[retname1]=df["Exp Ret"].expanding(min_periods=min_periods).std(ddof=1)
|
2569
|
+
df[retname1]=df["Exp Ret"].expanding().std(ddof=1)
|
2570
|
+
df[retname2]=df[retname1]*100.0
|
2571
|
+
|
2572
|
+
#计算扩展窗口调整收益率风险:基于调整收益率
|
2573
|
+
retname3="Exp Adj Ret Volatility"
|
2574
|
+
retname4="Exp Adj Ret Volatility%"
|
2575
|
+
#df[retname3]=df["Exp Adj Ret"].expanding(min_periods=min_periods).std(ddof=1)
|
2576
|
+
df[retname3]=df["Exp Adj Ret"].expanding().std(ddof=1)
|
2577
|
+
df[retname4]=df[retname3]*100.0
|
2578
|
+
|
2579
|
+
return df
|
2580
|
+
|
2488
2581
|
if __name__ =="__main__":
|
2489
2582
|
basedate='2019-1-1'
|
2490
2583
|
pricedf=get_price('000002.SZ','2018-1-1','2020-3-16')
|
@@ -2526,6 +2619,16 @@ if __name__ =="__main__":
|
|
2526
2619
|
df=get_price("000002.SZ","2020-1-1","2020-3-16")
|
2527
2620
|
print(lpsd(df['Close']))
|
2528
2621
|
|
2622
|
+
import numpy as np
|
2623
|
+
|
2624
|
+
def downside_std(returns, target_return=0):
|
2625
|
+
"""
|
2626
|
+
功能:计算下偏标准差(下方风险)
|
2627
|
+
注意:暂时弃用,因为容易引起float divided zero问题。
|
2628
|
+
"""
|
2629
|
+
downside_diff = np.maximum(target_return - returns, 0)
|
2630
|
+
return np.sqrt(np.mean(downside_diff ** 2))
|
2631
|
+
|
2529
2632
|
#==============================================================================
|
2530
2633
|
def rolling_ret_lpsd(df, period="Weekly"):
|
2531
2634
|
"""
|
@@ -2551,6 +2654,7 @@ def rolling_ret_lpsd(df, period="Weekly"):
|
|
2551
2654
|
retname2=retname1+'%'
|
2552
2655
|
#import numpy as np
|
2553
2656
|
df[retname1]=df[periodret].rolling(rollingnum,min_periods=1).apply(lambda x: lpsd(x))
|
2657
|
+
#df[retname1]=df[periodret].rolling(rollingnum,min_periods=1).apply(downside_std, raw=True)
|
2554
2658
|
df[retname2]=df[retname1]*100.0
|
2555
2659
|
|
2556
2660
|
#计算滚动下偏标准差:基于调整收益率
|
@@ -2558,6 +2662,7 @@ def rolling_ret_lpsd(df, period="Weekly"):
|
|
2558
2662
|
retname3=period+" Adj Ret LPSD"
|
2559
2663
|
retname4=retname3+'%'
|
2560
2664
|
df[retname3]=df[periodadjret].rolling(rollingnum,min_periods=1).apply(lambda x: lpsd(x))
|
2665
|
+
#df[retname3]=df[periodadjret].rolling(rollingnum,min_periods=1).apply(downside_std, raw=True)
|
2561
2666
|
df[retname4]=df[retname3]*100.0
|
2562
2667
|
|
2563
2668
|
return df
|
@@ -2569,12 +2674,14 @@ if __name__ =="__main__":
|
|
2569
2674
|
vdf=rolling_ret_lpsd(retdf, period)
|
2570
2675
|
|
2571
2676
|
#==============================================================================
|
2572
|
-
def
|
2677
|
+
def expanding_ret_lpsd_x(df0,basedate,min_periods=1):
|
2573
2678
|
"""
|
2574
2679
|
功能:基于日收益率数据集,从起始日期basedate开始的收益率损失风险扩展窗口序列。
|
2575
2680
|
输入:
|
2576
2681
|
日收益率数据集df。
|
2577
2682
|
输出:扩展调整收益率波动风险序列,按照日期升序排列。
|
2683
|
+
|
2684
|
+
注意:算法可能存在错误,暂时废弃!!!
|
2578
2685
|
"""
|
2579
2686
|
df0["Daily Ret"]=df0['Close'].pct_change()
|
2580
2687
|
df0["Daily Adj Ret"]=df0['Adj Close'].pct_change()
|
@@ -2588,7 +2695,7 @@ def expanding_ret_lpsd(df0,basedate):
|
|
2588
2695
|
retname2=retname1+'%'
|
2589
2696
|
import numpy as np
|
2590
2697
|
#df[retname1]=df["Daily Ret"].expanding(min_periods=1).apply(lambda x: lpsd(x)*np.sqrt(len(x)))
|
2591
|
-
df[retname1]=df["Daily Ret"].expanding(min_periods=
|
2698
|
+
df[retname1]=df["Daily Ret"].expanding(min_periods=min_periods).apply(lambda x: lpsd(x))
|
2592
2699
|
#df[retname1]=df["Daily Ret"].expanding(min_periods=5).apply(lambda x: lpsd(x))
|
2593
2700
|
df[retname2]=df[retname1]*100.0
|
2594
2701
|
|
@@ -2596,12 +2703,67 @@ def expanding_ret_lpsd(df0,basedate):
|
|
2596
2703
|
retname3="Exp Adj Ret LPSD"
|
2597
2704
|
retname4=retname3+'%'
|
2598
2705
|
#df[retname3]=df["Daily Adj Ret"].expanding(min_periods=1).apply(lambda x: lpsd(x)*np.sqrt(len(x)))
|
2599
|
-
df[retname3]=df["Daily Adj Ret"].expanding(min_periods=
|
2706
|
+
df[retname3]=df["Daily Adj Ret"].expanding(min_periods=min_periods).apply(lambda x: lpsd(x))
|
2600
2707
|
#df[retname3]=df["Daily Adj Ret"].expanding(min_periods=5).apply(lambda x: lpsd(x))
|
2601
2708
|
df[retname4]=df[retname3]*100.0
|
2602
2709
|
|
2603
2710
|
return df
|
2604
2711
|
|
2712
|
+
#==============================================================================
|
2713
|
+
def expanding_ret_lpsd(df0,basedate,min_periods=1):
|
2714
|
+
"""
|
2715
|
+
功能:基于日收益率数据集,从起始日期basedate开始的收益率损失风险扩展窗口序列。
|
2716
|
+
输入:
|
2717
|
+
日收益率数据集df。
|
2718
|
+
输出:扩展调整收益率波动风险序列,按照日期升序排列。
|
2719
|
+
|
2720
|
+
新算法:解决开始部分过度波动的诡异现象
|
2721
|
+
"""
|
2722
|
+
collist=list(df0)
|
2723
|
+
|
2724
|
+
if not ("Daily Ret" in collist):
|
2725
|
+
df0["Daily Ret"]=df0['Close'].pct_change()
|
2726
|
+
#df0["Daily Ret"]=df0["Daily Ret"].fillna(method='bfill', axis=1)
|
2727
|
+
df0["Daily Ret"]=df0["Daily Ret"].interpolate()
|
2728
|
+
|
2729
|
+
if not ("Daily Adj Ret" in collist):
|
2730
|
+
df0["Daily Adj Ret"]=df0['Adj Close'].pct_change()
|
2731
|
+
#df0["Daily Adj Ret"]=df0["Daily Adj Ret"].fillna(method='bfill', axis=1)
|
2732
|
+
df0["Daily Adj Ret"]=df0["Daily Adj Ret"].interpolate()
|
2733
|
+
|
2734
|
+
import pandas as pd
|
2735
|
+
basedate_pd=pd.to_datetime(basedate)
|
2736
|
+
df=df0[df0.index >= basedate_pd]
|
2737
|
+
|
2738
|
+
# 计算Exp Ret和Exp Adj Ret
|
2739
|
+
if not ('Exp Ret' in collist):
|
2740
|
+
df['Exp Ret'] = (1 + df['Daily Ret']).cumprod() - 1
|
2741
|
+
df['Exp Ret%'] = df['Exp Ret'] * 100.0
|
2742
|
+
|
2743
|
+
if not ('Exp Adj Ret' in collist):
|
2744
|
+
df['Exp Adj Ret'] = (1 + df['Daily Adj Ret']).cumprod() - 1
|
2745
|
+
df['Exp Adj Ret%'] = df['Exp Adj Ret'] * 100.0
|
2746
|
+
|
2747
|
+
#计算扩展窗口调整收益率下偏标准差:基于普通收益率
|
2748
|
+
retname1="Exp Ret LPSD"
|
2749
|
+
retname2=retname1+'%'
|
2750
|
+
import numpy as np
|
2751
|
+
#df[retname1]=df["Exp Ret"].expanding(min_periods=min_periods).apply(lambda x: lpsd(x))
|
2752
|
+
df[retname1]=df["Exp Ret"].expanding().apply(lambda x: lpsd(x))
|
2753
|
+
#df[retname1]=df["Exp Ret"].expanding().apply(downside_std, raw=True)
|
2754
|
+
df[retname2]=df[retname1]*100.0
|
2755
|
+
|
2756
|
+
#计算扩展窗口调整下偏标准差:基于调整收益率
|
2757
|
+
retname3="Exp Adj Ret LPSD"
|
2758
|
+
retname4=retname3+'%'
|
2759
|
+
#df[retname3]=df["Exp Adj Ret"].expanding(min_periods=min_periods).apply(lambda x: lpsd(x))
|
2760
|
+
df[retname3]=df["Exp Adj Ret"].expanding().apply(lambda x: lpsd(x))
|
2761
|
+
#df[retname3]=df["Exp Adj Ret"].expanding().apply(downside_std, raw=True)
|
2762
|
+
df[retname4]=df[retname3]*100.0
|
2763
|
+
|
2764
|
+
return df
|
2765
|
+
|
2766
|
+
|
2605
2767
|
if __name__ =="__main__":
|
2606
2768
|
basedate='2019-1-1'
|
2607
2769
|
pricedf=get_price('000002.SZ','2018-1-1','2020-3-16')
|
siat/security_trend.py
CHANGED
File without changes
|
siat/security_trend2.py
CHANGED
@@ -575,7 +575,7 @@ def security_trend(ticker,indicator='Close',adjust='', \
|
|
575
575
|
attention_value=attention_value,attention_value_area=attention_value_area, \
|
576
576
|
attention_point=attention_point,attention_point_area=attention_point_area, \
|
577
577
|
band_area=band_area, \
|
578
|
-
graph=graph,axhline_value=0,axhline_label='', \
|
578
|
+
graph=graph,axhline_value=0,axhline_label='',power=power, \
|
579
579
|
loc1=loc1, \
|
580
580
|
printout=printout, \
|
581
581
|
sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
|
@@ -599,7 +599,7 @@ def security_trend(ticker,indicator='Close',adjust='', \
|
|
599
599
|
attention_value=attention_value,attention_value_area=attention_value_area, \
|
600
600
|
attention_point=attention_point,attention_point_area=attention_point_area, \
|
601
601
|
band_area=band_area, \
|
602
|
-
graph=graph,facecolor=facecolor,loc=loc1, \
|
602
|
+
graph=graph,facecolor=facecolor,loc=loc1,power=power, \
|
603
603
|
annotate=annotate,annotate_value=annotate_value, \
|
604
604
|
mark_top=mark_top,mark_bottom=mark_bottom, \
|
605
605
|
mark_start=mark_start,mark_end=mark_end, \
|
siat/stock.py
CHANGED
@@ -566,13 +566,18 @@ def all_calculate(pricedf,ticker1,fromdate,todate,ticker_type='auto'):
|
|
566
566
|
|
567
567
|
# 横向拼接合并
|
568
568
|
result=pd.concat([df1a,df1b,df1c,df1d],axis=1,join='outer')
|
569
|
+
# 合并后产生的重复字段仅保留第一次出现的
|
570
|
+
result3 = result.loc[:, ~result.columns.duplicated(keep='first')]
|
571
|
+
|
569
572
|
|
570
573
|
# 去掉重复的列,但要避免仅仅因为数值相同而去掉有用的列,比如误删'Close'列
|
574
|
+
"""
|
571
575
|
result1=result.T
|
572
576
|
result1['item']=result1.index #在行中增加临时列名,避免误删
|
573
577
|
result2=result1.drop_duplicates(subset=None,keep='first',ignore_index=False)
|
574
578
|
result2.drop("item", axis=1, inplace=True) #去掉临时列名
|
575
579
|
result3=result2.T
|
580
|
+
"""
|
576
581
|
|
577
582
|
return result3
|
578
583
|
|
@@ -649,7 +654,12 @@ if __name__ =="__main__":
|
|
649
654
|
indicator='Close'
|
650
655
|
fromdate='2025-1-1'; todate='2025-6-15'
|
651
656
|
|
652
|
-
|
657
|
+
# 测试组9
|
658
|
+
ticker='JD'
|
659
|
+
indicator='Exp Ret%'
|
660
|
+
fromdate='2025-4-1'; todate='2025-6-30'
|
661
|
+
|
662
|
+
zeroline=False; adjust=''
|
653
663
|
attention_value='';attention_value_area=''
|
654
664
|
attention_point='';attention_point_area=''
|
655
665
|
average_value=False
|
siat/stock_advice_linear.py
CHANGED
File without changes
|
siat/stock_base.py
CHANGED
File without changes
|
siat/stock_china.py
CHANGED
File without changes
|
siat/stock_info.pickle
CHANGED
File without changes
|
siat/stock_prices_kneighbors.py
CHANGED
File without changes
|
siat/stock_prices_linear.py
CHANGED
File without changes
|
siat/stock_profile.py
CHANGED
File without changes
|
siat/stock_technical.py
CHANGED
File without changes
|
siat/stooq.py
CHANGED
File without changes
|
siat/transaction.py
CHANGED
File without changes
|
siat/translate.py
CHANGED
File without changes
|
siat/valuation.py
CHANGED
File without changes
|
siat/valuation_china.py
CHANGED
File without changes
|
siat/var_model_validation.py
CHANGED
File without changes
|
siat/yf_name.py
CHANGED
File without changes
|
File without changes
|