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.
Files changed (218) hide show
  1. siat/__init__.py +0 -0
  2. siat/allin.py +0 -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 +0 -0
  13. siat/compare_cross.py +0 -0
  14. siat/copyrights.py +0 -0
  15. siat/cryptocurrency.py +0 -0
  16. siat/economy.py +0 -0
  17. siat/economy2.py +0 -0
  18. siat/esg.py +0 -0
  19. siat/event_study.py +0 -0
  20. siat/exchange_bond_china.pickle +0 -0
  21. siat/fama_french.py +0 -0
  22. siat/fin_stmt2_yahoo.py +0 -0
  23. siat/financial_base.py +0 -0
  24. siat/financial_statements.py +0 -0
  25. siat/financials.py +0 -0
  26. siat/financials2.py +0 -0
  27. siat/financials_china.py +0 -0
  28. siat/financials_china2.py +0 -0
  29. siat/fund.py +0 -0
  30. siat/fund_china.pickle +0 -0
  31. siat/fund_china.py +0 -0
  32. siat/future_china.py +0 -0
  33. siat/google_authenticator.py +0 -0
  34. siat/grafix.py +0 -0
  35. siat/holding_risk.py +0 -0
  36. siat/luchy_draw.py +0 -0
  37. siat/market_china.py +0 -0
  38. siat/markowitz.py +0 -0
  39. siat/markowitz2.py +0 -0
  40. siat/markowitz2_20250704.py +0 -0
  41. siat/markowitz2_20250705.py +0 -0
  42. siat/markowitz_simple.py +0 -0
  43. siat/ml_cases.py +0 -0
  44. siat/ml_cases_example.py +0 -0
  45. siat/option_china.py +0 -0
  46. siat/option_pricing.py +0 -0
  47. siat/other_indexes.py +0 -0
  48. siat/risk_adjusted_return.py +0 -0
  49. siat/risk_adjusted_return2.py +0 -0
  50. siat/risk_evaluation.py +0 -0
  51. siat/risk_free_rate.py +0 -0
  52. siat/sector_china.py +0 -0
  53. siat/security_price2.py +0 -0
  54. siat/security_prices.py +40 -2
  55. siat/security_trend.py +0 -0
  56. siat/security_trend2.py +0 -0
  57. siat/stock.py +0 -0
  58. siat/stock_advice_linear.py +0 -0
  59. siat/stock_base.py +0 -0
  60. siat/stock_china.py +0 -0
  61. siat/stock_info.pickle +0 -0
  62. siat/stock_prices_kneighbors.py +0 -0
  63. siat/stock_prices_linear.py +0 -0
  64. siat/stock_profile.py +0 -0
  65. siat/stock_technical.py +0 -0
  66. siat/stooq.py +0 -0
  67. siat/transaction.py +0 -0
  68. siat/translate.py +0 -0
  69. siat/valuation.py +0 -0
  70. siat/valuation_china.py +0 -0
  71. siat/var_model_validation.py +0 -0
  72. siat/yf_name.py +0 -0
  73. {siat-3.10.132.dist-info/licenses → siat-3.10.133.dist-info}/LICENSE +0 -0
  74. {siat-3.10.132.dist-info → siat-3.10.133.dist-info}/METADATA +232 -235
  75. siat-3.10.133.dist-info/RECORD +78 -0
  76. {siat-3.10.132.dist-info → siat-3.10.133.dist-info}/WHEEL +1 -1
  77. {siat-3.10.132.dist-info → siat-3.10.133.dist-info}/top_level.txt +0 -1
  78. build/lib/build/lib/siat/__init__.py +0 -75
  79. build/lib/build/lib/siat/allin.py +0 -137
  80. build/lib/build/lib/siat/assets_liquidity.py +0 -915
  81. build/lib/build/lib/siat/beta_adjustment.py +0 -1058
  82. build/lib/build/lib/siat/beta_adjustment_china.py +0 -548
  83. build/lib/build/lib/siat/blockchain.py +0 -143
  84. build/lib/build/lib/siat/bond.py +0 -2900
  85. build/lib/build/lib/siat/bond_base.py +0 -992
  86. build/lib/build/lib/siat/bond_china.py +0 -100
  87. build/lib/build/lib/siat/bond_zh_sina.py +0 -143
  88. build/lib/build/lib/siat/capm_beta.py +0 -783
  89. build/lib/build/lib/siat/capm_beta2.py +0 -887
  90. build/lib/build/lib/siat/common.py +0 -5360
  91. build/lib/build/lib/siat/compare_cross.py +0 -642
  92. build/lib/build/lib/siat/copyrights.py +0 -18
  93. build/lib/build/lib/siat/cryptocurrency.py +0 -667
  94. build/lib/build/lib/siat/economy.py +0 -1471
  95. build/lib/build/lib/siat/economy2.py +0 -1853
  96. build/lib/build/lib/siat/esg.py +0 -536
  97. build/lib/build/lib/siat/event_study.py +0 -815
  98. build/lib/build/lib/siat/fama_french.py +0 -1521
  99. build/lib/build/lib/siat/fin_stmt2_yahoo.py +0 -982
  100. build/lib/build/lib/siat/financial_base.py +0 -1160
  101. build/lib/build/lib/siat/financial_statements.py +0 -598
  102. build/lib/build/lib/siat/financials.py +0 -2339
  103. build/lib/build/lib/siat/financials2.py +0 -1278
  104. build/lib/build/lib/siat/financials_china.py +0 -4433
  105. build/lib/build/lib/siat/financials_china2.py +0 -2212
  106. build/lib/build/lib/siat/fund.py +0 -629
  107. build/lib/build/lib/siat/fund_china.py +0 -3307
  108. build/lib/build/lib/siat/future_china.py +0 -551
  109. build/lib/build/lib/siat/google_authenticator.py +0 -47
  110. build/lib/build/lib/siat/grafix.py +0 -3636
  111. build/lib/build/lib/siat/holding_risk.py +0 -867
  112. build/lib/build/lib/siat/luchy_draw.py +0 -638
  113. build/lib/build/lib/siat/market_china.py +0 -1168
  114. build/lib/build/lib/siat/markowitz.py +0 -2363
  115. build/lib/build/lib/siat/markowitz2.py +0 -3150
  116. build/lib/build/lib/siat/markowitz2_20250704.py +0 -2969
  117. build/lib/build/lib/siat/markowitz2_20250705.py +0 -3158
  118. build/lib/build/lib/siat/markowitz_simple.py +0 -373
  119. build/lib/build/lib/siat/ml_cases.py +0 -2291
  120. build/lib/build/lib/siat/ml_cases_example.py +0 -60
  121. build/lib/build/lib/siat/option_china.py +0 -3069
  122. build/lib/build/lib/siat/option_pricing.py +0 -1925
  123. build/lib/build/lib/siat/other_indexes.py +0 -409
  124. build/lib/build/lib/siat/risk_adjusted_return.py +0 -1576
  125. build/lib/build/lib/siat/risk_adjusted_return2.py +0 -1900
  126. build/lib/build/lib/siat/risk_evaluation.py +0 -2218
  127. build/lib/build/lib/siat/risk_free_rate.py +0 -351
  128. build/lib/build/lib/siat/sector_china.py +0 -4140
  129. build/lib/build/lib/siat/security_price2.py +0 -727
  130. build/lib/build/lib/siat/security_prices.py +0 -3408
  131. build/lib/build/lib/siat/security_trend.py +0 -402
  132. build/lib/build/lib/siat/security_trend2.py +0 -646
  133. build/lib/build/lib/siat/stock.py +0 -4284
  134. build/lib/build/lib/siat/stock_advice_linear.py +0 -934
  135. build/lib/build/lib/siat/stock_base.py +0 -26
  136. build/lib/build/lib/siat/stock_china.py +0 -2095
  137. build/lib/build/lib/siat/stock_prices_kneighbors.py +0 -910
  138. build/lib/build/lib/siat/stock_prices_linear.py +0 -386
  139. build/lib/build/lib/siat/stock_profile.py +0 -707
  140. build/lib/build/lib/siat/stock_technical.py +0 -3305
  141. build/lib/build/lib/siat/stooq.py +0 -74
  142. build/lib/build/lib/siat/transaction.py +0 -347
  143. build/lib/build/lib/siat/translate.py +0 -5183
  144. build/lib/build/lib/siat/valuation.py +0 -1378
  145. build/lib/build/lib/siat/valuation_china.py +0 -2076
  146. build/lib/build/lib/siat/var_model_validation.py +0 -444
  147. build/lib/build/lib/siat/yf_name.py +0 -811
  148. build/lib/siat/__init__.py +0 -75
  149. build/lib/siat/allin.py +0 -137
  150. build/lib/siat/assets_liquidity.py +0 -915
  151. build/lib/siat/beta_adjustment.py +0 -1058
  152. build/lib/siat/beta_adjustment_china.py +0 -548
  153. build/lib/siat/blockchain.py +0 -143
  154. build/lib/siat/bond.py +0 -2900
  155. build/lib/siat/bond_base.py +0 -992
  156. build/lib/siat/bond_china.py +0 -100
  157. build/lib/siat/bond_zh_sina.py +0 -143
  158. build/lib/siat/capm_beta.py +0 -783
  159. build/lib/siat/capm_beta2.py +0 -887
  160. build/lib/siat/common.py +0 -5360
  161. build/lib/siat/compare_cross.py +0 -642
  162. build/lib/siat/copyrights.py +0 -18
  163. build/lib/siat/cryptocurrency.py +0 -667
  164. build/lib/siat/economy.py +0 -1471
  165. build/lib/siat/economy2.py +0 -1853
  166. build/lib/siat/esg.py +0 -536
  167. build/lib/siat/event_study.py +0 -815
  168. build/lib/siat/fama_french.py +0 -1521
  169. build/lib/siat/fin_stmt2_yahoo.py +0 -982
  170. build/lib/siat/financial_base.py +0 -1160
  171. build/lib/siat/financial_statements.py +0 -598
  172. build/lib/siat/financials.py +0 -2339
  173. build/lib/siat/financials2.py +0 -1278
  174. build/lib/siat/financials_china.py +0 -4433
  175. build/lib/siat/financials_china2.py +0 -2212
  176. build/lib/siat/fund.py +0 -629
  177. build/lib/siat/fund_china.py +0 -3307
  178. build/lib/siat/future_china.py +0 -551
  179. build/lib/siat/google_authenticator.py +0 -47
  180. build/lib/siat/grafix.py +0 -3636
  181. build/lib/siat/holding_risk.py +0 -867
  182. build/lib/siat/luchy_draw.py +0 -638
  183. build/lib/siat/market_china.py +0 -1168
  184. build/lib/siat/markowitz.py +0 -2363
  185. build/lib/siat/markowitz2.py +0 -3150
  186. build/lib/siat/markowitz2_20250704.py +0 -2969
  187. build/lib/siat/markowitz2_20250705.py +0 -3158
  188. build/lib/siat/markowitz_simple.py +0 -373
  189. build/lib/siat/ml_cases.py +0 -2291
  190. build/lib/siat/ml_cases_example.py +0 -60
  191. build/lib/siat/option_china.py +0 -3069
  192. build/lib/siat/option_pricing.py +0 -1925
  193. build/lib/siat/other_indexes.py +0 -409
  194. build/lib/siat/risk_adjusted_return.py +0 -1576
  195. build/lib/siat/risk_adjusted_return2.py +0 -1900
  196. build/lib/siat/risk_evaluation.py +0 -2218
  197. build/lib/siat/risk_free_rate.py +0 -351
  198. build/lib/siat/sector_china.py +0 -4140
  199. build/lib/siat/security_price2.py +0 -727
  200. build/lib/siat/security_prices.py +0 -3408
  201. build/lib/siat/security_trend.py +0 -402
  202. build/lib/siat/security_trend2.py +0 -646
  203. build/lib/siat/stock.py +0 -4284
  204. build/lib/siat/stock_advice_linear.py +0 -934
  205. build/lib/siat/stock_base.py +0 -26
  206. build/lib/siat/stock_china.py +0 -2095
  207. build/lib/siat/stock_prices_kneighbors.py +0 -910
  208. build/lib/siat/stock_prices_linear.py +0 -386
  209. build/lib/siat/stock_profile.py +0 -707
  210. build/lib/siat/stock_technical.py +0 -3305
  211. build/lib/siat/stooq.py +0 -74
  212. build/lib/siat/transaction.py +0 -347
  213. build/lib/siat/translate.py +0 -5183
  214. build/lib/siat/valuation.py +0 -1378
  215. build/lib/siat/valuation_china.py +0 -2076
  216. build/lib/siat/var_model_validation.py +0 -444
  217. build/lib/siat/yf_name.py +0 -811
  218. siat-3.10.132.dist-info/RECORD +0 -218
@@ -1,707 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- 本模块功能:
4
- 所属工具包:提供全球股票基本信息,初版
5
- SIAT:Security Investment Analysis Tool
6
- 创建日期:2020年1月16日
7
- 最新修订日期:2020年2月4日
8
- 作者:王德宏 (WANG Dehong, Peter)
9
- 作者单位:北京外国语大学国际商学院
10
- 作者邮件:wdehong2000@163.com
11
- 版权所有:王德宏
12
- 用途限制:仅限研究与教学使用,不可商用!商用需要额外授权。
13
- 特别声明:作者不对使用本工具进行证券投资导致的任何损益负责!
14
- """
15
-
16
- #==============================================================================
17
- #屏蔽所有警告性信息
18
- import warnings; warnings.filterwarnings('ignore')
19
- #==============================================================================
20
- #以下使用雅虎财经数据源
21
- #==============================================================================
22
- if __name__ =="__main__":
23
- ticker='AAPL'
24
- ticker='1398.HK'
25
- ticker='601398.SS'
26
- ticker='000002.SZ'
27
-
28
- option='basic'
29
- option='financial'
30
- option='market'
31
-
32
-
33
- def profile(ticker,option="basic"):
34
- """
35
- 功能:显示企业基本信息
36
- 输入:股票代码
37
- 输出:企业基本信息
38
- """
39
- print(".....Searching for company profile of",ticker,".....")
40
-
41
- if not(option in ["basic","financial","market"]):
42
- print(".....Valid options: basic, financial, market")
43
- return None
44
-
45
- import datetime as dt
46
- today=dt.date.today()
47
-
48
- import yfinance as yf
49
- firm=yf.Ticker(ticker)
50
-
51
- # get stock info
52
- try:
53
- i=firm.info
54
- except:
55
- print("Stock code not found:",ticker)
56
- return None
57
-
58
- if option == "basic":
59
- print("\n=== Corporate Profile - Basics ===")
60
- print("Today:",today)
61
-
62
- print('Company Name:',i['shortName'])
63
- print('Stock Code:',i['symbol'])
64
- print('Trading Currency:',i['currency'])
65
-
66
- print('Sector:',i['sector'])
67
- print('Industry:',i['industry'])
68
-
69
- print('Company Location:',i['city']+', '+i['country'])
70
- try: addr2=i['address2']
71
- except: addr2=""
72
- print('Company Address:',i['address1']+', '+addr2)
73
- try:
74
- print('Head Office Phone:',i['phone'])
75
- except: pass
76
- print('Website:',i['website'])
77
-
78
- try:
79
- print('Full Time Employees:',format(i['fullTimeEmployees'],'0,d'))
80
- except: pass
81
-
82
- try:
83
- print('Green Finance(ESG Population):',i['isEsgPopulated'])
84
- except: pass
85
-
86
- print('Exchange Code:',i['exchange'])
87
- print('Exchange City:',i['exchangeTimezoneName'])
88
-
89
- if option == "financial":
90
- print("\n=== Corporate Profile - Financials ===")
91
- print("Today:",today)
92
- print('Company Name:',i['shortName'])
93
- #print('Dividend Yield:',i['dividendYield'])
94
- #print('Trailing Annual Dividend Yield:',i['trailingAnnualDividendYield'])
95
- #print('5-year Avg Dividend Yield:',i['fiveYearAvgDividendYield'])
96
-
97
- print('Dividend Rate('+i['currency']+'):',i['dividendRate'])
98
- print('Trailing Annual Dividend Rate:',i['trailingAnnualDividendRate'])
99
-
100
- """
101
- 注意:百分比的两种不同打印方法
102
- {:.2%}无需事先乘以100
103
- {:.2f}%需事先乘以100
104
- """
105
- print('Dividend Yield: {:.2%}'.format(i['dividendYield']))
106
- print('Trailing Annual Dividend Yield: {:.2%}'.format(i['trailingAnnualDividendYield']))
107
- print('5-year Average Dividend Yield: {:.2f}%'.format(i['fiveYearAvgDividendYield']))
108
-
109
- print('Payout Ratio: {:.2%}'.format(i['payoutRatio']))
110
-
111
- print('Trailing PE:',round(i['trailingPE'],2))
112
- print('Forward PE:',round(i['forwardPE'],2))
113
-
114
- print('Trailing EPS:',round(i['trailingEps'],2))
115
- print('Forward EPS:',round(i['forwardEps'],2))
116
-
117
- print('Profit Margins: {:.2%}'.format(i['profitMargins']))
118
- print('Earnings Quarterly Growth: {:.2%}'.format(i['earningsQuarterlyGrowth']))
119
-
120
- print('Price To Sales TTM:',round(i['priceToSalesTrailing12Months'],2))
121
-
122
- evr=i['enterpriseToRevenue']
123
- if not ((evr < 0) or (evr == None)):
124
- print('Enterprise To Revenue:',round(evr,2))
125
-
126
- evebitda=i['enterpriseToEbitda']
127
- if not (evebitda is None):
128
- print('Enterprise To EBITDA:',round(evebitda,2))
129
- print('Price To Book:',round(i['priceToBook'],2))
130
-
131
- nitc=int(i['netIncomeToCommon']/1000000)
132
- print('Net Income to Common(million):',format(nitc,'0,d'))
133
-
134
- if option == "market":
135
- print("\n=== Corporate Profile - Market ===")
136
- print("Today:",today)
137
- print('Company Name:',i['shortName'])
138
- print('Stock Code:',i['symbol'])
139
- print('Currency:',i['currency'])
140
-
141
- som=int(i['sharesOutstanding']/1000000)
142
- print('Shares Outstanding(million):',format(som,'0,d'))
143
-
144
- """
145
- Float shares=Shares outstanding - Shares held by company insiders and
146
- controlling shareholders
147
- """
148
- #fsm=int(i['floatShares']/1000000)
149
- #print('Float Shares(million):',fsm)
150
-
151
- #mktcap=int(i['marketCap']/1000000)
152
- #print('Market Capitalization(million):',format(mktcap,'0,d'))
153
-
154
- try:
155
- print('Beta:',round(i['beta'],2))
156
- except: pass
157
- print('Previous Close Price:',i['previousClose'])
158
- print('50-day Average Price:',round(i['fiftyDayAverage'],2))
159
- print('200-day Average Price:',round(i['twoHundredDayAverage'],2))
160
-
161
- print('52-week High:',i['fiftyTwoWeekHigh'])
162
- print('52-week Low:',i['fiftyTwoWeekLow'])
163
- if not (i['heldPercentInstitutions'] is None):
164
- print('Held by Institutions: {:.4%}'.format(i['heldPercentInstitutions']))
165
- if not (i['heldPercentInsiders'] is None):
166
- print('Held by Insiders: {:.4%}'.format(i['heldPercentInsiders']))
167
- #print('Short% Of Float:',i['shortPercentOfFloat'])
168
-
169
- return i
170
-
171
- if __name__ =="__main__":
172
- info=profile("600519.SS")
173
- info=profile("MSFT",option="market")
174
- info=profile("MSFT",option="financial")
175
- info=profile("600519.SS",option="financial")
176
- info=profile("0700.HK",option="financial")
177
- info=profile("TCS.NS",option="market")
178
- info=profile("BMW.DE",option="financial")
179
-
180
- #==============================================================================
181
- def get_sustainability(stocklist):
182
- """
183
- 功能:根据股票代码列表,抓取企业最新的可持续性发展数据
184
- 输入参数:
185
- stocklist:股票代码列表,例如单个股票["AAPL"], 多只股票["AAPL","MSFT","GOOG"]
186
- 输出参数:
187
- 企业最新的可持续性发展数据,数据框
188
- """
189
-
190
- #引用插件
191
- import yfinance as yf
192
- tickerlist=stocklist.copy()
193
-
194
- #测试数据,使用后请注释掉
195
- """
196
- tickerlist=["PDD","MSFT","BABA","JD","GOOG"]
197
- """
198
-
199
- #处理股票列表中的第一只股票,跳过无数据的项目
200
- skiplist=[]
201
- for t in tickerlist:
202
- tp=yf.Ticker(t)
203
- try:
204
- print("...Searching data for",t,"...",end='')
205
- sst=tp.sustainability
206
- sst.rename(columns={'Value':t},inplace=True)
207
- sstt=sst.T
208
- except: #本项目无数据,进入下一次循环
209
- print(", not found:-(")
210
- skiplist=skiplist+[t]
211
- continue
212
- skiplist=skiplist+[t]
213
- print(", done!")
214
- break
215
-
216
- #仅保留尚未处理的项目
217
- for t in skiplist: tickerlist.remove(t)
218
-
219
- #处理股票列表中的其他股票
220
- for t in tickerlist:
221
- #print("---stock:",t)
222
- tp=yf.Ticker(t)
223
- try:
224
- print("...Searching data for",t,"...",end='')
225
- sst1=tp.sustainability
226
- sst1.rename(columns={'Value':t},inplace=True)
227
- except:
228
- print(", not found:-(")
229
- continue #未抓取到数据
230
- sst1t=sst1.T
231
- try:
232
- sstt=sstt.append([sst1t])
233
- except:
234
- sstt=sstt._append([sst1t])
235
- print(", done!")
236
-
237
- #只保留需要的列
238
- sust=sstt[['totalEsg','percentile','esgPerformance','environmentScore', \
239
- 'environmentPercentile','socialScore','socialPercentile', \
240
- 'governanceScore','governancePercentile','peerGroup','peerCount']].copy()
241
- sust.rename(columns={'totalEsg':'ESGscore','percentile':'ESGpercentile', \
242
- 'esgPerformance':'ESGperformance','environmentScore':'EPscore', \
243
- 'environmentPercentile':'EPpercentile','socialScore':'CSRscore', \
244
- 'socialPercentile':'CSRpercentile','governanceScore':'CGscore', \
245
- 'governancePercentile':'CGpercentile', \
246
- 'peerGroup':'Peer Group','peerCount':'Count'},inplace=True)
247
-
248
- return sust
249
-
250
- if __name__ =="__main__":
251
- stocklist=["PDD","BABA","JD","GOOG","WMT"]
252
- sust=get_sustainability(stocklist)
253
-
254
-
255
- #==============================================================================
256
- def print_sustainability(sustainability,option="ESG"):
257
- """
258
- 功能:显示企业的可持续性发展数据
259
- 输入参数:
260
- sustainability:抓取到的企业可持续性数据框
261
- 输出参数:无
262
- """
263
-
264
- if not (option in ['ESG','EP','CSR','CG']):
265
- print("...Error 01(print_sustainability): only ESG/EP/CSR/CG are valid")
266
- return
267
-
268
- import datetime as dt
269
- today=dt.date.today()
270
- s=sustainability.copy()
271
-
272
- #显示分数和分位数
273
- if option=="ESG":
274
- s=s.sort_values(['ESGscore'],ascending=False)
275
- print("\n=== Corporate Sustainability Performance ===")
276
- esg=s[['ESGscore','ESGpercentile','ESGperformance','Peer Group','Count']]
277
- print(esg)
278
- print("\nSource: Yahoo Finance,",str(today))
279
-
280
- if option=="EP":
281
- s=s.sort_values(['EPscore'],ascending=False)
282
- print("\n=== Corporate Environment Protection Performance ===")
283
- ep=s[['EPscore','EPpercentile','Peer Group','Count']]
284
- print(ep)
285
- print("\nSource: Yahoo Finance,",str(today))
286
-
287
- if option=="CSR":
288
- s=s.sort_values(['CSRscore'],ascending=False)
289
- print("\n=== Corporate Social Responsibility Performance ===")
290
- print(s[['CSRscore','CSRpercentile','Peer Group','Count']])
291
- print("\nSource: Yahoo Finance,",str(today))
292
-
293
- if option=="CG":
294
- s=s.sort_values(['CGscore'],ascending=False)
295
- print("\n=== Corporate Governance Performance ===")
296
- print(s[['CGscore','CGpercentile','Peer Group','Count']])
297
- print("\nSource: Yahoo Finance,",str(today))
298
-
299
- return
300
-
301
- if __name__ =="__main__":
302
- print_sustainability(sust,option="ESG")
303
- print_sustainability(sust,option="EP")
304
- print_sustainability(sust,option="CSR")
305
- print_sustainability(sust,option="CG")
306
- print_sustainability(sust,option="ABC")
307
-
308
- #==============================================================================
309
- def ploth_sustainability(sustainability,option="ESG"):
310
- """
311
- 功能:显示企业的可持续性发展数据
312
- 输入参数:
313
- sustainability:抓取到的企业可持续性数据框
314
- 输出参数:无
315
- """
316
-
317
- if not (option in ['ESG','EP','CSR','CG']):
318
- print("...Error 01(plot_sustainability): only ESG/EP/CSR/CG are valid")
319
- return
320
-
321
- s=sustainability.copy()
322
- import matplotlib.pyplot as plt
323
- import datetime as dt
324
- today=dt.date.today()
325
- n=len(s)
326
-
327
- #绘制分数图
328
- if option=="ESG":
329
- #排序
330
- s=s.sort_values(['ESGscore'],ascending=True)
331
-
332
- titletxt="Corporate Sustainability Performance"
333
- plt.title(titletxt,fontsize=16,fontweight='bold')
334
-
335
- xlabeltxt1="Score"
336
- xlabeltxt=xlabeltxt1+'\n('+"Source: Yahoo Finance, "+str(today)+")"
337
- font1 = {'family':'Times New Roman','weight':'normal','size':14,}
338
- plt.xlabel(xlabeltxt,font1)
339
-
340
- if n < 6:
341
- graf=plt.barh(s.index,s['ESGscore'],facecolor='b',height=0.6,alpha=0.8)
342
- else:
343
- graf=plt.barh(s.index,s['ESGscore'],facecolor='b',alpha=0.8)
344
-
345
- plt.gca().set_facecolor('whitesmoke')
346
- plt.show()
347
-
348
- if option=="EP":
349
- s=s.sort_values(['EPscore'],ascending=True)
350
-
351
- titletxt="Corporate Environment Protection Performance"
352
- plt.title(titletxt,fontsize=13,fontweight='bold')
353
-
354
- xlabeltxt1="Score"
355
- xlabeltxt=xlabeltxt1+'\n('+"Source: Yahoo Finance, "+str(today)+")"
356
- font1 = {'family':'Times New Roman','weight':'normal','size':14,}
357
- plt.xlabel(xlabeltxt,font1)
358
-
359
- if n < 6:
360
- graf=plt.barh(s.index,s['EPscore'],facecolor='g',height=0.6,alpha=0.8)
361
- else:
362
- graf=plt.barh(s.index,s['EPscore'],facecolor='g',alpha=0.8)
363
-
364
- plt.gca().set_facecolor('whitesmoke')
365
- plt.show()
366
-
367
- if option=="CSR":
368
- s=s.sort_values(['CSRscore'],ascending=True)
369
-
370
- titletxt="Corporate Social Responsibility Performance"
371
- plt.title(titletxt,fontsize=13,fontweight='bold')
372
-
373
- xlabeltxt1="Score"
374
- xlabeltxt=xlabeltxt1+'\n('+"Source: Yahoo Finance, "+str(today)+")"
375
- font1 = {'family':'Times New Roman','weight':'normal','size':14,}
376
- plt.xlabel(xlabeltxt,font1)
377
-
378
- if n < 6:
379
- graf=plt.barh(s.index,s['CSRscore'],facecolor='tan',height=0.6,alpha=0.8)
380
- else:
381
- graf=plt.barh(s.index,s['CSRscore'],facecolor='tan',alpha=0.8)
382
-
383
- plt.gca().set_facecolor('whitesmoke')
384
- plt.show()
385
-
386
- if option=="CG":
387
- s=s.sort_values(['CGscore'],ascending=True)
388
-
389
- titletxt="Corporate Governance Performance"
390
- plt.title(titletxt,fontsize=16,fontweight='bold')
391
-
392
- xlabeltxt1="Score"
393
- xlabeltxt=xlabeltxt1+'\n('+"Source: Yahoo Finance, "+str(today)+")"
394
- font1 = {'family':'Times New Roman','weight':'normal','size':14,}
395
- plt.xlabel(xlabeltxt,font1)
396
-
397
- if n < 6:
398
- graf=plt.barh(s.index,s['CGscore'],facecolor='y',height=0.6,alpha=0.9)
399
- else:
400
- graf=plt.barh(s.index,s['CGscore'],facecolor='y',alpha=0.9)
401
-
402
- plt.gca().set_facecolor('whitesmoke')
403
- plt.show()
404
-
405
- #绘制分位数图
406
- if option=="ESG":
407
- #排序
408
- s=s.sort_values(['ESGpercentile'],ascending=True)
409
-
410
- titletxt="Corporate Sustainability Performance"
411
- plt.title(titletxt,fontsize=16,fontweight='bold')
412
-
413
- xlabeltxt1="Percentile in industrial sector"
414
- xlabeltxt=xlabeltxt1+'\n('+"Source: Yahoo Finance, "+str(today)+")"
415
- font1 = {'family':'Times New Roman','weight':'normal','size':14,}
416
- plt.xlabel(xlabeltxt,font1)
417
-
418
- if n < 6:
419
- graf=plt.barh(s.index,s['ESGpercentile'],facecolor='b',height=0.6,alpha=0.8)
420
- else:
421
- graf=plt.barh(s.index,s['ESGpercentile'],facecolor='b',alpha=0.8)
422
-
423
- plt.gca().set_facecolor('whitesmoke')
424
- plt.show()
425
-
426
- if option=="EP":
427
- s=s.sort_values(['EPpercentile'],ascending=True)
428
-
429
- titletxt="Corporate Environment Protection Performance"
430
- plt.title(titletxt,fontsize=13,fontweight='bold')
431
-
432
- xlabeltxt1="Percentile in industrial sector"
433
- xlabeltxt=xlabeltxt1+'\n('+"Source: Yahoo Finance, "+str(today)+")"
434
- font1 = {'family':'Times New Roman','weight':'normal','size':14,}
435
- plt.xlabel(xlabeltxt,font1)
436
-
437
- if n < 6:
438
- graf=plt.barh(s.index,s['EPpercentile'],facecolor='g',height=0.6,alpha=0.8)
439
- else:
440
- graf=plt.barh(s.index,s['EPpercentile'],facecolor='g',alpha=0.8)
441
-
442
- plt.gca().set_facecolor('whitesmoke')
443
- plt.show()
444
-
445
- if option=="CSR":
446
- s=s.sort_values(['CSRpercentile'],ascending=True)
447
-
448
- titletxt="Corporate Social Responsibility Performance"
449
- plt.title(titletxt,fontsize=13,fontweight='bold')
450
-
451
- xlabeltxt1="Percentile in industrial sector"
452
- xlabeltxt=xlabeltxt1+'\n('+"Source: Yahoo Finance, "+str(today)+")"
453
- font1 = {'family':'Times New Roman','weight':'normal','size':14,}
454
- plt.xlabel(xlabeltxt,font1)
455
-
456
- if n < 6:
457
- graf=plt.barh(s.index,s['CSRpercentile'],facecolor='tan',height=0.6,alpha=0.8)
458
- else:
459
- graf=plt.barh(s.index,s['CSRpercentile'],facecolor='tan',alpha=0.8)
460
-
461
- plt.gca().set_facecolor('whitesmoke')
462
- plt.show()
463
-
464
- if option=="CG":
465
- s=s.sort_values(['CGpercentile'],ascending=True)
466
-
467
- titletxt="Corporate Governance Performance"
468
- plt.title(titletxt,fontsize=16,fontweight='bold')
469
-
470
- xlabeltxt1="Percentile in industrial sector"
471
- xlabeltxt=xlabeltxt1+'\n('+"Source: Yahoo Finance, "+str(today)+")"
472
- font1 = {'family':'Times New Roman','weight':'normal','size':14,}
473
- plt.xlabel(xlabeltxt,font1)
474
-
475
- if n < 6:
476
- graf=plt.barh(s.index,s['CGpercentile'],facecolor='y',height=0.6,alpha=0.9)
477
- else:
478
- graf=plt.barh(s.index,s['CGpercentile'],facecolor='y',alpha=0.9)
479
-
480
- plt.gca().set_facecolor('whitesmoke')
481
- plt.show()
482
-
483
- return
484
-
485
- if __name__ =="__main__":
486
- ploth_sustainability(sust,option="ESG")
487
- ploth_sustainability(sust,option="EP")
488
- ploth_sustainability(sust,option="CSR")
489
- ploth_sustainability(sust,option="CG")
490
-
491
- #==============================================================================
492
- def plot_sustainability(sustainability,option="ESG"):
493
- """
494
- 功能:显示企业的可持续性发展数据,同时显示分数和分位数
495
- 输入参数:
496
- sustainability:抓取到的企业可持续性数据框
497
- 输出参数:无
498
- """
499
-
500
- if not (option in ['ESG','EP','CSR','CG']):
501
- print("...Error 01(plot_sustainability): only ESG/EP/CSR/CG are valid")
502
- return
503
-
504
- s=sustainability.copy()
505
-
506
- import numpy as np
507
- import matplotlib.pyplot as plt
508
- #from matplotlib.ticker import MultipleLocator
509
- import datetime as dt
510
-
511
- today=dt.date.today()
512
- l=len(s.index)
513
- n=np.arange(l)
514
- if l < 6: width=0.45 #经验值,0.45*6=2.7
515
- else: width=round(2.9/l,2)
516
- #print("Firms:",s.index,", Width:",width)
517
-
518
- #fig,ax=plt.subplots(figsize=(10,6))
519
- fig,ax=plt.subplots(figsize=(12.8,6.4))
520
-
521
- #绘制分数和分位数图
522
- if option=="ESG":
523
- s=s.sort_values(['ESGscore'],ascending=False)
524
-
525
- b1=ax.bar(n-width/2,s['ESGscore'],width,tick_label=s.index,label='Score')
526
- b2=ax.bar(n+width/2,s['ESGpercentile'],width,label='Percentile (%)')
527
-
528
- plt.legend(loc='best')
529
-
530
- for b in b1+b2:
531
- h=b.get_height()
532
- ax.text(b.get_x()+b.get_width()/2,h,h,ha='center',va='bottom')
533
-
534
- fontlabel={'family':'Times New Roman','weight':'normal','size':16}
535
- plt.ylabel('ESG Index',fontlabel)
536
- plt.ylim(0,100)
537
- xlabeltxt='\n'+"Source: Yahoo Finance, "+str(today)
538
- plt.xlabel(xlabeltxt,fontlabel)
539
-
540
- titletxt="Corporate Sustainability Performance (ESG)"
541
- fonttitle={'family':'Times New Roman','weight':'normal','size':24}
542
- plt.title(titletxt,fonttitle)
543
-
544
- plt.gca().set_facecolor('whitesmoke')
545
- plt.show()
546
-
547
- if option=="EP":
548
- s=s.sort_values(['EPscore'],ascending=False)
549
-
550
- b1=ax.bar(n-width/2,s['EPscore'],width,tick_label=s.index,label='Score')
551
- b2=ax.bar(n+width/2,s['EPpercentile'],width,label='Percentile (%)')
552
- plt.legend(loc='best')
553
-
554
- for b in b1+b2:
555
- h=b.get_height()
556
- ax.text(b.get_x()+b.get_width()/2,h,h,ha='center',va='bottom')
557
-
558
- fontlabel={'family':'Times New Roman','weight':'normal','size':16}
559
- plt.ylabel('EP Index',fontlabel)
560
- plt.ylim(0,100)
561
- xlabeltxt='\n'+"Source: Yahoo Finance, "+str(today)
562
- plt.xlabel(xlabeltxt,fontlabel)
563
-
564
- titletxt="Corporate Environment Protection Performance (EP)"
565
- fonttitle={'family':'Times New Roman','weight':'normal','size':22}
566
- plt.title(titletxt,fonttitle)
567
-
568
- plt.gca().set_facecolor('whitesmoke')
569
- plt.show()
570
-
571
- if option=="CSR":
572
- s=s.sort_values(['CSRscore'],ascending=False)
573
-
574
- b1=ax.bar(n-width/2,s['CSRscore'],width,tick_label=s.index,label='Score')
575
- b2=ax.bar(n+width/2,s['CSRpercentile'],width,label='Percentile (%)')
576
- plt.legend(loc='best')
577
-
578
- for b in b1+b2:
579
- h=b.get_height()
580
- ax.text(b.get_x()+b.get_width()/2,h,h,ha='center',va='bottom')
581
-
582
- fontlabel={'family':'Times New Roman','weight':'normal','size':16}
583
- plt.ylabel('CSR Index',fontlabel)
584
- plt.ylim(0,100)
585
- xlabeltxt='\n'+"Source: Yahoo Finance, "+str(today)
586
- plt.xlabel(xlabeltxt,fontlabel)
587
-
588
- titletxt="Corporate Social Responsibility Performance (CSR)"
589
- fonttitle={'family':'Times New Roman','weight':'normal','size':22}
590
- plt.title(titletxt,fonttitle)
591
-
592
- plt.gca().set_facecolor('whitesmoke')
593
- plt.show()
594
-
595
- if option=="CG":
596
- s=s.sort_values(['CGscore'],ascending=False)
597
-
598
- b1=ax.bar(n-width/2,s['CGscore'],width,tick_label=s.index,label='Score')
599
- b2=ax.bar(n+width/2,s['CGpercentile'],width,label='Percentile (%)')
600
- plt.legend(loc='best')
601
-
602
- for b in b1+b2:
603
- h=b.get_height()
604
- ax.text(b.get_x()+b.get_width()/2,h,h,ha='center',va='bottom')
605
-
606
- fontlabel={'family':'Times New Roman','weight':'normal','size':16}
607
- plt.ylabel('CG Index',fontlabel)
608
- plt.ylim(0,100)
609
- xlabeltxt='\n'+"Source: Yahoo Finance, "+str(today)
610
- plt.xlabel(xlabeltxt,fontlabel)
611
-
612
- titletxt="Corporate Governance Performance (CG)"
613
- fonttitle={'family':'Times New Roman','weight':'normal','size':24}
614
- plt.title(titletxt,fonttitle)
615
-
616
- plt.gca().set_facecolor('whitesmoke')
617
- plt.show()
618
-
619
- return
620
-
621
- if __name__ =="__main__":
622
- plot_sustainability(sust,option="ESG")
623
- plot_sustainability(sust,option="EP")
624
- plot_sustainability(sust,option="CSR")
625
- plot_sustainability(sust,option="CG")
626
-
627
- stocklist2=["AMZN","EBAY","BABA","JD","VIPS","WMT"]
628
- sust2=get_sustainability(stocklist2)
629
- plot_sustainability(sust2)
630
- #==============================================================================
631
- def sustainability(stocklist):
632
- """
633
- 功能:抓取、打印和绘图企业的可持续性发展数据,演示用
634
- 输入参数:
635
- stocklist:股票代码列表,例如单个股票["AAPL"], 多只股票["AAPL","MSFT","GOOG"]
636
- 输出参数:
637
- 企业最新的可持续性发展数据,数据框
638
- """
639
-
640
- #抓取数据
641
- sust=get_sustainability(stocklist)
642
-
643
- #打印和绘图ESG
644
- ploth_sustainability(sust,option="ESG")
645
- print_sustainability(sust,option="ESG")
646
- #打印和绘图EP
647
- ploth_sustainability(sust,option="EP")
648
- print_sustainability(sust,option="EP")
649
- #打印和绘图CSR
650
- ploth_sustainability(sust,option="CSR")
651
- print_sustainability(sust,option="CSR")
652
- #打印和绘图CG
653
- ploth_sustainability(sust,option="CG")
654
- print_sustainability(sust,option="CG")
655
-
656
- return sust
657
-
658
- if __name__ =="__main__":
659
- stocklist1=["AMZN","EBAY","BABA"]
660
- sust1=sustainability(stocklist1)
661
- stocklist2=["AMZN","EBAY","BABA","JD","VIPS","WMT"]
662
- sust2=sustainability(stocklist2)
663
-
664
- #==============================================================================
665
- #==============================================================================
666
- def sustainability2(stocklist):
667
- """
668
- 功能:抓取、打印和绘图企业的可持续性发展数据,演示用
669
- 输入参数:
670
- stocklist:股票代码列表,例如单个股票["AAPL"], 多只股票["AAPL","MSFT","GOOG"]
671
- 输出参数:
672
- 企业最新的可持续性发展数据,数据框
673
- """
674
-
675
- #抓取数据
676
- sust=get_sustainability(stocklist)
677
-
678
- #打印和绘图ESG
679
- plot_sustainability(sust,option="ESG")
680
- print_sustainability(sust,option="ESG")
681
- #打印和绘图EP
682
- plot_sustainability(sust,option="EP")
683
- print_sustainability(sust,option="EP")
684
- #打印和绘图CSR
685
- plot_sustainability(sust,option="CSR")
686
- print_sustainability(sust,option="CSR")
687
- #打印和绘图CG
688
- plot_sustainability(sust,option="CG")
689
- print_sustainability(sust,option="CG")
690
-
691
- return sust
692
-
693
- if __name__ =="__main__":
694
- stocklist1=["AMZN","EBAY","BABA"]
695
- sust1=sustainability2(stocklist1)
696
- stocklist2=["AMZN","EBAY","BABA","JD","VIPS","WMT"]
697
- sust2=sustainability2(stocklist2)
698
-
699
-
700
-
701
-
702
-
703
-
704
-
705
-
706
-
707
-