siat 3.10.125__py3-none-any.whl → 3.10.127__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.
Files changed (87) hide show
  1. siat/common.py +106 -2
  2. siat/exchange_bond_china.pickle +0 -0
  3. siat/fund_china.pickle +0 -0
  4. siat/stock.py +10 -2
  5. siat/stock_info.pickle +0 -0
  6. {siat-3.10.125.dist-info → siat-3.10.127.dist-info}/METADATA +235 -226
  7. siat-3.10.127.dist-info/RECORD +76 -0
  8. {siat-3.10.125.dist-info → siat-3.10.127.dist-info}/WHEEL +1 -1
  9. {siat-3.10.125.dist-info → siat-3.10.127.dist-info/licenses}/LICENSE +0 -0
  10. {siat-3.10.125.dist-info → siat-3.10.127.dist-info}/top_level.txt +0 -0
  11. siat/__init__ -20240701.py +0 -65
  12. siat/__init__.py.backup_20250214.py +0 -73
  13. siat/alpha_vantage_test.py +0 -24
  14. siat/assets_liquidity_test.py +0 -44
  15. siat/barrons_scraping_test.py +0 -276
  16. siat/beta_adjustment_test.py +0 -77
  17. siat/bond_test.py +0 -142
  18. siat/capm_beta_test.py +0 -49
  19. siat/cmat_commons.py +0 -961
  20. siat/compare_cross_test.py +0 -117
  21. siat/concepts_iwencai.py +0 -86
  22. siat/concepts_kpl.py +0 -93
  23. siat/cryptocurrency_test.py +0 -71
  24. siat/derivative.py +0 -1111
  25. siat/economy-20230125.py +0 -1206
  26. siat/economy_test.py +0 -360
  27. siat/esg_test.py +0 -63
  28. siat/fama_french_test.py +0 -115
  29. siat/financial_statements_test.py +0 -31
  30. siat/financials2 - /321/205/320/231/320/277/321/206/320/254/320/274.py" +0 -341
  31. siat/financials_china2_test.py +0 -67
  32. siat/financials_china2_test2.py +0 -88
  33. siat/financials_china2_test3.py +0 -87
  34. siat/financials_china_test.py +0 -475
  35. siat/financials_china_test2.py +0 -197
  36. siat/financials_china_test2_fin_indicator.py +0 -197
  37. siat/financials_test.py +0 -713
  38. siat/fred_test.py +0 -40
  39. siat/fund_china_test.py +0 -175
  40. siat/fund_test.py +0 -40
  41. siat/future_china_test.py +0 -37
  42. siat/global_index_test.py +0 -66
  43. siat/grafix_test.py +0 -112
  44. siat/holding_risk_test.py +0 -13
  45. siat/local_debug_test.py +0 -100
  46. siat/markowitz2-20240620.py +0 -2614
  47. siat/markowitz_ccb_test.py +0 -37
  48. siat/markowitz_ef_test.py +0 -136
  49. siat/markowitz_old.py +0 -871
  50. siat/markowitz_simple-20230709.py +0 -370
  51. siat/markowitz_test.py +0 -164
  52. siat/markowitz_test2.py +0 -69
  53. siat/ml_cases_example1.py +0 -60
  54. siat/option_china_test.py +0 -447
  55. siat/option_pricing_test.py +0 -81
  56. siat/option_sina_api_test.py +0 -112
  57. siat/proxy_test.py +0 -84
  58. siat/quandl_test.py +0 -39
  59. siat/risk_adjusted_return_test.py +0 -81
  60. siat/risk_evaluation_test.py +0 -96
  61. siat/risk_free_rate_test.py +0 -127
  62. siat/sector_china_test.py +0 -203
  63. siat/security_price.py +0 -831
  64. siat/security_prices_test.py +0 -310
  65. siat/security_trend2-20240620.py +0 -493
  66. siat/setup.py +0 -41
  67. siat/shenwan index history test.py +0 -41
  68. siat/stock_china_test.py +0 -38
  69. siat/stock_info_test.py +0 -189
  70. siat/stock_list_china_test.py +0 -33
  71. siat/stock_technical-20240620.py +0 -2736
  72. siat/stock_test.py +0 -487
  73. siat/temp.py +0 -36
  74. siat/test2_graphviz.py +0 -484
  75. siat/test_graphviz.py +0 -411
  76. siat/test_markowitz_simple.py +0 -198
  77. siat/test_markowitz_simple_revised.py +0 -215
  78. siat/test_markowitz_simple_revised2.py +0 -218
  79. siat/transaction_test.py +0 -436
  80. siat/translate-20230125.py +0 -2107
  81. siat/translate-20230206.py +0 -2109
  82. siat/translate-20230215.py +0 -2158
  83. siat/translate_20240606.py +0 -4206
  84. siat/translate_241003_keep.py +0 -4300
  85. siat/universal_test.py +0 -100
  86. siat/valuation_market_china_test.py +0 -36
  87. siat-3.10.125.dist-info/RECORD +0 -152
@@ -1,493 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- 本模块功能:证券指标趋势分析,部分支持投资组合
4
- 所属工具包:证券投资分析工具SIAT
5
- SIAT:Security Investment Analysis Tool
6
- 创建日期:2024年3月24日
7
- 最新修订日期:
8
- 作者:王德宏 (WANG Dehong, Peter)
9
- 作者单位:北京外国语大学国际商学院
10
- 作者邮件:wdehong2000@163.com
11
- 版权所有:王德宏
12
- 用途限制:仅限研究与教学使用!
13
- 特别声明:作者不对使用本工具进行证券投资导致的任何损益负责!
14
- """
15
-
16
- #==============================================================================
17
- #关闭所有警告
18
- import warnings; warnings.filterwarnings('ignore')
19
- #==============================================================================
20
- from siat.common import *
21
- from siat.translate import *
22
- from siat.stock import *
23
- from siat.security_prices import *
24
- from siat.security_price2 import *
25
- from siat.capm_beta2 import *
26
- from siat.risk_adjusted_return2 import *
27
- from siat.valuation import *
28
- from siat.grafix import *
29
-
30
- import pandas as pd
31
- import datetime as dt; todaydt=str(dt.date.today())
32
- #==============================================================================
33
- #==============================================================================
34
- if __name__=='__main__':
35
- #测试组1
36
- ticker='JD'
37
- indicator='Exp Ret%'
38
- start='2022-1-1'
39
- end='2022-12-31'
40
- datatag=False
41
- power=1
42
- graph=True
43
- source='auto'
44
-
45
- df=security_trend(ticker,indicator=indicator,power=1)
46
-
47
- #测试组2
48
- ticker='AAPL'
49
- indicator=['Close','Open']
50
- start='default'
51
- end='default'
52
- datatag=False
53
- power=0
54
- graph=True
55
- twinx=True
56
- loc1='upper left'
57
- loc2='lower right'
58
- source='auto'
59
-
60
- #测试组3
61
- ticker='AAPL'
62
- indicator=['Close','Open','High','Low']
63
- start='default'
64
- end='default'
65
- datatag=False
66
- power=0
67
- graph=True
68
- twinx=True
69
- loc1='upper left'
70
- loc2='lower right'
71
- source='auto'
72
- ticker_type='auto'
73
-
74
- #测试组4
75
- ticker=["GCZ25.CMX","GCZ24.CMX"]
76
- indicator='Close'
77
- start="2020-1-1"
78
- end="2020-6-30"
79
-
80
-
81
- #测试组5
82
- ticker=["180801.SZ","180101.SZ"]
83
- indicator='Close'
84
- start="2024-1-1"
85
- end="2024-5-30"
86
- ticker_type='fund'
87
-
88
- df=security_trend(ticker,indicator,start,end,ticker_type=ticker_type)
89
-
90
-
91
- def security_trend(ticker,indicator='Close', \
92
- start='default',end='default', \
93
-
94
- attention_value='',average_value=False, \
95
-
96
- kline=False,kline_demo=False,mav=[5,10,20], \
97
-
98
- dividend=False,split=False, \
99
-
100
- ret_type='Annual Ret%',RF=0,regression_period=365,market_index="auto", \
101
- sortby='tpw_mean',trailing=7,trend_threshhold=0.05, \
102
-
103
- graph=True,twinx=False,loc1='best',loc2='best', \
104
- datatag=False,power=0, \
105
- smooth=True,date_range=False,date_freq=False, \
106
-
107
- preprocess='none',scaling_option='change%', \
108
-
109
- annotate=False,annotate_value=False, \
110
- mark_top=False,mark_bottom=False,mark_end=False, \
111
-
112
- printout=False,source='auto', \
113
- ticker_type='auto', \
114
- facecolor='whitesmoke'):
115
-
116
- """
117
- 功能:组合指令,分析证券指标走势,支持多个证券、多个指标和多种绘图方式。
118
- 参数描述:
119
- ticker参数:证券标示,支持多个经济体的证券,包括股票、基金、部分欧美衍生品。
120
- 股票:单一股票,股票列表,支持全球主要证券市场的股票。
121
- 债券:因数据来源关系,本指令暂不支持债券,计划首先支持最活跃的沪深可转债。
122
- 基金:因数据来源关系,仅支持下列市场的部分基金:
123
- 沪深交易所(ETF/LOF/REIT基金),美市(ETF/REIT/共同基金),日韩欧洲(部分ETF/REIT基金)。
124
- 利率产品:因数据来源关系,仅支持欧美市场的部分利率产品。
125
- 衍生品:因数据来源关系,仅支持欧美市场的部分商品、金融期货和期权产品(如股票期权)。
126
- 投资组合:使用字典表示法,成分股仅支持全球交易所上市的主要股票(限同币种)。
127
- 投资组合仅支持RAR指标和CAPM贝塔系数,其他指标暂不支持。
128
-
129
- indicator参数:支持证券价格、收益率、风险指标、估值指标、RAR指标和CAPM贝塔系数。
130
- 证券价格:支持开盘价、收盘价、最高最低价。
131
- 收益率:支持基本的日收益率、滚动收益率和扩展收益率。滚动收益率支持周、月、季度和年。
132
- 风险指标:支持滚动收益率和扩展收益率的标准差(波动风险)和下偏标准差(损失风险)。
133
- RAR指标:支持夏普比率、詹森阿尔法、索替诺比率和特雷诺比率。
134
- 估值指标:支持市盈率、市净率和市值。仅支持中国内地、中国香港、美股和波兰上市的股票。
135
- 市值指标不支持市场指数。
136
-
137
- start参数:指定分析的开始日期或期间。日期格式:YYYY-mm-dd
138
- 作为期间时,支持最近的1个月、1个季度、半年、1年、2年、3年、5年、8年、10年或今年以来。
139
- 省略时默认为最近的1个月。
140
- end参数:指定分析的结束日期。日期格式:YYYY-mm-dd。省略时默认为今日。
141
-
142
- attention_value参数:绘图时绘制一条水平线,用以强调一个阈值。默认不绘制。
143
- average_value参数:开关打开时,绘图时绘制一条均值线,仅适用于绘制单条曲线。默认关闭。
144
-
145
- kline参数:开关打开时,绘制一条K线图,仅适用于单只股票。默认关闭。
146
- kline_demo参数:与kline开关同时打开时,绘制一条K线图原理演示图,仅适用于单只股票。
147
- mav参数:仅当kline开关打开时有效,用于指定K线图中单条或多条移动平均线的天数。
148
-
149
- stock_dividend和stock_split参数:显示一只股票的分红和分拆历史,支持全球主要市场的股票。
150
- 注意:本参数需要访问雅虎财经网站获取数据。
151
-
152
- ret_type、RF、regression_period和market_index参数:仅用于计算RAR指标和CAPM贝塔系数。
153
- ret_type参数:指定计算RAR的收益率类型,支持滚动和扩展收益率,但不建议混合使用。
154
- RF参数:指定年化无风险利率,非百分比数值。
155
- regression_period参数:指定CAPM回归时的日期期间跨度,为日历日(自然日),默认一年。
156
- market_index参数:用于计算CAPM回归贝塔系数时的市场收益率。
157
- 系统能够自动识别全球主要证券市场的指数,其他证券市场可由人工指定具体的市场指数代码。
158
-
159
- graph参数:指定是否将分析结果绘制曲线,默认绘制。
160
- twinx参数:指定绘图时是否使用双轴绘图法,仅用于两条曲线且其数量级差异较大时。
161
- loc1和loc2参数:用于指定绘图时图例的位置,包括左右上角(下角、中间)、上下中间或图中央。
162
- loc1用于指定非双轴图或双轴图中第1条曲线图例的位置,loc2用于指定双轴图中第2条曲线的位置。
163
- datatag参数:用于指定绘图时是否绘制数据标签,仅当数据稀疏时适用,默认关闭。
164
- power参数:用于指定绘图时是否使用多项式绘制趋势线,可指定多项式的阶数,1为直线,默认不绘制。
165
- smooth参数:指定绘图时是否对曲线进行平滑处理,仅适用于少量数据构造的曲线,默认打开。
166
- date_range参数:绘制时序图时强制横轴的开始和结束日期,默认关闭。
167
- date_freq参数:绘制时序图时强制横轴的日期间隔大小。默认关闭,由系统自动决定。
168
- annotate参数:绘图时是否将曲线名称标注在曲线末端。默认关闭(使用传统图例),以避免重叠。
169
-
170
- preprocess参数:绘图前是否进行数据预处理,默认不使用。
171
- 预处理方式:支持标准化、正态化、取对数和同步缩放法,常用的为同步缩放法。
172
- scaling_option参数:指定同步缩放法的对齐选项,支持均值、最小值、起点值、百分比和变化率方法。
173
- 其中,百分比和变化率方法常用。适用于数值差异大的价格走势对比分析,其他指标不适用或效果不明显。
174
-
175
- printout参数:仅适用于有相关功能的指标(例如RAR)打开结果表格输出,默认关闭。
176
-
177
- source参数:指定证券基础数据来源,默认由系统决定。当系统找到的数据不理想时,可手动指定。
178
- 若指定雅虎财经数据源,需要拥有访问该网站的权限。
179
- """
180
- critical_value=attention_value
181
-
182
- portfolio_flag=False #标志:ticker中是否含有投资组合
183
- ticker=tickers_cvt2yahoo(ticker) #支持多种形式证券代码格式
184
-
185
- # 检查证券代码
186
- if isinstance(ticker,str):
187
- ticker_num=1
188
- tickers=[ticker]
189
- elif isinstance(ticker,list):
190
- ticker_num=len(ticker)
191
- tickers=ticker
192
- for t in tickers: #检查列表中是否存在投资组合
193
- if isinstance(t,dict):
194
- portfolio_flag=True
195
- #print(" #Warning(security_trend): only RAR and CAPM beta indicators support portfolio")
196
- #print(" All other indicators do not support portfolio")
197
- elif isinstance(ticker,dict): #检查是否投资组合
198
- portfolio_flag=True
199
- ticker_num=1
200
- tickers=[ticker]
201
- #print(" #Warning(security_trend): only RAR and CAPM beta indicators support portfolio")
202
- #print(" All other indicators do not support portfolio")
203
- else:
204
- print(" #Error(security_trend): unrecognizable security codes",ticker)
205
- return None
206
-
207
- # 检查日期:如有错误自动更正
208
- fromdate,todate=start_end_preprocess(start=start,end=end)
209
-
210
- # 处理K线图=================================================================
211
- if kline and not kline_demo:
212
- if portfolio_flag:
213
- print(" #Warning(security_trend): ticker of or with portfolio does not support for K line")
214
- return None
215
-
216
- # 跟踪
217
- #print(tickers[0],fromdate,todate)
218
- if start in ['default']:
219
- fromdate=date_adjust(todate,adjust=-60)
220
- if not isinstance(mav,list):
221
- mav=[mav]
222
- df=candlestick(stkcd=tickers[0],fromdate=fromdate,todate=todate,mav=mav, \
223
- ticker_type=ticker_type,facecolor=facecolor)
224
- return df
225
-
226
- if kline and kline_demo:
227
- if portfolio_flag:
228
- print(" #Warning(security_trend): ticker of or with portfolio does not support for K line")
229
- return None
230
-
231
- if start in ['default']:
232
- fromdate=date_adjust(todate,adjust=-7)
233
-
234
- df=candlestick_demo(tickers[0],fromdate=fromdate,todate=todate, \
235
- ticker_type=ticker_type,facecolor=facecolor)
236
- return df
237
-
238
- # 处理股票分红和股票分拆:需要访问雅虎财经=====================================
239
- if dividend:
240
- if portfolio_flag:
241
- print(" #Warning(security_trend): investment portfolio does not support for stock dividend")
242
- return None
243
-
244
- if start in ['default']:
245
- fromdate=date_adjust(todate,adjust=-365*5)
246
- print(" #Notice: try to access Yahoo for stock dividend ...")
247
- df=stock_dividend(ticker=tickers[0],fromdate=fromdate,todate=todate,facecolor=facecolor)
248
- return df
249
-
250
- if split:
251
- if portfolio_flag:
252
- print(" #Warning(security_trend): investment portfolio does not support for stock split")
253
- return None
254
-
255
- if start in ['default']:
256
- fromdate=date_adjust(todate,adjust=-365*5)
257
- print(" #Notice: try to access Yahoo for stock split ...")
258
- df=stock_split(ticker=tickers[0],fromdate=fromdate,todate=todate,facecolor=facecolor)
259
- return df
260
-
261
-
262
- # 检查趋势指标:是否字符串或列表=================================================
263
- if isinstance(indicator,str):
264
- measures=[indicator]
265
- indicator_num=1
266
- elif isinstance(indicator,list):
267
- measures=indicator
268
- indicator_num=len(indicator)
269
- else:
270
- print(" #Error(security_trend): invalid indicator(s) for",indicator)
271
- return None
272
-
273
- # 检查趋势指标
274
- indicator_list1=['Open','Close','Adj Close','High','Low',
275
- 'Daily Ret','Daily Ret%','Daily Adj Ret','Daily Adj Ret%',
276
- 'log(Daily Ret)','log(Daily Adj Ret)','Weekly Ret','Weekly Ret%',
277
- 'Weekly Adj Ret','Weekly Adj Ret%','Monthly Ret','Monthly Ret%',
278
- 'Monthly Adj Ret','Monthly Adj Ret%','Quarterly Ret','Quarterly Ret%',
279
- 'Quarterly Adj Ret','Quarterly Adj Ret%','Annual Ret','Annual Ret%',
280
- 'Annual Adj Ret','Annual Adj Ret%','Exp Ret','Exp Ret%','Exp Adj Ret',
281
- 'Exp Adj Ret%','Weekly Price Volatility','Weekly Adj Price Volatility',
282
- 'Monthly Price Volatility','Monthly Adj Price Volatility',
283
- 'Quarterly Price Volatility','Quarterly Adj Price Volatility',
284
- 'Annual Price Volatility','Annual Adj Price Volatility',
285
- 'Exp Price Volatility','Exp Adj Price Volatility',
286
- 'Weekly Ret Volatility','Weekly Ret Volatility%',
287
- 'Weekly Adj Ret Volatility','Weekly Adj Ret Volatility%',
288
- 'Monthly Ret Volatility', 'Monthly Ret Volatility%',
289
- 'Monthly Adj Ret Volatility', 'Monthly Adj Ret Volatility%',
290
- 'Quarterly Ret Volatility', 'Quarterly Ret Volatility%',
291
- 'Quarterly Adj Ret Volatility', 'Quarterly Adj Ret Volatility%',
292
- 'Annual Ret Volatility', 'Annual Ret Volatility%',
293
- 'Annual Adj Ret Volatility', 'Annual Adj Ret Volatility%',
294
- 'Exp Ret Volatility', 'Exp Ret Volatility%', 'Exp Adj Ret Volatility',
295
- 'Exp Adj Ret Volatility%', 'Weekly Ret LPSD', 'Weekly Ret LPSD%',
296
- 'Weekly Adj Ret LPSD', 'Weekly Adj Ret LPSD%', 'Monthly Ret LPSD',
297
- 'Monthly Ret LPSD%', 'Monthly Adj Ret LPSD', 'Monthly Adj Ret LPSD%',
298
- 'Quarterly Ret LPSD', 'Quarterly Ret LPSD%', 'Quarterly Adj Ret LPSD',
299
- 'Quarterly Adj Ret LPSD%', 'Annual Ret LPSD', 'Annual Ret LPSD%',
300
- 'Annual Adj Ret LPSD', 'Annual Adj Ret LPSD%', 'Exp Ret LPSD',
301
- 'Exp Ret LPSD%', 'Exp Adj Ret LPSD', 'Exp Adj Ret LPSD%',
302
- ]
303
-
304
- indicator_list2=['treynor','sharpe','sortino','alpha','Treynor','Sharpe','Sortino','Alpha']
305
- indicator_list3=['pe','pb','mv','PE','PB','MV','Pe','Pb','Mv','ROE','roe','Roe']
306
- indicator_list4=['beta','Beta','BETA']
307
-
308
- # 是否属于支持的指标
309
- for m in measures:
310
- if not (m in indicator_list1 + indicator_list2 + indicator_list3 + indicator_list4):
311
- print(" #Error(security_trend): unsupported indicator for",m)
312
- print(" Supported indicators:")
313
- printlist(indicator_list1,numperline=4,beforehand=' ',separator=' ')
314
- printlist(indicator_list2,numperline=5,beforehand=' ',separator=' ')
315
- printlist(indicator_list3,numperline=5,beforehand=' ',separator=' ')
316
- printlist(indicator_list4,numperline=5,beforehand=' ',separator=' ')
317
- return None
318
-
319
- #检查是否跨组比较:不能同时支持indicator_list1/2/3/4的指标,即不能跨组比较!
320
- indicator_group1=False #组1:普通指标(股价,收益率,风险)
321
- indicator_group2=False #组2:RAR指标(夏普/阿尔法/索替诺/特雷诺指标)
322
- indicator_group3=False #组3:估值指标(市盈率,市净率,市值)
323
- indicator_group4=False #组4:贝塔系数
324
-
325
- list_group1=list_group2=list_group3=list_group4=0
326
- for m in measures:
327
- if m in indicator_list4:
328
- list_group4=1
329
- indicator_group4=True
330
- measures = [x.lower() for x in measures]
331
-
332
- if m in indicator_list3:
333
- list_group3=1
334
- indicator_group3=True
335
- measures = [x.upper() for x in measures]
336
-
337
- if m in indicator_list2:
338
- list_group2=1
339
- indicator_group2=True
340
- measures = [x.lower() for x in measures]
341
-
342
- if m in indicator_list1:
343
- list_group1=1
344
- indicator_group1=True
345
- measures = [x.title() for x in measures]
346
- measures = [x.replace('Lpsd','LPSD') if 'Lpsd' in x else x for x in measures]
347
-
348
- if list_group1+list_group2+list_group3+list_group4 >= 2:
349
- print(" #Error(security_trend): cannot support hybrid indicators together for",list2str(measures))
350
- return None
351
-
352
- #检查指标是否支持投资组合:暂不支持组1/3的指标
353
- """
354
- if portfolio_flag and (indicator_group1 or indicator_group3):
355
- print(" #Warning(security_trend): ticker of or with portfolio does not support indicator",list2str(measures))
356
- return None
357
- """
358
- # 情形1:单个证券,单个普通指标===============================================
359
- # 绘制横线
360
- zeroline=False
361
- if (critical_value != ''):
362
- if isinstance(critical_value,float) or isinstance(critical_value,int):
363
- zeroline=critical_value
364
-
365
- if ticker_num==1 and indicator_num==1 and indicator_group1:
366
- df=security_indicator(ticker=tickers[0],indicator=measures[0], \
367
- fromdate=fromdate,todate=todate, \
368
- zeroline=zeroline, \
369
- average_value=average_value, \
370
- datatag=datatag,power=power,graph=graph, \
371
- source=source, \
372
- mark_top=mark_top,mark_bottom=mark_bottom, \
373
- mark_end=mark_end,ticker_type=ticker_type, \
374
- facecolor=facecolor)
375
- return df
376
-
377
- # 情形2:单个证券,两个普通指标,twinx==True =================================
378
- if ticker_num==1 and indicator_num == 2 and indicator_group1 and twinx:
379
- df=compare_security(tickers=tickers[0],measures=measures[:2], \
380
- fromdate=fromdate,todate=todate,twinx=twinx, \
381
- loc1=loc1,loc2=loc2,graph=graph,source=source, \
382
- ticker_type=ticker_type,facecolor=facecolor)
383
- return df
384
-
385
- # 情形3:单个证券,两个及以上普通指标=========================================
386
- if ticker_num==1 and indicator_num >= 2 and indicator_group1 and not twinx:
387
- df=security_mindicators(ticker=tickers[0],measures=measures, \
388
- fromdate=fromdate,todate=todate, \
389
- graph=graph,smooth=smooth,loc=loc1, \
390
- date_range=date_range,date_freq=date_freq, \
391
- annotate=annotate,annotate_value=annotate_value, \
392
- source=source,
393
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
394
- ticker_type=ticker_type,facecolor=facecolor)
395
- return df
396
-
397
- # 情形4:两个证券,取第一个普通指标,twinx==True =============================
398
- if ticker_num==2 and indicator_group1 and twinx:
399
- df=compare_security(tickers=tickers,measures=measures[0], \
400
- fromdate=fromdate,todate=todate,twinx=twinx, \
401
- loc1=loc1,loc2=loc2,graph=graph,source=source, \
402
- ticker_type=ticker_type,facecolor=facecolor)
403
- return df
404
-
405
- # 情形5:两个及以上证券,取第一个普通指标=====================================
406
- if ticker_num==2:
407
- linewidth=2.5
408
- elif ticker_num==3:
409
- linewidth=2.0
410
- else:
411
- linewidth=1.5
412
-
413
- # 绘制横线
414
- axhline_value=0
415
- axhline_label=''
416
- if (critical_value != ''):
417
- if isinstance(critical_value,float) or isinstance(critical_value,int):
418
- axhline_value=critical_value
419
- axhline_label='零线'
420
-
421
- if ((ticker_num == 2 and not twinx) or ticker_num > 2) and indicator_group1:
422
- df=compare_msecurity(tickers=tickers,measure=measures[0], \
423
- start=fromdate,end=todate, \
424
- axhline_value=axhline_value,axhline_label=axhline_label, \
425
- preprocess=preprocess,linewidth=linewidth, \
426
- scaling_option=scaling_option, \
427
- graph=graph,loc=loc1, \
428
- annotate=annotate,annotate_value=annotate_value, \
429
- smooth=smooth, \
430
- source=source, \
431
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
432
- ticker_type=ticker_type,facecolor=facecolor)
433
- return df
434
-
435
- # 情形6:单个或多个证券,单个或多个RAR指标,支持投资组合=======================
436
- # 注意:支持滚动收益率和扩展收益率,但不建议混合使用,因为难以解释结果
437
- if indicator_group2:
438
- df=compare_rar_security(ticker=tickers,start=fromdate,end=todate,rar=measures, \
439
- ret_type=ret_type,RF=RF,regression_period=regression_period, \
440
- graph=graph,axhline_value=0,axhline_label='', \
441
- loc1=loc1, \
442
- printout=printout, \
443
- sortby=sortby,trailing=trailing,trend_threshhold=trend_threshhold, \
444
- annotate=annotate,annotate_value=annotate_value, \
445
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
446
- mktidx=market_index,source=source, \
447
- ticker_type=ticker_type,facecolor=facecolor)
448
- return df
449
-
450
- # 情形7:单个或多个证券,CAPM贝塔系数=========================================
451
- if indicator_group4:
452
- df=compare_beta_security(ticker=tickers,start=fromdate,end=todate, \
453
- RF=RF,regression_period=regression_period, \
454
- graph=graph,facecolor=facecolor, \
455
- annotate=annotate,annotate_value=annotate_value, \
456
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
457
- mktidx=market_index,source=source, \
458
- ticker_type=ticker_type)
459
-
460
- return df
461
-
462
-
463
- # 情形8:估值指标PE/PB/MV/ROE,仅针对股票,无需ticker_type====================
464
- if indicator_group3:
465
- df=security_valuation(tickers=tickers,indicators=measures,start=fromdate,end=todate, \
466
- preprocess=preprocess,scaling_option=scaling_option, \
467
- twinx=twinx,loc1=loc1,loc2=loc2, \
468
- graph=graph,facecolor=facecolor, \
469
- annotate=annotate,annotate_value=annotate_value, \
470
- mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end)
471
- return df
472
-
473
- # 其他未预料情形
474
- print(" #Error(security_trend): unsupported combination of security(ies) and indicator(s):-(")
475
-
476
- return None
477
-
478
- #==============================================================================
479
-
480
- #==============================================================================
481
- #==============================================================================
482
- #==============================================================================
483
-
484
-
485
-
486
-
487
-
488
-
489
-
490
-
491
-
492
-
493
-
siat/setup.py DELETED
@@ -1,41 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- Created on Thu Aug 13 13:24:42 2020
4
-
5
- @author: Peter
6
- """
7
-
8
- from __future__ import print_function
9
- from setuptools import setup, find_packages
10
- import sys
11
-
12
- setup(
13
- name="siat",
14
- version="1.0.1",
15
- author="WANG Dehong (Peter)",
16
- author_email="wdehong2000@163.com",
17
- description="Security Investment Analysis Tools",
18
- long_description=open("README.rst").read(),
19
- license="WANG Dehong",
20
- packages=['siat'],
21
- classifiers=[
22
- "Environment :: Anaconda Environment",
23
- 'Intended Audience :: Financial Researchers',
24
- 'License :: OSI Approved :: BFSU License',
25
- 'Natural Language :: Chinese/English',
26
- 'Operating System :: Windows 7/10',
27
- 'Operating System :: Microsoft',
28
- 'Operating System :: POSIX',
29
- 'Operating System :: Unix',
30
- 'Topic :: Finance :: Analysis',
31
- "Topic :: Internet",
32
- "Topic :: Software Development :: Libraries :: Python Modules",
33
- 'Programming Language :: Python :: 3.3',
34
- 'Programming Language :: Python :: 3.4',
35
- 'Programming Language :: Python :: 3.5',
36
- 'Programming Language :: Python :: 3.6',
37
- 'Programming Language :: Python :: 3.7',
38
- 'Programming Language :: Python :: 3.8',
39
- ],
40
- zip_safe=True,
41
- )
@@ -1,41 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- 功能:获取申万一级行业历史行情指数
4
- """
5
-
6
- from opendatatools import swindex
7
- import pandas as pd
8
-
9
- # 1. 获取申万指数列表
10
- cata, msg = swindex.get_index_list()
11
- cata.head(20)
12
-
13
- # 2. 获取申万指数成分信息
14
-
15
- content, msg = swindex.get_index_cons('801040')
16
-
17
- # 3. 获取申万指数日线
18
-
19
- daily, msg = swindex.get_index_daily('801040','2010-01-01', '2021-02-24')
20
- daily.tail(20)
21
-
22
- # 4. 获取申万指数每日的量化指标(pe、pb等)
23
-
24
- quant, msg = swindex.get_index_dailyindicator('801040', '2010-01-01', '2021-02-24',freq='d')
25
- quant.head(20)
26
-
27
- # 示例:查取申万所有一级行业任意时间区间走势
28
- def get_price_sw_industry(start_date, end_date):
29
- cata, msg = swindex.get_index_list()
30
- first_industry = cata.iloc[18:46, 0:2].reset_index(drop=True)
31
- price = pd.DataFrame()
32
- for i in range(0,len(first_industry)):
33
- daily, msg = swindex.get_index_daily(first_industry.iloc[i,0],start_date, end_date)
34
- close = daily[['date', 'close']].sort_values(by="date", ascending=True).set_index('date').rename(columns={'close': first_industry.iloc[i,1]})
35
- price = pd.concat([price,close],axis=1, join='outer').astype('float')
36
-
37
- price.to_excel('data/申万一级行业行情走势.xlsx', sheet_name='指数')
38
-
39
- return price
40
-
41
- get_price_sw_industry('2020-10-01','2020-12-31')
siat/stock_china_test.py DELETED
@@ -1,38 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- import os; os.chdir("S:/siat")
4
- from siat.stock_china import *
5
-
6
- #==============================================================================
7
- import akshare as ak
8
- l1=ticker[0]; market='sh'
9
- if l1 in ['0','2','3']: market='sz'
10
- df = ak.stock_individual_fund_flow(stock=ticker, market=market)
11
- df.to_excel("D:/BFSU WORK/600519MFI.xlsx",index=False,encoding='utf-8',sheet_name='Sheet1')
12
-
13
- if __name__=='__main__':
14
- ticker='600519.SS'
15
- dfp=get_money_flowin(ticker)
16
-
17
- X,ydf=make_sample(dfp,ndays=1,preCumTimes=1)
18
-
19
- scaler_X1=preprocess(X,preproctype='min-max')
20
- scaler_X2=preprocess(X,preproctype='0-1')
21
- scaler_X3=preprocess(X,preproctype='log')
22
-
23
-
24
- #==============================================================================
25
- ticker='600519.ss'
26
-
27
- forecast_direction_knn(ticker,ndays=5,max_neighbours=2,max_RS=2)
28
-
29
- if __name__=='__main__':
30
- df=get_money_flowin(ticker)
31
- df=price_price_knn('600519.SS',df,ndays=1,max_neighbours=3,max_RS=2)
32
-
33
- forecast_price_knn(ticker,ndays=1,max_neighbours=2,max_RS=2)
34
-
35
-
36
- forecast_direction_knn(ticker,ndays=5,max_neighbours=10,max_RS=10)
37
- forecast_price_knn(ticker,ndays=5,max_neighbours=10,max_RS=10)
38
- #==============================================================================