siat 3.10.132__py3-none-any.whl → 3.10.133__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 +0 -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 +0 -0
- 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 +0 -0
- 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 +0 -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 +0 -0
- siat/risk_evaluation.py +0 -0
- siat/risk_free_rate.py +0 -0
- siat/sector_china.py +0 -0
- siat/security_price2.py +0 -0
- siat/security_prices.py +40 -2
- siat/security_trend.py +0 -0
- siat/security_trend2.py +0 -0
- siat/stock.py +0 -0
- 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.10.133.dist-info}/LICENSE +0 -0
- {siat-3.10.132.dist-info → siat-3.10.133.dist-info}/METADATA +232 -235
- siat-3.10.133.dist-info/RECORD +78 -0
- {siat-3.10.132.dist-info → siat-3.10.133.dist-info}/WHEEL +1 -1
- {siat-3.10.132.dist-info → siat-3.10.133.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
build/lib/siat/stooq.py
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
from pandas_datareader.base import _DailyBaseReader
|
2
|
-
|
3
|
-
|
4
|
-
class StooqDailyReader(_DailyBaseReader):
|
5
|
-
|
6
|
-
"""
|
7
|
-
Returns DataFrame/dict of Dataframes of historical stock prices from
|
8
|
-
symbols, over date range, start to end.
|
9
|
-
|
10
|
-
Parameters
|
11
|
-
----------
|
12
|
-
symbols : string, array-like object (list, tuple, Series), or DataFrame
|
13
|
-
Single stock symbol (ticker), array-like object of symbols or
|
14
|
-
DataFrame with index containing stock symbols.
|
15
|
-
start : string, int, date, datetime, Timestamp
|
16
|
-
Starting date. Parses many different kind of date
|
17
|
-
representations (e.g., 'JAN-01-2010', '1/1/10', 'Jan, 1, 1980'). Defaults to
|
18
|
-
20 years before current date.
|
19
|
-
end : string, int, date, datetime, Timestamp
|
20
|
-
Ending date
|
21
|
-
retry_count : int, default 3
|
22
|
-
Number of times to retry query request.
|
23
|
-
pause : int, default 0.1
|
24
|
-
Time, in seconds, to pause between consecutive queries of chunks. If
|
25
|
-
single value given for symbol, represents the pause between retries.
|
26
|
-
chunksize : int, default 25
|
27
|
-
Number of symbols to download consecutively before initiating pause.
|
28
|
-
session : Session, default None
|
29
|
-
requests.sessions.Session instance to be used
|
30
|
-
freq: string, d, w, m ,q, y for daily, weekly, monthly, quarterly, yearly
|
31
|
-
|
32
|
-
Notes
|
33
|
-
-----
|
34
|
-
See `Stooq <https://stooq.com>`__
|
35
|
-
"""
|
36
|
-
|
37
|
-
@property
|
38
|
-
def url(self):
|
39
|
-
"""API URL"""
|
40
|
-
return "https://stooq.com/q/d/l/"
|
41
|
-
|
42
|
-
def _get_params(self, symbol, country="US"):
|
43
|
-
symbol_parts = symbol.split(".")
|
44
|
-
if not symbol.startswith("^"):
|
45
|
-
if len(symbol_parts) == 1: #若symbol中不含后缀,不再自动加后缀.US
|
46
|
-
pass
|
47
|
-
#symbol = ".".join([symbol, country])
|
48
|
-
elif symbol_parts[1].lower() == "pl": #后缀为波兰
|
49
|
-
#pass
|
50
|
-
symbol = symbol_parts[0]
|
51
|
-
else:
|
52
|
-
#pass
|
53
|
-
if symbol_parts[1].lower() not in [
|
54
|
-
"de",
|
55
|
-
"hk",
|
56
|
-
"hu",
|
57
|
-
"jp",
|
58
|
-
"uk",
|
59
|
-
"us",
|
60
|
-
"f",
|
61
|
-
"b",
|
62
|
-
"m",
|
63
|
-
"cn",
|
64
|
-
]:
|
65
|
-
symbol = ".".join([symbol, "US"])
|
66
|
-
|
67
|
-
params = {
|
68
|
-
"s": symbol,
|
69
|
-
"i": self.freq or "d",
|
70
|
-
"d1": self.start.strftime("%Y%m%d"),
|
71
|
-
"d2": self.end.strftime("%Y%m%d"),
|
72
|
-
}
|
73
|
-
|
74
|
-
return params
|
build/lib/siat/transaction.py
DELETED
@@ -1,347 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
"""
|
3
|
-
本模块功能:为维持兼容性,套壳stock的模块
|
4
|
-
所属工具包:证券投资分析工具SIAT
|
5
|
-
SIAT:Security Investment Analysis Tool
|
6
|
-
创建日期:2021年5月16日
|
7
|
-
最新修订日期:
|
8
|
-
作者:王德宏 (WANG Dehong, Peter)
|
9
|
-
作者单位:北京外国语大学国际商学院
|
10
|
-
作者邮件:wdehong2000@163.com
|
11
|
-
版权所有:王德宏
|
12
|
-
用途限制:仅限研究与教学使用,不可商用!商用需要额外授权。
|
13
|
-
特别声明:作者不对使用本工具进行证券投资导致的任何损益负责!
|
14
|
-
"""
|
15
|
-
#==============================================================================
|
16
|
-
#屏蔽所有警告性信息
|
17
|
-
import warnings; warnings.filterwarnings('ignore')
|
18
|
-
#==============================================================================
|
19
|
-
from siat.common import *
|
20
|
-
from siat.translate import *
|
21
|
-
from siat.grafix import *
|
22
|
-
from siat.security_prices import *
|
23
|
-
from siat.security_price2 import *
|
24
|
-
|
25
|
-
# 复制股票分析函数
|
26
|
-
from siat.stock import *
|
27
|
-
#==============================================================================
|
28
|
-
#==============================================================================
|
29
|
-
#==============================================================================
|
30
|
-
# 功能:灵活比较证券指标:先获取收盘价,再行计算、比较和绘图
|
31
|
-
# 特点1:比compare_security更灵活,可处理债券指数与股票指数的比较
|
32
|
-
# 特点2:可处理短期国债与长期国债的收益率,模拟短期和长期无风险收益率
|
33
|
-
#==============================================================================
|
34
|
-
if __name__=='__main__':
|
35
|
-
df1=get_prices('000300.SS','2018-1-1','2020-12-31')
|
36
|
-
|
37
|
-
from siat.bond import *
|
38
|
-
df2=bond_prices_china('中债-综合指数','2018-1-1','2020-12-31',graph=False)
|
39
|
-
|
40
|
-
indicator='Annual Ret%'
|
41
|
-
fromdate='2019-7-1'
|
42
|
-
todate='2020-6-30'
|
43
|
-
graph=True
|
44
|
-
power=0
|
45
|
-
zeroline=True
|
46
|
-
twinx=False
|
47
|
-
|
48
|
-
def compare_indicator(df1,df2,indicator,fromdate,todate, \
|
49
|
-
graph=True,power=0,zeroline=True, \
|
50
|
-
twinx=False,loc1='upper left',loc2='lower left'):
|
51
|
-
"""
|
52
|
-
功能:基于两个数据表df1/df2中的列Close/Adj Close计算指标indicator,绘图比较
|
53
|
-
输入要求:数据表df1/df2中需要,索引为datetime,Close, Adj Close,ticker,source和footnote
|
54
|
-
当footnote为空时不需要显示
|
55
|
-
"""
|
56
|
-
#检查日期期间
|
57
|
-
result,start,end=check_period(fromdate,todate)
|
58
|
-
if not result:
|
59
|
-
print(" #Error(compare_indicator): invalid date period from",fromdate,'to',todate)
|
60
|
-
if graph: return
|
61
|
-
else: return None
|
62
|
-
|
63
|
-
#检查是否支持该indicator
|
64
|
-
indlist=['Close','Adj Close','Daily Ret','Daily Ret%','Daily Adj Ret','Daily Adj Ret%',
|
65
|
-
'log(Daily Ret)','log(Daily Adj Ret)','Weekly Ret','Weekly Ret%',
|
66
|
-
'Weekly Adj Ret','Weekly Adj Ret%','Monthly Ret','Monthly Ret%',
|
67
|
-
'Monthly Adj Ret','Monthly Adj Ret%','Quarterly Ret','Quarterly Ret%',
|
68
|
-
'Quarterly Adj Ret','Quarterly Adj Ret%','Annual Ret','Annual Ret%',
|
69
|
-
'Annual Adj Ret','Annual Adj Ret%','Exp Ret','Exp Ret%','Exp Adj Ret',
|
70
|
-
'Exp Adj Ret%','Weekly Price Volatility','Weekly Adj Price Volatility',
|
71
|
-
'Monthly Price Volatility','Monthly Adj Price Volatility',
|
72
|
-
'Quarterly Price Volatility','Quarterly Adj Price Volatility',
|
73
|
-
'Annual Price Volatility','Annual Adj Price Volatility',
|
74
|
-
'Exp Price Volatility','Exp Adj Price Volatility',
|
75
|
-
'Weekly Ret Volatility','Weekly Ret Volatility%',
|
76
|
-
'Weekly Adj Ret Volatility','Weekly Adj Ret Volatility%',
|
77
|
-
'Monthly Ret Volatility', 'Monthly Ret Volatility%',
|
78
|
-
'Monthly Adj Ret Volatility', 'Monthly Adj Ret Volatility%',
|
79
|
-
'Quarterly Ret Volatility', 'Quarterly Ret Volatility%',
|
80
|
-
'Quarterly Adj Ret Volatility', 'Quarterly Adj Ret Volatility%',
|
81
|
-
'Annual Ret Volatility', 'Annual Ret Volatility%',
|
82
|
-
'Annual Adj Ret Volatility', 'Annual Adj Ret Volatility%',
|
83
|
-
'Exp Ret Volatility', 'Exp Ret Volatility%', 'Exp Adj Ret Volatility',
|
84
|
-
'Exp Adj Ret Volatility%', 'Weekly Ret LPSD', 'Weekly Ret LPSD%',
|
85
|
-
'Weekly Adj Ret LPSD', 'Weekly Adj Ret LPSD%', 'Monthly Ret LPSD',
|
86
|
-
'Monthly Ret LPSD%', 'Monthly Adj Ret LPSD', 'Monthly Adj Ret LPSD%',
|
87
|
-
'Quarterly Ret LPSD', 'Quarterly Ret LPSD%', 'Quarterly Adj Ret LPSD',
|
88
|
-
'Quarterly Adj Ret LPSD%', 'Annual Ret LPSD', 'Annual Ret LPSD%',
|
89
|
-
'Annual Adj Ret LPSD', 'Annual Adj Ret LPSD%', 'Exp Ret LPSD',
|
90
|
-
'Exp Ret LPSD%', 'Exp Adj Ret LPSD', 'Exp Adj Ret LPSD%']
|
91
|
-
if indicator not in indlist:
|
92
|
-
print(" #Error(compare_indicator): unsupported indicator",indicator)
|
93
|
-
print(" Supported indicators:",indlist)
|
94
|
-
if graph: return
|
95
|
-
else: return None
|
96
|
-
|
97
|
-
print(" Calculating indicators ......")
|
98
|
-
#计算df1中的indicator
|
99
|
-
df1i=calc_indicators(df1,indicator)
|
100
|
-
df1i1=df1i[df1i.index >=start]
|
101
|
-
df1i2=df1i1[df1i1.index <= end]
|
102
|
-
|
103
|
-
#计算df2中的indicator
|
104
|
-
df2i=calc_indicators(df2,indicator)
|
105
|
-
df2i1=df2i[df2i.index >=start]
|
106
|
-
df2i2=df2i1[df2i1.index <= end]
|
107
|
-
|
108
|
-
#绘图
|
109
|
-
ticker1=ticker_name(df1i2['ticker'][0])
|
110
|
-
colname1=indicator
|
111
|
-
label1=ectranslate(indicator)
|
112
|
-
|
113
|
-
ticker2=ticker_name(df2i2['ticker'][0])
|
114
|
-
colname2=indicator
|
115
|
-
label2=ectranslate(indicator)
|
116
|
-
|
117
|
-
ylabeltxt=label1
|
118
|
-
titletxt="证券指标走势比较"
|
119
|
-
|
120
|
-
note=''
|
121
|
-
note1=df1i2['footnote'][0]
|
122
|
-
if note1 != '':
|
123
|
-
#note="证券1:"+note1
|
124
|
-
note=note1
|
125
|
-
note2=df2i2['footnote'][0]
|
126
|
-
if note2 != '':
|
127
|
-
#note=note+",证券2:"+note2
|
128
|
-
note=note+";"+note2
|
129
|
-
if note != '':
|
130
|
-
note=note+'\n'
|
131
|
-
|
132
|
-
source1=df1i2['source'][0]
|
133
|
-
source2=df2i2['source'][0]
|
134
|
-
if source1 == source2:
|
135
|
-
source=source1
|
136
|
-
else:
|
137
|
-
source=source1+','+source2
|
138
|
-
|
139
|
-
import datetime
|
140
|
-
today = datetime.date.today().strftime("%Y-%m-%d")
|
141
|
-
source="数据来源:"+source+','+today
|
142
|
-
|
143
|
-
footnote=''
|
144
|
-
if note != '':
|
145
|
-
footnote=note+source
|
146
|
-
else:
|
147
|
-
footnote=source
|
148
|
-
|
149
|
-
plot_line2(df1i2,ticker1,colname1,label1, \
|
150
|
-
df2i2,ticker2,colname2,label2, \
|
151
|
-
ylabeltxt,titletxt,footnote, \
|
152
|
-
power=power,zeroline=zeroline, \
|
153
|
-
twinx=twinx,loc1=loc1,loc2=loc2)
|
154
|
-
|
155
|
-
if graph: return
|
156
|
-
else: return df1i2,df2i2
|
157
|
-
|
158
|
-
if __name__=='__main__':
|
159
|
-
compare_indicator(df1,df2,'Annual Ret%','2019-7-1','2020-6-30')
|
160
|
-
compare_indicator(df1,df2,'Annual Ret Volatility%','2019-7-1','2020-6-30')
|
161
|
-
|
162
|
-
from siat.bond import *
|
163
|
-
search_bond_index_china(keystr='国债',printout=True)
|
164
|
-
df1=bond_index_china('中债-0-1年国债指数','2018-1-1','2020-12-31',graph=False)
|
165
|
-
df2=bond_index_china('中债-10年期国债指数','2018-1-1','2020-12-31',graph=False)
|
166
|
-
compare_indicator(df1,df2,'Annual Ret%','2019-7-1','2020-6-30')
|
167
|
-
compare_indicator(df1,df2,'Annual Ret Volatility%','2019-7-1','2020-6-30')
|
168
|
-
compare_indicator(df1,df2,'Exp Ret%','2019-7-1','2020-6-30')
|
169
|
-
|
170
|
-
|
171
|
-
#==============================================================================
|
172
|
-
if __name__=='__main__':
|
173
|
-
from siat.bond import *
|
174
|
-
search_bond_index_china(keystr='国债',printout=True)
|
175
|
-
df1=bond_index_china('中债-10年期国债指数','2018-1-1','2020-12-31',graph=False)
|
176
|
-
|
177
|
-
indicator='Annual Ret%'
|
178
|
-
fromdate='2019-7-1'
|
179
|
-
todate='2020-6-30'
|
180
|
-
graph=True
|
181
|
-
power=0
|
182
|
-
zeroline=True
|
183
|
-
twinx=False
|
184
|
-
|
185
|
-
def draw_indicator(df1,indicator,fromdate,todate, \
|
186
|
-
graph=True,power=0,zeroline=True):
|
187
|
-
"""
|
188
|
-
功能:基于单个数据表df1中的列Close/Adj Close计算指标indicator,绘图
|
189
|
-
输入要求:数据表df1中需要,索引为datetime,Close, Adj Close,ticker和footnote
|
190
|
-
当footnote为空时不需要显示
|
191
|
-
"""
|
192
|
-
#检查日期期间
|
193
|
-
result,start,end=check_period(fromdate,todate)
|
194
|
-
if not result:
|
195
|
-
print(" #Error(calc_indicator): invalid date period from",fromdate,'to',todate)
|
196
|
-
if graph: return
|
197
|
-
else: return None
|
198
|
-
|
199
|
-
#检查是否支持该indicator
|
200
|
-
indlist=['Close','Adj Close','Daily Ret','Daily Ret%','Daily Adj Ret','Daily Adj Ret%',
|
201
|
-
'log(Daily Ret)','log(Daily Adj Ret)','Weekly Ret','Weekly Ret%',
|
202
|
-
'Weekly Adj Ret','Weekly Adj Ret%','Monthly Ret','Monthly Ret%',
|
203
|
-
'Monthly Adj Ret','Monthly Adj Ret%','Quarterly Ret','Quarterly Ret%',
|
204
|
-
'Quarterly Adj Ret','Quarterly Adj Ret%','Annual Ret','Annual Ret%',
|
205
|
-
'Annual Adj Ret','Annual Adj Ret%','Exp Ret','Exp Ret%','Exp Adj Ret',
|
206
|
-
'Exp Adj Ret%','Weekly Price Volatility','Weekly Adj Price Volatility',
|
207
|
-
'Monthly Price Volatility','Monthly Adj Price Volatility',
|
208
|
-
'Quarterly Price Volatility','Quarterly Adj Price Volatility',
|
209
|
-
'Annual Price Volatility','Annual Adj Price Volatility',
|
210
|
-
'Exp Price Volatility','Exp Adj Price Volatility',
|
211
|
-
'Weekly Ret Volatility','Weekly Ret Volatility%',
|
212
|
-
'Weekly Adj Ret Volatility','Weekly Adj Ret Volatility%',
|
213
|
-
'Monthly Ret Volatility', 'Monthly Ret Volatility%',
|
214
|
-
'Monthly Adj Ret Volatility', 'Monthly Adj Ret Volatility%',
|
215
|
-
'Quarterly Ret Volatility', 'Quarterly Ret Volatility%',
|
216
|
-
'Quarterly Adj Ret Volatility', 'Quarterly Adj Ret Volatility%',
|
217
|
-
'Annual Ret Volatility', 'Annual Ret Volatility%',
|
218
|
-
'Annual Adj Ret Volatility', 'Annual Adj Ret Volatility%',
|
219
|
-
'Exp Ret Volatility', 'Exp Ret Volatility%', 'Exp Adj Ret Volatility',
|
220
|
-
'Exp Adj Ret Volatility%', 'Weekly Ret LPSD', 'Weekly Ret LPSD%',
|
221
|
-
'Weekly Adj Ret LPSD', 'Weekly Adj Ret LPSD%', 'Monthly Ret LPSD',
|
222
|
-
'Monthly Ret LPSD%', 'Monthly Adj Ret LPSD', 'Monthly Adj Ret LPSD%',
|
223
|
-
'Quarterly Ret LPSD', 'Quarterly Ret LPSD%', 'Quarterly Adj Ret LPSD',
|
224
|
-
'Quarterly Adj Ret LPSD%', 'Annual Ret LPSD', 'Annual Ret LPSD%',
|
225
|
-
'Annual Adj Ret LPSD', 'Annual Adj Ret LPSD%', 'Exp Ret LPSD',
|
226
|
-
'Exp Ret LPSD%', 'Exp Adj Ret LPSD', 'Exp Adj Ret LPSD%']
|
227
|
-
if indicator not in indlist:
|
228
|
-
print(" #Error(calc_indicator): unsupported indicator",indicator)
|
229
|
-
print(" Supported indicators:",indlist)
|
230
|
-
if graph: return
|
231
|
-
else: return None
|
232
|
-
|
233
|
-
print(" Calculating indicators ......")
|
234
|
-
#计算df1中的indicator
|
235
|
-
df1i=calc_indicators(df1,indicator)
|
236
|
-
df1i1=df1i[df1i.index >=start]
|
237
|
-
df1i2=df1i1[df1i1.index <= end]
|
238
|
-
|
239
|
-
|
240
|
-
#绘图
|
241
|
-
ticker1=ticker_name(df1i2['ticker'][0])
|
242
|
-
colname1=indicator
|
243
|
-
label1=ectranslate(indicator)
|
244
|
-
|
245
|
-
ylabeltxt=label1
|
246
|
-
titletxt="证券指标走势:"+ticker1
|
247
|
-
|
248
|
-
note=''
|
249
|
-
note1=df1i2['footnote'][0]
|
250
|
-
if note1 != '':
|
251
|
-
note="证券1:"+note1
|
252
|
-
if note != '':
|
253
|
-
note=note+'\n'
|
254
|
-
|
255
|
-
source1=df1i2['source'][0]
|
256
|
-
source=source1
|
257
|
-
|
258
|
-
import datetime
|
259
|
-
today = datetime.date.today().strftime("%Y-%m-%d")
|
260
|
-
source="数据来源:"+source+','+today
|
261
|
-
|
262
|
-
footnote=''
|
263
|
-
if note != '':
|
264
|
-
footnote=note+source
|
265
|
-
else:
|
266
|
-
footnote=source
|
267
|
-
|
268
|
-
plot_line(df1i2,colname1,label1,ylabeltxt,titletxt,footnote, \
|
269
|
-
power=power,zeroline=zeroline)
|
270
|
-
#print("power=",power,"zeroline=",zeroline)
|
271
|
-
|
272
|
-
if graph: return
|
273
|
-
else: return df1i2
|
274
|
-
|
275
|
-
if __name__=='__main__':
|
276
|
-
draw_indicator(df1,'Annual Ret%','2019-7-1','2020-6-30')
|
277
|
-
#==============================================================================
|
278
|
-
if __name__=='__main__':
|
279
|
-
indicator=''
|
280
|
-
df=df1
|
281
|
-
|
282
|
-
def calc_indicators(df,indicator):
|
283
|
-
"""
|
284
|
-
功能:基于df中的列Close/Adj Close计算indicator,生成新的列indicator
|
285
|
-
"""
|
286
|
-
|
287
|
-
#计算indicator
|
288
|
-
#import siat.stock as sst
|
289
|
-
import siat.security_prices as sst
|
290
|
-
#加入日收益率
|
291
|
-
df1=sst.calc_daily_return(df)
|
292
|
-
df1.dropna(subset=['Daily Ret'],inplace=True)
|
293
|
-
fromdate=df1.index[0].strftime("%Y-%m-%d")
|
294
|
-
|
295
|
-
#加入滚动收益率
|
296
|
-
df1a=sst.calc_rolling_return(df1, "Weekly")
|
297
|
-
df1b=sst.calc_rolling_return(df1a, "Monthly")
|
298
|
-
df1c=sst.calc_rolling_return(df1b, "Quarterly")
|
299
|
-
df1d=sst.calc_rolling_return(df1c, "Annual")
|
300
|
-
#加入扩展收益率
|
301
|
-
df2=sst.calc_expanding_return(df1d,fromdate)
|
302
|
-
collist=list(df2)
|
303
|
-
if indicator in collist:
|
304
|
-
return df2
|
305
|
-
|
306
|
-
#加入滚动价格波动风险
|
307
|
-
df2a=sst.rolling_price_volatility(df2, "Weekly")
|
308
|
-
df2b=sst.rolling_price_volatility(df2a, "Monthly")
|
309
|
-
df2c=sst.rolling_price_volatility(df2b, "Quarterly")
|
310
|
-
df2d=sst.rolling_price_volatility(df2c, "Annual")
|
311
|
-
#加入累计价格波动风险
|
312
|
-
df3=sst.expanding_price_volatility(df2d,fromdate)
|
313
|
-
collist=list(df3)
|
314
|
-
if indicator in collist:
|
315
|
-
return df3
|
316
|
-
|
317
|
-
#加入滚动收益率波动风险
|
318
|
-
df3a=sst.rolling_ret_volatility(df3, "Weekly")
|
319
|
-
df3b=sst.rolling_ret_volatility(df3a, "Monthly")
|
320
|
-
df3c=sst.rolling_ret_volatility(df3b, "Quarterly")
|
321
|
-
df3d=sst.rolling_ret_volatility(df3c, "Annual")
|
322
|
-
#加入累计收益率波动风险
|
323
|
-
df4=sst.expanding_ret_volatility(df3d,fromdate)
|
324
|
-
collist=list(df4)
|
325
|
-
if indicator in collist:
|
326
|
-
return df4
|
327
|
-
|
328
|
-
#加入滚动收益率下偏标准差
|
329
|
-
df4a=sst.rolling_ret_lpsd(df4, "Weekly")
|
330
|
-
df4b=sst.rolling_ret_lpsd(df4a, "Monthly")
|
331
|
-
df4c=sst.rolling_ret_lpsd(df4b, "Quarterly")
|
332
|
-
df4d=sst.rolling_ret_lpsd(df4c, "Annual")
|
333
|
-
#加入扩展收益率下偏标准差
|
334
|
-
df5=sst.expanding_ret_lpsd(df4d,fromdate)
|
335
|
-
|
336
|
-
return df5
|
337
|
-
|
338
|
-
if __name__=='__main__':
|
339
|
-
df1i=calc_indicators(df1,'')
|
340
|
-
|
341
|
-
#==============================================================================
|
342
|
-
#==============================================================================
|
343
|
-
#==============================================================================
|
344
|
-
|
345
|
-
#==============================================================================
|
346
|
-
|
347
|
-
|