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.
Files changed (221) hide show
  1. siat/__init__.py +0 -0
  2. siat/allin.py +8 -0
  3. siat/assets_liquidity.py +0 -0
  4. siat/beta_adjustment.py +0 -0
  5. siat/beta_adjustment_china.py +0 -0
  6. siat/blockchain.py +0 -0
  7. siat/bond.py +0 -0
  8. siat/bond_base.py +0 -0
  9. siat/bond_china.py +0 -0
  10. siat/bond_zh_sina.py +0 -0
  11. siat/capm_beta.py +0 -0
  12. siat/capm_beta2.py +4 -4
  13. siat/common.py +9 -6
  14. siat/compare_cross.py +0 -0
  15. siat/copyrights.py +0 -0
  16. siat/cryptocurrency.py +0 -0
  17. siat/economy.py +0 -0
  18. siat/economy2.py +0 -0
  19. siat/esg.py +0 -0
  20. siat/event_study.py +0 -0
  21. siat/exchange_bond_china.pickle +0 -0
  22. siat/fama_french.py +0 -0
  23. siat/fin_stmt2_yahoo.py +0 -0
  24. siat/financial_base.py +0 -0
  25. siat/financial_statements.py +0 -0
  26. siat/financials.py +0 -0
  27. siat/financials2.py +0 -0
  28. siat/financials_china.py +0 -0
  29. siat/financials_china2.py +0 -0
  30. siat/fund.py +0 -0
  31. siat/fund_china.pickle +0 -0
  32. siat/fund_china.py +0 -0
  33. siat/future_china.py +0 -0
  34. siat/google_authenticator.py +0 -0
  35. siat/grafix.py +55 -4
  36. siat/holding_risk.py +0 -0
  37. siat/luchy_draw.py +0 -0
  38. siat/market_china.py +0 -0
  39. siat/markowitz.py +0 -0
  40. siat/markowitz2.py +1 -0
  41. siat/markowitz2_20250704.py +0 -0
  42. siat/markowitz2_20250705.py +0 -0
  43. siat/markowitz_simple.py +0 -0
  44. siat/ml_cases.py +0 -0
  45. siat/ml_cases_example.py +0 -0
  46. siat/option_china.py +0 -0
  47. siat/option_pricing.py +0 -0
  48. siat/other_indexes.py +0 -0
  49. siat/risk_adjusted_return.py +0 -0
  50. siat/risk_adjusted_return2.py +8 -4
  51. siat/risk_evaluation.py +0 -0
  52. siat/risk_free_rate.py +0 -0
  53. siat/save2docx.py +345 -0
  54. siat/save2pdf.py +145 -0
  55. siat/sector_china.py +0 -0
  56. siat/security_price2.py +0 -0
  57. siat/security_prices.py +168 -6
  58. siat/security_trend.py +0 -0
  59. siat/security_trend2.py +2 -2
  60. siat/stock.py +11 -1
  61. siat/stock_advice_linear.py +0 -0
  62. siat/stock_base.py +0 -0
  63. siat/stock_china.py +0 -0
  64. siat/stock_info.pickle +0 -0
  65. siat/stock_prices_kneighbors.py +0 -0
  66. siat/stock_prices_linear.py +0 -0
  67. siat/stock_profile.py +0 -0
  68. siat/stock_technical.py +0 -0
  69. siat/stooq.py +0 -0
  70. siat/transaction.py +0 -0
  71. siat/translate.py +0 -0
  72. siat/valuation.py +0 -0
  73. siat/valuation_china.py +0 -0
  74. siat/var_model_validation.py +0 -0
  75. siat/yf_name.py +0 -0
  76. {siat-3.10.132.dist-info/licenses → siat-3.11.1.dist-info}/LICENSE +0 -0
  77. {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/METADATA +234 -235
  78. siat-3.11.1.dist-info/RECORD +80 -0
  79. {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/WHEEL +1 -1
  80. {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/top_level.txt +0 -1
  81. build/lib/build/lib/siat/__init__.py +0 -75
  82. build/lib/build/lib/siat/allin.py +0 -137
  83. build/lib/build/lib/siat/assets_liquidity.py +0 -915
  84. build/lib/build/lib/siat/beta_adjustment.py +0 -1058
  85. build/lib/build/lib/siat/beta_adjustment_china.py +0 -548
  86. build/lib/build/lib/siat/blockchain.py +0 -143
  87. build/lib/build/lib/siat/bond.py +0 -2900
  88. build/lib/build/lib/siat/bond_base.py +0 -992
  89. build/lib/build/lib/siat/bond_china.py +0 -100
  90. build/lib/build/lib/siat/bond_zh_sina.py +0 -143
  91. build/lib/build/lib/siat/capm_beta.py +0 -783
  92. build/lib/build/lib/siat/capm_beta2.py +0 -887
  93. build/lib/build/lib/siat/common.py +0 -5360
  94. build/lib/build/lib/siat/compare_cross.py +0 -642
  95. build/lib/build/lib/siat/copyrights.py +0 -18
  96. build/lib/build/lib/siat/cryptocurrency.py +0 -667
  97. build/lib/build/lib/siat/economy.py +0 -1471
  98. build/lib/build/lib/siat/economy2.py +0 -1853
  99. build/lib/build/lib/siat/esg.py +0 -536
  100. build/lib/build/lib/siat/event_study.py +0 -815
  101. build/lib/build/lib/siat/fama_french.py +0 -1521
  102. build/lib/build/lib/siat/fin_stmt2_yahoo.py +0 -982
  103. build/lib/build/lib/siat/financial_base.py +0 -1160
  104. build/lib/build/lib/siat/financial_statements.py +0 -598
  105. build/lib/build/lib/siat/financials.py +0 -2339
  106. build/lib/build/lib/siat/financials2.py +0 -1278
  107. build/lib/build/lib/siat/financials_china.py +0 -4433
  108. build/lib/build/lib/siat/financials_china2.py +0 -2212
  109. build/lib/build/lib/siat/fund.py +0 -629
  110. build/lib/build/lib/siat/fund_china.py +0 -3307
  111. build/lib/build/lib/siat/future_china.py +0 -551
  112. build/lib/build/lib/siat/google_authenticator.py +0 -47
  113. build/lib/build/lib/siat/grafix.py +0 -3636
  114. build/lib/build/lib/siat/holding_risk.py +0 -867
  115. build/lib/build/lib/siat/luchy_draw.py +0 -638
  116. build/lib/build/lib/siat/market_china.py +0 -1168
  117. build/lib/build/lib/siat/markowitz.py +0 -2363
  118. build/lib/build/lib/siat/markowitz2.py +0 -3150
  119. build/lib/build/lib/siat/markowitz2_20250704.py +0 -2969
  120. build/lib/build/lib/siat/markowitz2_20250705.py +0 -3158
  121. build/lib/build/lib/siat/markowitz_simple.py +0 -373
  122. build/lib/build/lib/siat/ml_cases.py +0 -2291
  123. build/lib/build/lib/siat/ml_cases_example.py +0 -60
  124. build/lib/build/lib/siat/option_china.py +0 -3069
  125. build/lib/build/lib/siat/option_pricing.py +0 -1925
  126. build/lib/build/lib/siat/other_indexes.py +0 -409
  127. build/lib/build/lib/siat/risk_adjusted_return.py +0 -1576
  128. build/lib/build/lib/siat/risk_adjusted_return2.py +0 -1900
  129. build/lib/build/lib/siat/risk_evaluation.py +0 -2218
  130. build/lib/build/lib/siat/risk_free_rate.py +0 -351
  131. build/lib/build/lib/siat/sector_china.py +0 -4140
  132. build/lib/build/lib/siat/security_price2.py +0 -727
  133. build/lib/build/lib/siat/security_prices.py +0 -3408
  134. build/lib/build/lib/siat/security_trend.py +0 -402
  135. build/lib/build/lib/siat/security_trend2.py +0 -646
  136. build/lib/build/lib/siat/stock.py +0 -4284
  137. build/lib/build/lib/siat/stock_advice_linear.py +0 -934
  138. build/lib/build/lib/siat/stock_base.py +0 -26
  139. build/lib/build/lib/siat/stock_china.py +0 -2095
  140. build/lib/build/lib/siat/stock_prices_kneighbors.py +0 -910
  141. build/lib/build/lib/siat/stock_prices_linear.py +0 -386
  142. build/lib/build/lib/siat/stock_profile.py +0 -707
  143. build/lib/build/lib/siat/stock_technical.py +0 -3305
  144. build/lib/build/lib/siat/stooq.py +0 -74
  145. build/lib/build/lib/siat/transaction.py +0 -347
  146. build/lib/build/lib/siat/translate.py +0 -5183
  147. build/lib/build/lib/siat/valuation.py +0 -1378
  148. build/lib/build/lib/siat/valuation_china.py +0 -2076
  149. build/lib/build/lib/siat/var_model_validation.py +0 -444
  150. build/lib/build/lib/siat/yf_name.py +0 -811
  151. build/lib/siat/__init__.py +0 -75
  152. build/lib/siat/allin.py +0 -137
  153. build/lib/siat/assets_liquidity.py +0 -915
  154. build/lib/siat/beta_adjustment.py +0 -1058
  155. build/lib/siat/beta_adjustment_china.py +0 -548
  156. build/lib/siat/blockchain.py +0 -143
  157. build/lib/siat/bond.py +0 -2900
  158. build/lib/siat/bond_base.py +0 -992
  159. build/lib/siat/bond_china.py +0 -100
  160. build/lib/siat/bond_zh_sina.py +0 -143
  161. build/lib/siat/capm_beta.py +0 -783
  162. build/lib/siat/capm_beta2.py +0 -887
  163. build/lib/siat/common.py +0 -5360
  164. build/lib/siat/compare_cross.py +0 -642
  165. build/lib/siat/copyrights.py +0 -18
  166. build/lib/siat/cryptocurrency.py +0 -667
  167. build/lib/siat/economy.py +0 -1471
  168. build/lib/siat/economy2.py +0 -1853
  169. build/lib/siat/esg.py +0 -536
  170. build/lib/siat/event_study.py +0 -815
  171. build/lib/siat/fama_french.py +0 -1521
  172. build/lib/siat/fin_stmt2_yahoo.py +0 -982
  173. build/lib/siat/financial_base.py +0 -1160
  174. build/lib/siat/financial_statements.py +0 -598
  175. build/lib/siat/financials.py +0 -2339
  176. build/lib/siat/financials2.py +0 -1278
  177. build/lib/siat/financials_china.py +0 -4433
  178. build/lib/siat/financials_china2.py +0 -2212
  179. build/lib/siat/fund.py +0 -629
  180. build/lib/siat/fund_china.py +0 -3307
  181. build/lib/siat/future_china.py +0 -551
  182. build/lib/siat/google_authenticator.py +0 -47
  183. build/lib/siat/grafix.py +0 -3636
  184. build/lib/siat/holding_risk.py +0 -867
  185. build/lib/siat/luchy_draw.py +0 -638
  186. build/lib/siat/market_china.py +0 -1168
  187. build/lib/siat/markowitz.py +0 -2363
  188. build/lib/siat/markowitz2.py +0 -3150
  189. build/lib/siat/markowitz2_20250704.py +0 -2969
  190. build/lib/siat/markowitz2_20250705.py +0 -3158
  191. build/lib/siat/markowitz_simple.py +0 -373
  192. build/lib/siat/ml_cases.py +0 -2291
  193. build/lib/siat/ml_cases_example.py +0 -60
  194. build/lib/siat/option_china.py +0 -3069
  195. build/lib/siat/option_pricing.py +0 -1925
  196. build/lib/siat/other_indexes.py +0 -409
  197. build/lib/siat/risk_adjusted_return.py +0 -1576
  198. build/lib/siat/risk_adjusted_return2.py +0 -1900
  199. build/lib/siat/risk_evaluation.py +0 -2218
  200. build/lib/siat/risk_free_rate.py +0 -351
  201. build/lib/siat/sector_china.py +0 -4140
  202. build/lib/siat/security_price2.py +0 -727
  203. build/lib/siat/security_prices.py +0 -3408
  204. build/lib/siat/security_trend.py +0 -402
  205. build/lib/siat/security_trend2.py +0 -646
  206. build/lib/siat/stock.py +0 -4284
  207. build/lib/siat/stock_advice_linear.py +0 -934
  208. build/lib/siat/stock_base.py +0 -26
  209. build/lib/siat/stock_china.py +0 -2095
  210. build/lib/siat/stock_prices_kneighbors.py +0 -910
  211. build/lib/siat/stock_prices_linear.py +0 -386
  212. build/lib/siat/stock_profile.py +0 -707
  213. build/lib/siat/stock_technical.py +0 -3305
  214. build/lib/siat/stooq.py +0 -74
  215. build/lib/siat/transaction.py +0 -347
  216. build/lib/siat/translate.py +0 -5183
  217. build/lib/siat/valuation.py +0 -1378
  218. build/lib/siat/valuation_china.py +0 -2076
  219. build/lib/siat/var_model_validation.py +0 -444
  220. build/lib/siat/yf_name.py +0 -811
  221. 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
@@ -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
-