siat 3.10.132__py3-none-any.whl → 3.11.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- siat/__init__.py +0 -0
- siat/allin.py +8 -0
- siat/assets_liquidity.py +0 -0
- siat/beta_adjustment.py +0 -0
- siat/beta_adjustment_china.py +0 -0
- siat/blockchain.py +0 -0
- siat/bond.py +0 -0
- siat/bond_base.py +0 -0
- siat/bond_china.py +0 -0
- siat/bond_zh_sina.py +0 -0
- siat/capm_beta.py +0 -0
- siat/capm_beta2.py +4 -4
- siat/common.py +9 -6
- siat/compare_cross.py +0 -0
- siat/copyrights.py +0 -0
- siat/cryptocurrency.py +0 -0
- siat/economy.py +0 -0
- siat/economy2.py +0 -0
- siat/esg.py +0 -0
- siat/event_study.py +0 -0
- siat/exchange_bond_china.pickle +0 -0
- siat/fama_french.py +0 -0
- siat/fin_stmt2_yahoo.py +0 -0
- siat/financial_base.py +0 -0
- siat/financial_statements.py +0 -0
- siat/financials.py +0 -0
- siat/financials2.py +0 -0
- siat/financials_china.py +0 -0
- siat/financials_china2.py +0 -0
- siat/fund.py +0 -0
- siat/fund_china.pickle +0 -0
- siat/fund_china.py +0 -0
- siat/future_china.py +0 -0
- siat/google_authenticator.py +0 -0
- siat/grafix.py +55 -4
- siat/holding_risk.py +0 -0
- siat/luchy_draw.py +0 -0
- siat/market_china.py +0 -0
- siat/markowitz.py +0 -0
- siat/markowitz2.py +1 -0
- siat/markowitz2_20250704.py +0 -0
- siat/markowitz2_20250705.py +0 -0
- siat/markowitz_simple.py +0 -0
- siat/ml_cases.py +0 -0
- siat/ml_cases_example.py +0 -0
- siat/option_china.py +0 -0
- siat/option_pricing.py +0 -0
- siat/other_indexes.py +0 -0
- siat/risk_adjusted_return.py +0 -0
- siat/risk_adjusted_return2.py +8 -4
- siat/risk_evaluation.py +0 -0
- siat/risk_free_rate.py +0 -0
- siat/save2docx.py +345 -0
- siat/save2pdf.py +145 -0
- siat/sector_china.py +0 -0
- siat/security_price2.py +0 -0
- siat/security_prices.py +168 -6
- siat/security_trend.py +0 -0
- siat/security_trend2.py +2 -2
- siat/stock.py +11 -1
- siat/stock_advice_linear.py +0 -0
- siat/stock_base.py +0 -0
- siat/stock_china.py +0 -0
- siat/stock_info.pickle +0 -0
- siat/stock_prices_kneighbors.py +0 -0
- siat/stock_prices_linear.py +0 -0
- siat/stock_profile.py +0 -0
- siat/stock_technical.py +0 -0
- siat/stooq.py +0 -0
- siat/transaction.py +0 -0
- siat/translate.py +0 -0
- siat/valuation.py +0 -0
- siat/valuation_china.py +0 -0
- siat/var_model_validation.py +0 -0
- siat/yf_name.py +0 -0
- {siat-3.10.132.dist-info/licenses → siat-3.11.1.dist-info}/LICENSE +0 -0
- {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/METADATA +234 -235
- siat-3.11.1.dist-info/RECORD +80 -0
- {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/WHEEL +1 -1
- {siat-3.10.132.dist-info → siat-3.11.1.dist-info}/top_level.txt +0 -1
- build/lib/build/lib/siat/__init__.py +0 -75
- build/lib/build/lib/siat/allin.py +0 -137
- build/lib/build/lib/siat/assets_liquidity.py +0 -915
- build/lib/build/lib/siat/beta_adjustment.py +0 -1058
- build/lib/build/lib/siat/beta_adjustment_china.py +0 -548
- build/lib/build/lib/siat/blockchain.py +0 -143
- build/lib/build/lib/siat/bond.py +0 -2900
- build/lib/build/lib/siat/bond_base.py +0 -992
- build/lib/build/lib/siat/bond_china.py +0 -100
- build/lib/build/lib/siat/bond_zh_sina.py +0 -143
- build/lib/build/lib/siat/capm_beta.py +0 -783
- build/lib/build/lib/siat/capm_beta2.py +0 -887
- build/lib/build/lib/siat/common.py +0 -5360
- build/lib/build/lib/siat/compare_cross.py +0 -642
- build/lib/build/lib/siat/copyrights.py +0 -18
- build/lib/build/lib/siat/cryptocurrency.py +0 -667
- build/lib/build/lib/siat/economy.py +0 -1471
- build/lib/build/lib/siat/economy2.py +0 -1853
- build/lib/build/lib/siat/esg.py +0 -536
- build/lib/build/lib/siat/event_study.py +0 -815
- build/lib/build/lib/siat/fama_french.py +0 -1521
- build/lib/build/lib/siat/fin_stmt2_yahoo.py +0 -982
- build/lib/build/lib/siat/financial_base.py +0 -1160
- build/lib/build/lib/siat/financial_statements.py +0 -598
- build/lib/build/lib/siat/financials.py +0 -2339
- build/lib/build/lib/siat/financials2.py +0 -1278
- build/lib/build/lib/siat/financials_china.py +0 -4433
- build/lib/build/lib/siat/financials_china2.py +0 -2212
- build/lib/build/lib/siat/fund.py +0 -629
- build/lib/build/lib/siat/fund_china.py +0 -3307
- build/lib/build/lib/siat/future_china.py +0 -551
- build/lib/build/lib/siat/google_authenticator.py +0 -47
- build/lib/build/lib/siat/grafix.py +0 -3636
- build/lib/build/lib/siat/holding_risk.py +0 -867
- build/lib/build/lib/siat/luchy_draw.py +0 -638
- build/lib/build/lib/siat/market_china.py +0 -1168
- build/lib/build/lib/siat/markowitz.py +0 -2363
- build/lib/build/lib/siat/markowitz2.py +0 -3150
- build/lib/build/lib/siat/markowitz2_20250704.py +0 -2969
- build/lib/build/lib/siat/markowitz2_20250705.py +0 -3158
- build/lib/build/lib/siat/markowitz_simple.py +0 -373
- build/lib/build/lib/siat/ml_cases.py +0 -2291
- build/lib/build/lib/siat/ml_cases_example.py +0 -60
- build/lib/build/lib/siat/option_china.py +0 -3069
- build/lib/build/lib/siat/option_pricing.py +0 -1925
- build/lib/build/lib/siat/other_indexes.py +0 -409
- build/lib/build/lib/siat/risk_adjusted_return.py +0 -1576
- build/lib/build/lib/siat/risk_adjusted_return2.py +0 -1900
- build/lib/build/lib/siat/risk_evaluation.py +0 -2218
- build/lib/build/lib/siat/risk_free_rate.py +0 -351
- build/lib/build/lib/siat/sector_china.py +0 -4140
- build/lib/build/lib/siat/security_price2.py +0 -727
- build/lib/build/lib/siat/security_prices.py +0 -3408
- build/lib/build/lib/siat/security_trend.py +0 -402
- build/lib/build/lib/siat/security_trend2.py +0 -646
- build/lib/build/lib/siat/stock.py +0 -4284
- build/lib/build/lib/siat/stock_advice_linear.py +0 -934
- build/lib/build/lib/siat/stock_base.py +0 -26
- build/lib/build/lib/siat/stock_china.py +0 -2095
- build/lib/build/lib/siat/stock_prices_kneighbors.py +0 -910
- build/lib/build/lib/siat/stock_prices_linear.py +0 -386
- build/lib/build/lib/siat/stock_profile.py +0 -707
- build/lib/build/lib/siat/stock_technical.py +0 -3305
- build/lib/build/lib/siat/stooq.py +0 -74
- build/lib/build/lib/siat/transaction.py +0 -347
- build/lib/build/lib/siat/translate.py +0 -5183
- build/lib/build/lib/siat/valuation.py +0 -1378
- build/lib/build/lib/siat/valuation_china.py +0 -2076
- build/lib/build/lib/siat/var_model_validation.py +0 -444
- build/lib/build/lib/siat/yf_name.py +0 -811
- build/lib/siat/__init__.py +0 -75
- build/lib/siat/allin.py +0 -137
- build/lib/siat/assets_liquidity.py +0 -915
- build/lib/siat/beta_adjustment.py +0 -1058
- build/lib/siat/beta_adjustment_china.py +0 -548
- build/lib/siat/blockchain.py +0 -143
- build/lib/siat/bond.py +0 -2900
- build/lib/siat/bond_base.py +0 -992
- build/lib/siat/bond_china.py +0 -100
- build/lib/siat/bond_zh_sina.py +0 -143
- build/lib/siat/capm_beta.py +0 -783
- build/lib/siat/capm_beta2.py +0 -887
- build/lib/siat/common.py +0 -5360
- build/lib/siat/compare_cross.py +0 -642
- build/lib/siat/copyrights.py +0 -18
- build/lib/siat/cryptocurrency.py +0 -667
- build/lib/siat/economy.py +0 -1471
- build/lib/siat/economy2.py +0 -1853
- build/lib/siat/esg.py +0 -536
- build/lib/siat/event_study.py +0 -815
- build/lib/siat/fama_french.py +0 -1521
- build/lib/siat/fin_stmt2_yahoo.py +0 -982
- build/lib/siat/financial_base.py +0 -1160
- build/lib/siat/financial_statements.py +0 -598
- build/lib/siat/financials.py +0 -2339
- build/lib/siat/financials2.py +0 -1278
- build/lib/siat/financials_china.py +0 -4433
- build/lib/siat/financials_china2.py +0 -2212
- build/lib/siat/fund.py +0 -629
- build/lib/siat/fund_china.py +0 -3307
- build/lib/siat/future_china.py +0 -551
- build/lib/siat/google_authenticator.py +0 -47
- build/lib/siat/grafix.py +0 -3636
- build/lib/siat/holding_risk.py +0 -867
- build/lib/siat/luchy_draw.py +0 -638
- build/lib/siat/market_china.py +0 -1168
- build/lib/siat/markowitz.py +0 -2363
- build/lib/siat/markowitz2.py +0 -3150
- build/lib/siat/markowitz2_20250704.py +0 -2969
- build/lib/siat/markowitz2_20250705.py +0 -3158
- build/lib/siat/markowitz_simple.py +0 -373
- build/lib/siat/ml_cases.py +0 -2291
- build/lib/siat/ml_cases_example.py +0 -60
- build/lib/siat/option_china.py +0 -3069
- build/lib/siat/option_pricing.py +0 -1925
- build/lib/siat/other_indexes.py +0 -409
- build/lib/siat/risk_adjusted_return.py +0 -1576
- build/lib/siat/risk_adjusted_return2.py +0 -1900
- build/lib/siat/risk_evaluation.py +0 -2218
- build/lib/siat/risk_free_rate.py +0 -351
- build/lib/siat/sector_china.py +0 -4140
- build/lib/siat/security_price2.py +0 -727
- build/lib/siat/security_prices.py +0 -3408
- build/lib/siat/security_trend.py +0 -402
- build/lib/siat/security_trend2.py +0 -646
- build/lib/siat/stock.py +0 -4284
- build/lib/siat/stock_advice_linear.py +0 -934
- build/lib/siat/stock_base.py +0 -26
- build/lib/siat/stock_china.py +0 -2095
- build/lib/siat/stock_prices_kneighbors.py +0 -910
- build/lib/siat/stock_prices_linear.py +0 -386
- build/lib/siat/stock_profile.py +0 -707
- build/lib/siat/stock_technical.py +0 -3305
- build/lib/siat/stooq.py +0 -74
- build/lib/siat/transaction.py +0 -347
- build/lib/siat/translate.py +0 -5183
- build/lib/siat/valuation.py +0 -1378
- build/lib/siat/valuation_china.py +0 -2076
- build/lib/siat/var_model_validation.py +0 -444
- build/lib/siat/yf_name.py +0 -811
- siat-3.10.132.dist-info/RECORD +0 -218
@@ -1,1853 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
"""
|
3
|
-
本模块功能:宏观经济基本面分析
|
4
|
-
所属工具包:证券投资分析工具SIAT
|
5
|
-
SIAT:Security Investment Analysis Tool
|
6
|
-
创建日期:2025年3月9日
|
7
|
-
最新修订日期:2025年3月10日
|
8
|
-
作者:王德宏 (WANG Dehong, Peter)
|
9
|
-
作者单位:北京外国语大学国际商学院
|
10
|
-
版权所有:王德宏
|
11
|
-
用途限制:仅限研究与教学使用,不可商用!商用需要额外授权。
|
12
|
-
特别声明:作者不对使用本工具进行证券投资导致的任何损益负责!
|
13
|
-
"""
|
14
|
-
#==============================================================================
|
15
|
-
#关闭所有警告
|
16
|
-
import warnings; warnings.filterwarnings('ignore')
|
17
|
-
from siat.grafix import *
|
18
|
-
from siat.common import *
|
19
|
-
from siat.translate import *
|
20
|
-
#==============================================================================
|
21
|
-
import pandas as pd
|
22
|
-
from pandas_datareader import wb
|
23
|
-
import requests
|
24
|
-
|
25
|
-
#==============================================================================
|
26
|
-
if __name__=='__main__':
|
27
|
-
key_words='NY.GDP.MKTP'
|
28
|
-
key_words='per_allsp_gini_rur'
|
29
|
-
|
30
|
-
search_id_only=True
|
31
|
-
return_id_list=True
|
32
|
-
top=20; country='CN'; max_sleep=30; start='L3Y'
|
33
|
-
|
34
|
-
def test_economic_indicator(key_words='NY.GDP.MKTP',top=20, \
|
35
|
-
country='CN',max_sleep=30,start='L3Y'):
|
36
|
-
"""
|
37
|
-
===========================================================================
|
38
|
-
功能:测试某一类宏观经济指标的可用性
|
39
|
-
参数:
|
40
|
-
key_words:宏观经济指标类别,默认GDP系列指标'NY.GDP.MKTP'
|
41
|
-
country:测试使用的经济体,默认中国'CN'
|
42
|
-
max_sleep:测试指标指标之间的最大间隔秒数,默认30。若间隔时间过短可能被数据源屏蔽
|
43
|
-
"""
|
44
|
-
print(f"*** Indicator magic={key_words}, top={top}, country={country}, start={start}:")
|
45
|
-
id_list=indicator_wb(key_words,top=top,search_id_only=True,return_id_list=True)
|
46
|
-
id_list_usable=id_list.copy() #需要使用copy,不然两者始终同步
|
47
|
-
|
48
|
-
#屏蔽函数内print信息输出的类
|
49
|
-
import os, sys
|
50
|
-
class HiddenPrints:
|
51
|
-
def __enter__(self):
|
52
|
-
self._original_stdout = sys.stdout
|
53
|
-
sys.stdout = open(os.devnull, 'w')
|
54
|
-
|
55
|
-
def __exit__(self, exc_type, exc_val, exc_tb):
|
56
|
-
sys.stdout.close()
|
57
|
-
sys.stdout = self._original_stdout
|
58
|
-
|
59
|
-
print(f'\nTesting the above indicators in {country}, please wait ... ...') #空一行
|
60
|
-
for id in id_list:
|
61
|
-
#print(f"Testing {id} ... ...")
|
62
|
-
print_progress_percent2(id,id_list,steps=10,leading_blanks=4)
|
63
|
-
|
64
|
-
with HiddenPrints():
|
65
|
-
df=economy_trend2(country,indicator=id,start=start,graph=False)
|
66
|
-
|
67
|
-
if df is None:
|
68
|
-
#print(f"*** {id} deprecated or not provided for {country}")
|
69
|
-
id_list_usable.remove(id)
|
70
|
-
elif len(df)==0:
|
71
|
-
#printf(f"### {id} has no data for {country}")
|
72
|
-
id_list_usable.remove(id)
|
73
|
-
|
74
|
-
sleep_random(max_sleep)
|
75
|
-
|
76
|
-
print(f"\n*** Economic indicators available for {country}:")
|
77
|
-
for id in id_list_usable:
|
78
|
-
pos=id_list.index(id)+1
|
79
|
-
print(f"{pos} {id}")
|
80
|
-
|
81
|
-
return
|
82
|
-
|
83
|
-
|
84
|
-
#==============================================================================
|
85
|
-
if __name__=='__main__':
|
86
|
-
key_words='GDP per capita'
|
87
|
-
top=5; note=False
|
88
|
-
|
89
|
-
indicator_wb(key_words='GDP',top=10,note=False)
|
90
|
-
|
91
|
-
def find_economic_indicator(key_words='GDP',top=20, \
|
92
|
-
note=False,translate=False,source='wb', \
|
93
|
-
search_id_only=False, \
|
94
|
-
return_id_list=False):
|
95
|
-
"""
|
96
|
-
===========================================================================
|
97
|
-
功能:查找宏观经济指标代码
|
98
|
-
参数:
|
99
|
-
key_words:关键词,支持多关键词,使用空格隔开,默认'GDP'
|
100
|
-
top:显示最相似的若干个指标,默认10
|
101
|
-
note:是否显示指标的描述,默认否False
|
102
|
-
translate:是否调用AI大模型进行翻译,若翻译可能影响反应速度,默认否False
|
103
|
-
source:信息来源,默认'wb'
|
104
|
-
search_id_only:是否仅仅查找指标代码,默认False;
|
105
|
-
否则只查找指标代码,用于快速查找类似指标。
|
106
|
-
return_id_list:是否返回指标代码列表,默认False;
|
107
|
-
否则可用于快速检查返回的指标是否有数据、新数据或者已经deprecated
|
108
|
-
|
109
|
-
注意:有时网络可能拒绝访问,可以换个时段再次进行访问
|
110
|
-
"""
|
111
|
-
if source=='wb':
|
112
|
-
df=indicator_wb(key_words=key_words,top=top,note=note,translate=translate, \
|
113
|
-
search_id_only=search_id_only,return_id_list=return_id_list)
|
114
|
-
else:
|
115
|
-
print(" Sorry, the source option currently only supports wb (World Bank)")
|
116
|
-
|
117
|
-
return
|
118
|
-
|
119
|
-
#==============================================================================
|
120
|
-
|
121
|
-
if __name__=='__main__':
|
122
|
-
key_words='GDP'
|
123
|
-
key_words='NY.GDP.MKTP'
|
124
|
-
|
125
|
-
top=20; note=False; translate=False
|
126
|
-
search_id_only=True
|
127
|
-
return_id_list=True
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
def indicator_wb(key_words='GDP',top=20,note=False,translate=False, \
|
132
|
-
search_id_only=False, \
|
133
|
-
return_id_list=False):
|
134
|
-
"""
|
135
|
-
============================================================================
|
136
|
-
功能:在WB/IMF/FRED数据库中查找宏观经济指标的代码
|
137
|
-
参数:
|
138
|
-
key_words:可包括多个关键词,使用空格隔开,不区分大小写
|
139
|
-
top:输出相似度最高的,默认20个
|
140
|
-
note:是否显示每个指标的注释,默认False
|
141
|
-
translate: 是否翻译,默认False
|
142
|
-
search_id_only:是否仅仅查找指标代码,默认False;
|
143
|
-
否则只查找指标代码,用于快速查找类似指标。
|
144
|
-
return_id_list:是否返回指标代码列表,默认False;
|
145
|
-
否则可用于快速检查返回的指标是否有数据、新数据或者已经deprecated
|
146
|
-
|
147
|
-
输出:基于文本相似度,输出可能的指标代码及其简介
|
148
|
-
|
149
|
-
返回值:可能的指标代码及其简介
|
150
|
-
"""
|
151
|
-
import re
|
152
|
-
|
153
|
-
# 拆分关键词字符串为列表
|
154
|
-
#words_list=key_words.split(' ')
|
155
|
-
if not search_id_only:
|
156
|
-
words_list=re.split(r'[\s,.,]+', key_words)
|
157
|
-
else:
|
158
|
-
words_list=[key_words]
|
159
|
-
|
160
|
-
# 循环查找每个关键词,并合成
|
161
|
-
df=None
|
162
|
-
for word in words_list:
|
163
|
-
try:
|
164
|
-
if not search_id_only:
|
165
|
-
df_tmp=wb.search(word)
|
166
|
-
else:
|
167
|
-
df_tmp=wb.search('')
|
168
|
-
except:
|
169
|
-
#print(" Sorry, data source rejected connection, try again later")
|
170
|
-
break
|
171
|
-
|
172
|
-
# 合并
|
173
|
-
if df is None:
|
174
|
-
df=df_tmp
|
175
|
-
else:
|
176
|
-
df=pd.concat([df,df_tmp])
|
177
|
-
|
178
|
-
# 未找到
|
179
|
-
if df is None:
|
180
|
-
print(" Sorry, data source rejected connection, try again later")
|
181
|
-
return
|
182
|
-
if len(df) == 0:
|
183
|
-
print(f" Pity, nothing found for {key_words}")
|
184
|
-
return
|
185
|
-
|
186
|
-
# 去重
|
187
|
-
df.drop_duplicates(subset=['id'],keep='first',inplace=True)
|
188
|
-
|
189
|
-
# 去掉名称中的逗号、左右括号、美元符号和百分号,以免降低模糊匹配度
|
190
|
-
#df['name2']=df['name'].apply(lambda x: re.sub('[(),$%]', '', x))
|
191
|
-
if not search_id_only:
|
192
|
-
df['name2']=df['name'].apply(lambda x: re.sub('[(),]', '', x))
|
193
|
-
#df['name2']=df.apply(lambda x: re.sub('[(),]', '', x['name']) + ' ' + x['id'],axis=1)
|
194
|
-
|
195
|
-
# 匹配相似度
|
196
|
-
df2=fuzzy_search_wb(df,key_words=key_words,column='name2',top=top)
|
197
|
-
else:
|
198
|
-
df['id_tag']=df['id'].apply(lambda x: 1 if key_words.lower() in x.lower() else 0)
|
199
|
-
df2=df[df['id_tag']==1].head(top)
|
200
|
-
|
201
|
-
#note=True
|
202
|
-
|
203
|
-
df2.reset_index(drop=True,inplace=True)
|
204
|
-
df2['seq']=df2.index + 1
|
205
|
-
|
206
|
-
# 遍历输出
|
207
|
-
if len(df2)==0:
|
208
|
-
print(f"Sorry, no indicator found with key words: {key_words}")
|
209
|
-
return None
|
210
|
-
|
211
|
-
#print('') #空一行
|
212
|
-
for row in df2.itertuples():
|
213
|
-
|
214
|
-
print(f"{row.seq} {row.id}",end=': ')
|
215
|
-
if not translate:
|
216
|
-
print(f"{row.name}",end='')
|
217
|
-
else:
|
218
|
-
print(f"{row.name}[{lang_auto2(row.name)}]",end='')
|
219
|
-
if row.unit != '':
|
220
|
-
print(f", unit: {row.unit}")
|
221
|
-
else:
|
222
|
-
print('')
|
223
|
-
if note:
|
224
|
-
if row.sourceNote != '':
|
225
|
-
print(f"{row.sourceNote}")
|
226
|
-
if translate:
|
227
|
-
print(f"{lang_auto2(row.sourceNote)}")
|
228
|
-
print('') #空一行
|
229
|
-
|
230
|
-
if return_id_list:
|
231
|
-
return list(df2['id'])
|
232
|
-
else:
|
233
|
-
return
|
234
|
-
|
235
|
-
#==============================================================================
|
236
|
-
if __name__=='__main__':
|
237
|
-
key_words='GDP per capita'
|
238
|
-
column='name'
|
239
|
-
top=10
|
240
|
-
|
241
|
-
def fuzzy_search_wb(df,key_words='GDP per capita',column='name',top=10):
|
242
|
-
"""
|
243
|
-
===========================================================================
|
244
|
-
功能:给定key_words,模糊搜索df的column字段,列出匹配度最高的10个指标及其解释
|
245
|
-
参数:
|
246
|
-
df:wb.search产生的指标集
|
247
|
-
column:需要搜索的字段名,默认'id'
|
248
|
-
key_words:需要匹配的关键词组,默认'GDP'
|
249
|
-
top:列出模糊匹配度最高的若干个指标,默认10
|
250
|
-
|
251
|
-
输出:无
|
252
|
-
返回:指标列表
|
253
|
-
"""
|
254
|
-
|
255
|
-
# 将关键词组和列中的每个值都转换为小写单词集合
|
256
|
-
def normalize_text(text):
|
257
|
-
return set(text.lower().split())
|
258
|
-
|
259
|
-
# 应用函数并比较集合
|
260
|
-
df["normalized_"+column] = df[column].apply(normalize_text)
|
261
|
-
key_words_set = normalize_text(key_words)
|
262
|
-
|
263
|
-
# 计算相似度(基于集合的交集和并集)
|
264
|
-
def calculate_similarity(text_set, key_words_set):
|
265
|
-
intersection = text_set.intersection(key_words_set)
|
266
|
-
union = text_set.union(key_words_set)
|
267
|
-
return len(intersection) / len(union)
|
268
|
-
|
269
|
-
df["similarity"] = df["normalized_"+column].apply(lambda x: calculate_similarity(x, key_words_set))
|
270
|
-
|
271
|
-
# 按相似度降序
|
272
|
-
df.sort_values(['similarity'], ascending = False, inplace=True)
|
273
|
-
|
274
|
-
df2=df[['id','name','unit','sourceNote']].head(top)
|
275
|
-
|
276
|
-
return df2
|
277
|
-
|
278
|
-
#==============================================================================
|
279
|
-
if __name__ =="__main__":
|
280
|
-
indicator="NY.GDP.MKTP.KN"
|
281
|
-
indicator="6.0.GDP_current"
|
282
|
-
indicator="XYZ123"
|
283
|
-
|
284
|
-
indicator_name_wb(indicator)
|
285
|
-
|
286
|
-
def indicator_name_wb(indicator):
|
287
|
-
"""
|
288
|
-
===========================================================================
|
289
|
-
功能:抓取World Bank网页上指标的名称
|
290
|
-
indicator:WB指标名称,例如'NY.GDP.MKTP.KN'
|
291
|
-
"""
|
292
|
-
# 优先查询本地词典
|
293
|
-
indicator_name=economic_translate(indicator)
|
294
|
-
|
295
|
-
# 查询WB网页
|
296
|
-
if indicator_name == indicator:
|
297
|
-
# 构造 API 请求 URL
|
298
|
-
url = f"https://api.worldbank.org/v2/indicator/{indicator}?format=json"
|
299
|
-
|
300
|
-
# 发送请求
|
301
|
-
response = requests.get(url)
|
302
|
-
data = response.json()
|
303
|
-
|
304
|
-
# 提取指标名称
|
305
|
-
try:
|
306
|
-
indicator_name = data[1][0]['name']
|
307
|
-
except:
|
308
|
-
indicator_name = indicator
|
309
|
-
|
310
|
-
return indicator_name
|
311
|
-
|
312
|
-
|
313
|
-
#==============================================================================
|
314
|
-
if __name__ =="__main__":
|
315
|
-
ticker='CN'; show_name=True
|
316
|
-
check_country_code('ZWE',show_name=True)
|
317
|
-
check_country_code('ZAF',show_name=True)
|
318
|
-
check_country_code('cn',show_name=True)
|
319
|
-
|
320
|
-
def check_country_code(ticker='CN',show_name=False):
|
321
|
-
"""
|
322
|
-
===========================================================================
|
323
|
-
功能:检查国家代码是否支持
|
324
|
-
ticker:国家代码
|
325
|
-
show_name:是否显示国家名称,默认否False
|
326
|
-
|
327
|
-
返回值:若国家代码在列表中,True;否则,False
|
328
|
-
"""
|
329
|
-
country_codes=wb.country_codes
|
330
|
-
|
331
|
-
elements_to_remove = ['all','ALL','All']
|
332
|
-
country_code_list = [x for x in country_codes if x not in elements_to_remove]
|
333
|
-
|
334
|
-
result=False
|
335
|
-
if ticker in country_code_list:
|
336
|
-
result=True
|
337
|
-
|
338
|
-
if show_name:
|
339
|
-
if result:
|
340
|
-
indicator='NY.GDP.MKTP.KN'
|
341
|
-
df=economy_indicator_wb(ticker=ticker,indicator=indicator, \
|
342
|
-
start='2000',graph=False)
|
343
|
-
if not (df is None):
|
344
|
-
if len(df) >= 1:
|
345
|
-
country_name=df['country'].values[0]
|
346
|
-
print(f"Country code {ticker} refers to {country_name}")
|
347
|
-
else:
|
348
|
-
print(f"Country code {ticker} found, but its name not found")
|
349
|
-
else:
|
350
|
-
print(f"Found country code {ticker}, but its name not found")
|
351
|
-
else:
|
352
|
-
print(f"Country code {ticker} not found")
|
353
|
-
|
354
|
-
return result
|
355
|
-
|
356
|
-
|
357
|
-
#==============================================================================
|
358
|
-
if __name__ =="__main__":
|
359
|
-
ticker='CN'
|
360
|
-
indicator="NY.GDP.MKTP.KN"
|
361
|
-
indicator="GC.XPN.TOTL.GD.ZS"
|
362
|
-
indicator='NE.TRD.GNFS.ZS'
|
363
|
-
|
364
|
-
indicator='GC.GDP.COMP.ZS' # 自制指标
|
365
|
-
|
366
|
-
start='2015'; end='2025'; power=3
|
367
|
-
|
368
|
-
zeroline=False
|
369
|
-
attention_value=''; attention_value_area=''
|
370
|
-
attention_point=''; attention_point_area=''
|
371
|
-
average_value=False
|
372
|
-
datatag=False; graph=True
|
373
|
-
mark_top=True; mark_bottom=True; mark_end=True
|
374
|
-
facecolor='whitesmoke';loc='best'
|
375
|
-
|
376
|
-
|
377
|
-
df=economy_indicator_wb(ticker,indicator,start,end,power=3)
|
378
|
-
|
379
|
-
def economy_indicator_wb(ticker='CN',indicator='NY.GDP.MKTP.KN', \
|
380
|
-
start='L10Y',end='today',translate=False, \
|
381
|
-
zeroline=False, \
|
382
|
-
attention_value='',attention_value_area='', \
|
383
|
-
attention_point='',attention_point_area='', \
|
384
|
-
average_value=False, \
|
385
|
-
datatag=False,power=0,graph=True, \
|
386
|
-
mark_start=False,mark_top=False,mark_bottom=False,mark_end=True, \
|
387
|
-
facecolor='whitesmoke',loc='best',maxticks=30):
|
388
|
-
"""
|
389
|
-
===========================================================================
|
390
|
-
功能:绘制一个国家的一个宏观经济指标走势
|
391
|
-
参数:
|
392
|
-
ticker:国家编码,两位,默认'CN'
|
393
|
-
indicator:宏观经济指标,默认GDP (constant LCU),即本币不变价格GDP
|
394
|
-
start:开始日期,默认近十年
|
395
|
-
end:结束日期,默认当前日期
|
396
|
-
zeroline:是否绘制零线,默认False
|
397
|
-
attention_value:纵轴关注值或其列表,默认无''
|
398
|
-
attention_value_area:纵轴关注值区间强调,默认无''
|
399
|
-
attention_point:横轴关注值或其列表,默认无''
|
400
|
-
attention_point_area:横轴关注值区间强调,默认无''
|
401
|
-
average_value:是否绘制均值线,默认否False
|
402
|
-
datatag:是否标记折线中的各个数据点的数值,默认否False
|
403
|
-
power:是否绘制趋势线,默认否0
|
404
|
-
graph:是否绘图,默认是True
|
405
|
-
mark_top, mark_bottom, mark_end:是否标记最高、最低和末端点:默认是True
|
406
|
-
facecolor:背景颜色,默认'whitesmoke'
|
407
|
-
loc:图例位置,默认自动'best'
|
408
|
-
|
409
|
-
输出:图形
|
410
|
-
返回值:数据表
|
411
|
-
"""
|
412
|
-
import pandas as pd
|
413
|
-
|
414
|
-
# 自制指标
|
415
|
-
sm_ind_list=['GC.GDP.COMP.ZS']
|
416
|
-
if indicator in sm_ind_list:
|
417
|
-
sm_ind_flag=True
|
418
|
-
else:
|
419
|
-
sm_ind_flag=False
|
420
|
-
|
421
|
-
# 检测指标是否存在,并取得指标名称
|
422
|
-
indicator_name=indicator_name_wb(indicator)
|
423
|
-
if indicator_name == indicator:
|
424
|
-
print(f" #Error(economy_indicator_wb): indicator {indicator} not found")
|
425
|
-
return None
|
426
|
-
|
427
|
-
# 日期具体化
|
428
|
-
start,end=start_end_preprocess(start,end)
|
429
|
-
|
430
|
-
# 下载数据
|
431
|
-
if not sm_ind_flag:
|
432
|
-
try:
|
433
|
-
pricedf=wb.download(indicator=indicator,country=ticker,start=start,end=end)
|
434
|
-
except:
|
435
|
-
print(f" #Error(economy_indicator_wb): {indicator} not available for {ticker}")
|
436
|
-
return None
|
437
|
-
elif indicator == 'GC.GDP.COMP.ZS': # 针对自制指标
|
438
|
-
indtmp1='NY.GDP.FCST.CN' # Compensation of employees (current LCU),CN无数据!
|
439
|
-
indtmp2='NY.GDP.MKTP.CN' # GDP (current LCU)
|
440
|
-
try:
|
441
|
-
pricetmp1=wb.download(indicator=indtmp1,country=ticker,start=start,end=end)
|
442
|
-
except:
|
443
|
-
print(f" #Error(economy_indicator_wb): element {indtmp1} not available for {ticker}")
|
444
|
-
return None
|
445
|
-
try:
|
446
|
-
pricetmp2=wb.download(indicator=indtmp2,country=ticker,start=start,end=end)
|
447
|
-
except:
|
448
|
-
print(f" #Error(economy_indicator_wb): element {indtmp2} not available for {ticker}")
|
449
|
-
return None
|
450
|
-
|
451
|
-
# 算法=indtmp1 / indtmp2 * 100
|
452
|
-
pricetmp=pd.merge(pricetmp1,pricetmp2,how='inner',left_on=['country','year'],
|
453
|
-
right_on=['country','year'])
|
454
|
-
pricetmp[indicator]=pricetmp.apply(lambda x: round(x[indtmp1]/x[indtmp2]*100,2),axis=1)
|
455
|
-
pricedf=pricetmp
|
456
|
-
|
457
|
-
# 分离出country和year字段
|
458
|
-
pricedf['country']=pricedf.index[0][0]
|
459
|
-
pricedf['year']=pricedf.index
|
460
|
-
pricedf['year']=pricedf['year'].apply(lambda x: x[1])
|
461
|
-
|
462
|
-
pricedf=pricedf[['country','year',indicator]]
|
463
|
-
pricedf.reset_index(drop=True,inplace=True)
|
464
|
-
|
465
|
-
# 是否返回None
|
466
|
-
if pricedf is None:
|
467
|
-
print(f" #Error(economy_indicator_wb): no data found on {indicator} in {ticker}")
|
468
|
-
return None
|
469
|
-
# 是否返回空的数据表
|
470
|
-
if len(pricedf) == 0:
|
471
|
-
print(f" #Error(economy_indicator_wb): zero data found on {indicator} in {ticker}")
|
472
|
-
return None
|
473
|
-
# 是否返回数据表但内容均为NaN
|
474
|
-
if pricedf[indicator].isnull().all():
|
475
|
-
print(f" #Error(economy_indicator_wb): all empty data found on {indicator} in {ticker}")
|
476
|
-
return None
|
477
|
-
# 判断非空值的个数
|
478
|
-
if pricedf[indicator].count() == 1:
|
479
|
-
print(f" #Warning(economy_indicator_wb): only 1 non-empty data found on {indicator} in {ticker}")
|
480
|
-
#return None
|
481
|
-
|
482
|
-
pricedf.reset_index(drop=True,inplace=True)
|
483
|
-
pricedf.set_index('year',inplace=True)
|
484
|
-
pricedf.rename(columns={indicator:indicator_name},inplace=True)
|
485
|
-
country=pricedf['country'].values[0]
|
486
|
-
pricedf.sort_index(inplace=True)
|
487
|
-
#pricedf.drop(columns='country',inplace=True)
|
488
|
-
|
489
|
-
# 若不绘图则直接返回数据,不进行数量单位变换,否则后期对比可能产生数量级不一致问题
|
490
|
-
if not graph:
|
491
|
-
return pricedf
|
492
|
-
|
493
|
-
erdf3=pricedf
|
494
|
-
|
495
|
-
# 换算数量单位
|
496
|
-
ind_max=erdf3[indicator_name].max()
|
497
|
-
ind_min=erdf3[indicator_name].min()
|
498
|
-
ind_median=erdf3[indicator_name].median()
|
499
|
-
|
500
|
-
kilo=1000; million=kilo * 1000; billion=million * 1000
|
501
|
-
trillion=billion * 1000; quadrillion=trillion * 1000
|
502
|
-
|
503
|
-
if ind_median > quadrillion:
|
504
|
-
unit=text_lang('单位:千万亿','in Quadrillions'); unit_amount=quadrillion
|
505
|
-
elif ind_median > trillion:
|
506
|
-
unit=text_lang('单位:万亿','in Trillions'); unit_amount=trillion
|
507
|
-
elif ind_median > billion:
|
508
|
-
unit=text_lang('单位:十亿','in Billions'); unit_amount=billion
|
509
|
-
elif ind_median > million:
|
510
|
-
unit=text_lang('单位:百万','in Millions'); unit_amount=million
|
511
|
-
elif ind_median > kilo:
|
512
|
-
unit=text_lang('单位:千','in Thousands'); unit_amount=kilo
|
513
|
-
else:
|
514
|
-
unit=''; unit_amount=1
|
515
|
-
|
516
|
-
erdf3['unit']=unit; erdf3['unit_amount']=unit_amount
|
517
|
-
|
518
|
-
if unit != '':
|
519
|
-
erdf3[indicator_name]=erdf3[indicator_name].apply(lambda x: round(x/unit_amount,2))
|
520
|
-
|
521
|
-
# 绘图
|
522
|
-
# 判断是否绘制零线
|
523
|
-
if ind_max * ind_min <0:
|
524
|
-
zeroline=True
|
525
|
-
|
526
|
-
titletxt1=text_lang("经济分析","Economic Analysis")
|
527
|
-
titletxt=titletxt1+': '+country_translate(country)+', '+indicator_name
|
528
|
-
if unit != '':
|
529
|
-
titletxt=titletxt+', '+unit
|
530
|
-
|
531
|
-
import datetime; todaydt = datetime.date.today()
|
532
|
-
sourcetxt=text_lang("数据来源:WB/IMF/FRED","Data source: World Bank")
|
533
|
-
footnote=sourcetxt+', '+str(todaydt)
|
534
|
-
collabel=indicator_name
|
535
|
-
|
536
|
-
ylabeltxt=indicator_name
|
537
|
-
|
538
|
-
# 为避免绘图出错,对空值进行插值
|
539
|
-
erdf3.interpolate(method='linear',limit_direction='both',inplace=True)
|
540
|
-
|
541
|
-
# 翻译:挪到绘图函数中
|
542
|
-
"""
|
543
|
-
if translate:
|
544
|
-
ylabeltxt=lang_auto2(ylabeltxt)
|
545
|
-
titletxt=lang_auto2(titletxt)
|
546
|
-
"""
|
547
|
-
try:
|
548
|
-
plot_line(erdf3,indicator_name,collabel,ylabeltxt,titletxt,footnote,datatag=datatag, \
|
549
|
-
power=power,zeroline=zeroline, \
|
550
|
-
average_value=average_value, \
|
551
|
-
attention_value=attention_value,attention_value_area=attention_value_area, \
|
552
|
-
attention_point=attention_point,attention_point_area=attention_point_area, \
|
553
|
-
mark_top=mark_top,mark_bottom=mark_bottom, \
|
554
|
-
mark_start=mark_start,mark_end=mark_end, \
|
555
|
-
facecolor=facecolor,loc=loc,maxticks=30,translate=translate)
|
556
|
-
except Exception as e:
|
557
|
-
# 捕获所有异常
|
558
|
-
print(f" #Error(economy_indicator_wb):{e}")
|
559
|
-
print(" Details:")
|
560
|
-
import traceback
|
561
|
-
traceback.print_exc()
|
562
|
-
|
563
|
-
return pricedf
|
564
|
-
|
565
|
-
|
566
|
-
#==============================================================
|
567
|
-
if __name__ =="__main__":
|
568
|
-
ticker='CN'
|
569
|
-
indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.KN','NY.GDP.MKTP.CD','XYZ']
|
570
|
-
start='2010'
|
571
|
-
end='2025'
|
572
|
-
|
573
|
-
attention_value=''; attention_value_area=''
|
574
|
-
attention_point=''; attention_point_area=''
|
575
|
-
band_area=''
|
576
|
-
graph=True
|
577
|
-
smooth=True
|
578
|
-
loc='best'
|
579
|
-
facecolor='whitesmoke'
|
580
|
-
date_range=False
|
581
|
-
date_freq=False
|
582
|
-
annotate=False
|
583
|
-
annotate_value=False
|
584
|
-
mark_top=True; mark_bottom=True; mark_end=True
|
585
|
-
maxticks=30
|
586
|
-
|
587
|
-
df=economy_mindicators_wb(ticker,measures,fromdate,todate)
|
588
|
-
|
589
|
-
def economy_mindicators_wb(ticker='CN',indicator=['NY.GDP.MKTP.CN','NY.GDP.MKTP.KN'], \
|
590
|
-
start='L10Y',end='today', \
|
591
|
-
attention_value='',attention_value_area='', \
|
592
|
-
attention_point='',attention_point_area='', \
|
593
|
-
band_area='', \
|
594
|
-
graph=True,smooth=False,loc='best',facecolor='whitesmoke', \
|
595
|
-
date_range=False,date_freq=False, \
|
596
|
-
annotate=False,annotate_value=False, \
|
597
|
-
mark_start=False,mark_top=False,mark_bottom=False,mark_end=False, \
|
598
|
-
maxticks=30,translate=False):
|
599
|
-
"""
|
600
|
-
===========================================================================
|
601
|
-
功能:单个国家,多个宏观经济指标对比
|
602
|
-
主要参数:
|
603
|
-
ticker:国家代码,默认'CN'
|
604
|
-
indicator:指标代码列表,默认['NY.GDP.MKTP.CN','NY.GDP.MKTP.KN']
|
605
|
-
start:开始日期,默认'L10Y'
|
606
|
-
end:截止日期,默认'today'
|
607
|
-
attention_value:纵轴关注值或其列表,默认无''
|
608
|
-
attention_value_area:纵轴关注值区间强调,默认无''
|
609
|
-
attention_point:横轴关注值或其列表,默认无''
|
610
|
-
attention_point_area:横轴关注值区间强调,默认无''
|
611
|
-
band_area:两条曲线之间强调,默认无''
|
612
|
-
graph:是否绘图,默认True
|
613
|
-
loc:图例位置,默认自动'best'
|
614
|
-
facecolor:画布背景颜色,默认'whitesmoke'
|
615
|
-
annotate:是否在曲线末端标注,默认否False
|
616
|
-
annotate_value:是否标注曲线末端值,默认否False
|
617
|
-
mark_start, mark_top, mark_bottom, mark_end:是否标注起始值、最大、最小、末端值,默认否
|
618
|
-
maxticks=30:限制横轴刻度最大数量
|
619
|
-
|
620
|
-
date_range=False:指定开始结束日期绘图
|
621
|
-
date_freq=False:指定横轴日期间隔,例如'D'、'2D'、'W'、'M'等,横轴一般不超过25个标注,否则会重叠
|
622
|
-
|
623
|
-
输出:图形
|
624
|
-
返回值:数据表
|
625
|
-
"""
|
626
|
-
DEBUG=False
|
627
|
-
|
628
|
-
measures=indicator
|
629
|
-
fromdate,todate=start_end_preprocess(start,end)
|
630
|
-
|
631
|
-
#处理ticker,允许1个
|
632
|
-
if isinstance(ticker,list):
|
633
|
-
if len(ticker) >= 1:
|
634
|
-
ticker=ticker[0]
|
635
|
-
else:
|
636
|
-
print(" #Error(economy_mindicators_wb): need at least 1 country to continue")
|
637
|
-
return None
|
638
|
-
|
639
|
-
#处理measures,允许多个
|
640
|
-
if isinstance(measures,str):
|
641
|
-
measures=[measures]
|
642
|
-
|
643
|
-
#屏蔽函数内print信息输出的类
|
644
|
-
import os, sys
|
645
|
-
class HiddenPrints:
|
646
|
-
def __enter__(self):
|
647
|
-
self._original_stdout = sys.stdout
|
648
|
-
sys.stdout = open(os.devnull, 'w')
|
649
|
-
|
650
|
-
def __exit__(self, exc_type, exc_val, exc_tb):
|
651
|
-
sys.stdout.close()
|
652
|
-
sys.stdout = self._original_stdout
|
653
|
-
|
654
|
-
df=pd.DataFrame(); have_data=False
|
655
|
-
indicator_list=[]
|
656
|
-
for m in measures:
|
657
|
-
print(f" Searching indicator {m} ... ...")
|
658
|
-
|
659
|
-
with HiddenPrints():
|
660
|
-
dftmp=economy_indicator_wb(ticker=ticker,indicator=m, \
|
661
|
-
start=fromdate,end=todate, \
|
662
|
-
graph=False)
|
663
|
-
if dftmp is None:
|
664
|
-
print(f" #Warning(economy_mindicators_wb): none found for {m} with {ticker}")
|
665
|
-
continue
|
666
|
-
#return None
|
667
|
-
if len(dftmp) ==0:
|
668
|
-
print(f" #Warning(economy_mindicators_wb): empty record found on {m} for {ticker}")
|
669
|
-
continue
|
670
|
-
#return None
|
671
|
-
|
672
|
-
have_data=True
|
673
|
-
|
674
|
-
country=dftmp['country'].values[0]
|
675
|
-
dftmp.drop(columns=['country'],inplace=True)
|
676
|
-
indicator_name=list(dftmp)[0]
|
677
|
-
|
678
|
-
if m in band_area:
|
679
|
-
band_area = [indicator_name if x == m else x for x in band_area]
|
680
|
-
|
681
|
-
indicator_list=indicator_list+[indicator_name]
|
682
|
-
|
683
|
-
if len(df)==0:
|
684
|
-
df=dftmp
|
685
|
-
else:
|
686
|
-
df=pd.merge(df,dftmp,left_index=True,right_index=True)
|
687
|
-
|
688
|
-
# 若不绘图则直接返回数据
|
689
|
-
pricedf=df.copy()
|
690
|
-
if not graph: return pricedf
|
691
|
-
|
692
|
-
if not have_data:
|
693
|
-
#print(f" #Error(economy_mindicators_wb): no record found on {indicator} for {ticker}")
|
694
|
-
return None
|
695
|
-
|
696
|
-
# 绘图
|
697
|
-
titletxt=text_lang("经济趋势分析","Economic Trend Analysis")+': '+country_translate(country)
|
698
|
-
|
699
|
-
y_label=text_lang('经济指标',"Economic Indicator")
|
700
|
-
import datetime; todaydt = datetime.date.today()
|
701
|
-
footnote2=text_lang("数据来源:WB/IMF/FRED","Data source: World Bank")+', '+str(todaydt)
|
702
|
-
|
703
|
-
# 处理数量级问题
|
704
|
-
max_val=min_val=0
|
705
|
-
for c in list(df):
|
706
|
-
max_tmp=df[c].max(); min_tmp=df[c].min()
|
707
|
-
if max_val < max_tmp: max_val = max_tmp
|
708
|
-
if min_val > min_tmp: min_val = min_tmp
|
709
|
-
ind_median=(max_val + min_val) / 2
|
710
|
-
|
711
|
-
kilo=1000; million=kilo * 1000; billion=million * 1000
|
712
|
-
trillion=billion * 1000; quadrillion=trillion * 1000
|
713
|
-
|
714
|
-
if ind_median > quadrillion:
|
715
|
-
unit=text_lang('单位:千万亿','in Quadrillions'); unit_amount=quadrillion
|
716
|
-
elif ind_median > trillion:
|
717
|
-
unit=text_lang('单位:万亿','in Trillions'); unit_amount=trillion
|
718
|
-
elif ind_median > billion:
|
719
|
-
unit=text_lang('单位:十亿','in Billions'); unit_amount=billion
|
720
|
-
elif ind_median > million:
|
721
|
-
unit=text_lang('单位:百万','in Millions'); unit_amount=million
|
722
|
-
elif ind_median > kilo:
|
723
|
-
unit=text_lang('单位:千','in Thousands'); unit_amount=kilo
|
724
|
-
else:
|
725
|
-
unit=''; unit_amount=1
|
726
|
-
|
727
|
-
for c in list(df):
|
728
|
-
df[c]=df[c].apply(lambda x: round(x/unit_amount,2) if x >= unit_amount else round(x/unit_amount,4))
|
729
|
-
|
730
|
-
x_label=footnote2
|
731
|
-
if unit != '':
|
732
|
-
titletxt=titletxt+', '+unit
|
733
|
-
|
734
|
-
x_label=footnote2
|
735
|
-
|
736
|
-
axhline_value=0; axhline_label=''
|
737
|
-
above_zero=0; below_zero=0
|
738
|
-
for c in list(df):
|
739
|
-
c_max=df[c].max(); c_min=df[c].min()
|
740
|
-
try:
|
741
|
-
if c_max>0 or c_min>0: above_zero+=1
|
742
|
-
if c_max<0 or c_min<0: below_zero+=1
|
743
|
-
except: continue
|
744
|
-
|
745
|
-
if above_zero>0 and below_zero>0: #有正有负
|
746
|
-
if DEBUG:
|
747
|
-
print("DEBUG: draw axhline=0")
|
748
|
-
axhline_value=0
|
749
|
-
axhline_label=text_lang('零线',"Zeroline")
|
750
|
-
|
751
|
-
# 为避免绘图出错,对空值进行插值
|
752
|
-
df.interpolate(method='linear',limit_direction='both',inplace=True)
|
753
|
-
|
754
|
-
# 翻译指标名称
|
755
|
-
for c in list(df):
|
756
|
-
df.rename(columns={c:economic_translate(c)},inplace=True)
|
757
|
-
|
758
|
-
draw_lines2(df,y_label,x_label,axhline_value,axhline_label,titletxt, \
|
759
|
-
data_label=False,resample_freq='1D',smooth=smooth, \
|
760
|
-
date_range=date_range,date_freq=date_freq,date_fmt='%Y-%m-%d', \
|
761
|
-
attention_value=attention_value,attention_value_area=attention_value_area, \
|
762
|
-
attention_point=attention_point,attention_point_area=attention_point_area, \
|
763
|
-
annotate=annotate,annotate_value=annotate_value, \
|
764
|
-
mark_start=mark_start,mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
765
|
-
facecolor=facecolor, \
|
766
|
-
band_area=band_area,loc=loc,maxticks=maxticks,translate=translate)
|
767
|
-
|
768
|
-
return pricedf
|
769
|
-
|
770
|
-
|
771
|
-
#==============================================================================
|
772
|
-
if __name__ =="__main__":
|
773
|
-
tickers=['CN','US','JP']
|
774
|
-
indicator='NY.GDP.MKTP.PP.CD'
|
775
|
-
start='L20Y'; end='today'
|
776
|
-
|
777
|
-
attention_value=''; attention_value_area=''
|
778
|
-
attention_point=''; attention_point_area=''
|
779
|
-
axhline_value=0; axhline_label=''
|
780
|
-
preprocess='none'; linewidth=1.5
|
781
|
-
scaling_option='start'
|
782
|
-
plus_sign=False
|
783
|
-
graph=True; loc='best'; facecolor='whitesmoke'
|
784
|
-
annotate=False; annotate_value=False
|
785
|
-
smooth=True
|
786
|
-
mark_top=True; mark_bottom=True; mark_end=False
|
787
|
-
maxticks=30
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
def economy_mtickers_wb(ticker=['CN','US','JP'],indicator='NY.GDP.MKTP.PP.CD', \
|
792
|
-
start='L15Y',end='today', \
|
793
|
-
attention_value='',attention_value_area='', \
|
794
|
-
attention_point='',attention_point_area='', \
|
795
|
-
axhline_value=0,axhline_label='', \
|
796
|
-
preprocess='none',linewidth=1.5, \
|
797
|
-
scaling_option='start', \
|
798
|
-
plus_sign=False, \
|
799
|
-
graph=True,facecolor='whitesmoke', \
|
800
|
-
band_area='',loc='best', \
|
801
|
-
annotate=False,annotate_value=False, \
|
802
|
-
smooth=False, \
|
803
|
-
mark_start=False,mark_top=True,mark_bottom=True,mark_end=False, \
|
804
|
-
maxticks=30,translate=False):
|
805
|
-
"""
|
806
|
-
===========================================================================
|
807
|
-
功能:比较并绘制多个国家的单宏观经济指标曲线
|
808
|
-
主要参数:
|
809
|
-
ticker:国家代码,默认['CN','US','JP']
|
810
|
-
indicator:宏观经济指标,默认'NY.GDP.MKTP.PP.CD',即GDP PPP
|
811
|
-
start:开始日期,默认'L20Y'
|
812
|
-
end:截止日期,默认'today'
|
813
|
-
attention_value:纵轴关注值或其列表,默认无''
|
814
|
-
attention_value_area:纵轴关注区间强调,默认无''
|
815
|
-
attention_point:横轴关注值或其列表,默认无''
|
816
|
-
attention_point_area:横轴关注区间强调,默认无''
|
817
|
-
preprocess:数据预处理,默认无'none'
|
818
|
-
linewidth:曲线宽度,默认1.5
|
819
|
-
scaling_option:数据缩放方法,默认'start'
|
820
|
-
plus_sign:在缩放处理时,纵轴刻度是否带加减号,默认否False
|
821
|
-
graph:是否绘图,默认是True
|
822
|
-
loc:图例位置,默认自动处理'best'
|
823
|
-
facecolor:画布背景颜色,默认'whitesmoke'
|
824
|
-
annotate:是否标注曲线末端,默认否False
|
825
|
-
annotate_value:是否标注曲线末端数值,默认否False
|
826
|
-
mark_top:是否标注最大值,默认是True
|
827
|
-
mark_bottom:是否标注最小值,默认是True
|
828
|
-
mark_end:是否标注曲线末端值,默认否False
|
829
|
-
maxticks:设定横轴刻度数量最大值,默认30
|
830
|
-
|
831
|
-
注意:
|
832
|
-
ticker中须含有2个及以上国家代码,
|
833
|
-
indicator为单一指标,
|
834
|
-
axhline_label不为空时绘制水平线
|
835
|
-
|
836
|
-
preprocess:是否对绘图数据进行预处理,仅适用于指标数量级差异较大的数据,
|
837
|
-
不适用于比例、比率和百分比等数量级较为一致的指标。
|
838
|
-
standardize: 标准化处理,(x - mean(x))/std(x)
|
839
|
-
normalize: 归一化处理,(x - min(x))/(max(x) - min(x))
|
840
|
-
logarithm: 对数处理,np.log(x)
|
841
|
-
scaling:缩放处理,五种选项scaling_option
|
842
|
-
(mean均值,min最小值,start开始值,percentage相对每条曲线起点值的百分比,
|
843
|
-
change%相对每条曲线起点值变化的百分比)
|
844
|
-
change%方式的图形更接近于持有收益率(Exp Ret%),设为默认的缩放方式。
|
845
|
-
|
846
|
-
"""
|
847
|
-
DEBUG=False
|
848
|
-
|
849
|
-
tickers=ticker; measure=indicator
|
850
|
-
start,end=start_end_preprocess(start,end)
|
851
|
-
|
852
|
-
tickers=upper_ticker(tickers)
|
853
|
-
if not isinstance(tickers,list):
|
854
|
-
tickers=[tickers]
|
855
|
-
|
856
|
-
# 去掉重复代码:有必要,重复代码将导致后续处理出错KeyError: 0!
|
857
|
-
tickers=list(set(tickers))
|
858
|
-
|
859
|
-
if isinstance(measure,list):
|
860
|
-
measure=measure[0]
|
861
|
-
|
862
|
-
#屏蔽函数内print信息输出的类
|
863
|
-
import os, sys
|
864
|
-
class HiddenPrints:
|
865
|
-
def __enter__(self):
|
866
|
-
self._original_stdout = sys.stdout
|
867
|
-
sys.stdout = open(os.devnull, 'w')
|
868
|
-
|
869
|
-
def __exit__(self, exc_type, exc_val, exc_tb):
|
870
|
-
sys.stdout.close()
|
871
|
-
sys.stdout = self._original_stdout
|
872
|
-
|
873
|
-
#循环获取指标
|
874
|
-
#import pandas as pd
|
875
|
-
#from functools import reduce
|
876
|
-
|
877
|
-
dfs=pd.DataFrame(); have_data=False
|
878
|
-
country_list=[]
|
879
|
-
for t in tickers:
|
880
|
-
print(f" Looking for {measure} info in {t} ... ...")
|
881
|
-
with HiddenPrints():
|
882
|
-
df_tmp=economy_indicator_wb(ticker=t,indicator=measure, \
|
883
|
-
start=start,end=end,graph=False)
|
884
|
-
if df_tmp is None:
|
885
|
-
print(f" #Warning(economy_mticker_wb): {measure} info not found in {t}")
|
886
|
-
continue
|
887
|
-
if len(df_tmp)==0:
|
888
|
-
print(f" #Warning(economy_mticker_wb): zero info found for {measure} in {t}")
|
889
|
-
continue
|
890
|
-
|
891
|
-
have_data=True
|
892
|
-
|
893
|
-
country=df_tmp['country'].values[0]
|
894
|
-
country_list=country_list+[country]
|
895
|
-
df_tmp.drop(columns=['country'],inplace=True)
|
896
|
-
indicator_name=list(df_tmp)[0]
|
897
|
-
|
898
|
-
if DEBUG:
|
899
|
-
print(f"DEBUG: t={t}, band_area={band_area}, df_tmp={list(df_tmp)}")
|
900
|
-
|
901
|
-
if t in band_area:
|
902
|
-
band_area = [country if x == t else x for x in band_area]
|
903
|
-
|
904
|
-
df_tmp.rename(columns={indicator_name:country},inplace=True)
|
905
|
-
|
906
|
-
if len(dfs)==0:
|
907
|
-
dfs=df_tmp
|
908
|
-
else:
|
909
|
-
dfs=pd.concat([dfs,df_tmp],axis=1,join='outer')
|
910
|
-
|
911
|
-
# 翻译band_area
|
912
|
-
band_area=[country_translate(x) for x in band_area]
|
913
|
-
|
914
|
-
if dfs is None:
|
915
|
-
print(f" #Error(economy_mticker_wb): no records found for {measure}")
|
916
|
-
return None
|
917
|
-
if len(dfs)==0:
|
918
|
-
print(f" #Error(economy_mticker_wb): zero records found for {measure}")
|
919
|
-
return None
|
920
|
-
|
921
|
-
# 若不绘图则返回原始数据
|
922
|
-
pricedf=dfs.copy()
|
923
|
-
if not graph: return pricedf
|
924
|
-
|
925
|
-
if not have_data:
|
926
|
-
#print(f" #Error(economy_mticker_wb): no record found on {indicator} for {ticker}")
|
927
|
-
return None
|
928
|
-
|
929
|
-
# 绘图
|
930
|
-
titletxt=text_lang("经济分析","Economic Analysis")+': '+indicator_name
|
931
|
-
#y_label=indicator_name
|
932
|
-
y_label=text_lang("经济指标","Economic Indicator")
|
933
|
-
|
934
|
-
import datetime; todaydt = datetime.date.today()
|
935
|
-
footnote2=text_lang("数据来源:WB/IMF/FRED","Data source: WB/IMF/FRED")+', '+str(todaydt)
|
936
|
-
|
937
|
-
# 处理数量级问题
|
938
|
-
max_val=min_val=0
|
939
|
-
for c in list(dfs):
|
940
|
-
max_tmp=dfs[c].max(); min_tmp=dfs[c].min()
|
941
|
-
if max_val < max_tmp: max_val = max_tmp
|
942
|
-
if min_val > min_tmp: min_val = min_tmp
|
943
|
-
ind_median=(max_val + min_val) / 2
|
944
|
-
|
945
|
-
kilo=1000; million=kilo * 1000; billion=million * 1000
|
946
|
-
trillion=billion * 1000; quadrillion=trillion * 1000
|
947
|
-
|
948
|
-
if ind_median > quadrillion:
|
949
|
-
unit=text_lang('单位:千万亿','in Quadrillions'); unit_amount=quadrillion
|
950
|
-
elif ind_median > trillion:
|
951
|
-
unit=text_lang('单位:万亿','in Trillions'); unit_amount=trillion
|
952
|
-
elif ind_median > billion:
|
953
|
-
unit=text_lang('单位:十亿','in Billions'); unit_amount=billion
|
954
|
-
elif ind_median > million:
|
955
|
-
unit=text_lang('单位:百万','in Millions'); unit_amount=million
|
956
|
-
elif ind_median > kilo:
|
957
|
-
unit=text_lang('单位:千','in Thousands'); unit_amount=kilo
|
958
|
-
else:
|
959
|
-
unit=''; unit_amount=1
|
960
|
-
|
961
|
-
for c in list(dfs):
|
962
|
-
dfs[c]=dfs[c].apply(lambda x: round(x/unit_amount,2) if x >= unit_amount else round(x/unit_amount,4))
|
963
|
-
|
964
|
-
x_label=footnote2
|
965
|
-
|
966
|
-
if preprocess == 'scaling' and scaling_option == 'change%':
|
967
|
-
title_txt2=text_lang("增减幅度%","Change%")
|
968
|
-
titletxt=titletxt+', '+title_txt2
|
969
|
-
axhline_value=0
|
970
|
-
axhline_label="零线"
|
971
|
-
else:
|
972
|
-
if unit != '' and preprocess == 'none':
|
973
|
-
titletxt=titletxt+', '+unit
|
974
|
-
|
975
|
-
# 为避免出错,对空值进行插值
|
976
|
-
dfs.interpolate(method='linear',limit_direction='both',inplace=True)
|
977
|
-
# 标准化处理
|
978
|
-
try:
|
979
|
-
dfs2,axhline_label,x_label,y_label,plus_sign=df_preprocess(dfs,measure, \
|
980
|
-
axhline_label=axhline_label,x_label=x_label,y_label=y_label, \
|
981
|
-
preprocess=preprocess,scaling_option=scaling_option)
|
982
|
-
except:
|
983
|
-
print(" #Error(economy_mticker_wb): preprocess failed, returning dfs for further check")
|
984
|
-
return dfs
|
985
|
-
|
986
|
-
if DEBUG:
|
987
|
-
print("DEBUG: dfs2=",list(dfs2))
|
988
|
-
|
989
|
-
above_zero=0; below_zero=0
|
990
|
-
for c in list(dfs2):
|
991
|
-
c_max=dfs2[c].max(); c_min=dfs2[c].min()
|
992
|
-
try:
|
993
|
-
if c_max>0 or c_min>0: above_zero+=1
|
994
|
-
if c_max<0 or c_min<0: below_zero+=1
|
995
|
-
except: continue
|
996
|
-
|
997
|
-
if DEBUG:
|
998
|
-
print("DEBUG: above_zero=",above_zero,'below_zero=',below_zero)
|
999
|
-
|
1000
|
-
if above_zero>0 and below_zero>0: #有正有负
|
1001
|
-
if axhline_label=='':
|
1002
|
-
axhline_label='零线'
|
1003
|
-
|
1004
|
-
# 翻译国家名称
|
1005
|
-
for c in list(dfs2):
|
1006
|
-
dfs2.rename(columns={c:country_translate(c)},inplace=True)
|
1007
|
-
|
1008
|
-
draw_lines(dfs2,y_label,x_label,axhline_value,axhline_label,titletxt, \
|
1009
|
-
data_label=False,resample_freq='D',smooth=smooth,linewidth=linewidth, \
|
1010
|
-
band_area=band_area,loc=loc, \
|
1011
|
-
attention_value=attention_value,attention_value_area=attention_value_area, \
|
1012
|
-
attention_point=attention_point,attention_point_area=attention_point_area, \
|
1013
|
-
annotate=annotate,annotate_value=annotate_value,plus_sign=plus_sign, \
|
1014
|
-
mark_start=mark_start,mark_top=mark_top,mark_bottom=mark_bottom,mark_end=mark_end, \
|
1015
|
-
facecolor=facecolor, \
|
1016
|
-
maxticks_enable=False,maxticks=10, \
|
1017
|
-
translate=translate)
|
1018
|
-
|
1019
|
-
return pricedf
|
1020
|
-
|
1021
|
-
#==============================================================================
|
1022
|
-
|
1023
|
-
|
1024
|
-
def economy_trend2(ticker='CN',indicator='NY.GDP.MKTP.KN', \
|
1025
|
-
start='L10Y',end='today',translate=False, \
|
1026
|
-
attention_value='',attention_value_area='', \
|
1027
|
-
attention_point='',attention_point_area='', \
|
1028
|
-
mark_start=False,mark_top=False,mark_bottom=False,mark_end=False, \
|
1029
|
-
graph=True,facecolor='whitesmoke',loc='best',maxticks=30, \
|
1030
|
-
|
1031
|
-
zeroline=False,average_value=False, \
|
1032
|
-
datatag=False,power=0, \
|
1033
|
-
|
1034
|
-
annotate=False,annotate_value=False,smooth=False, \
|
1035
|
-
|
1036
|
-
band_area='',date_range=False,date_freq=False, \
|
1037
|
-
|
1038
|
-
axhline_value=0,axhline_label='', \
|
1039
|
-
preprocess='none',linewidth=1.5, \
|
1040
|
-
scaling_option='start', \
|
1041
|
-
plus_sign=False, \
|
1042
|
-
):
|
1043
|
-
"""
|
1044
|
-
功能:分析宏观经济指标,支持单国家单指标、多国家单指标、单国家多指标
|
1045
|
-
主要公共参数:
|
1046
|
-
ticker:国家编码,两位或三位ISO编码,默认'CN'
|
1047
|
-
indicator:宏观经济指标,默认GDP (constant LCU),即本币不变价格GDP
|
1048
|
-
start:开始日期,默认近十年
|
1049
|
-
end:结束日期,默认当前日期
|
1050
|
-
attention_value:纵轴关注值或其列表,默认无''
|
1051
|
-
attention_value_area:纵轴关注值区间强调,默认无''
|
1052
|
-
attention_point:横轴关注值或其列表,默认无''
|
1053
|
-
attention_point_area:横轴关注值区间强调,默认无''
|
1054
|
-
graph:是否绘图,默认是True
|
1055
|
-
mark_start, mark_top, mark_bottom, mark_end:是否标记开始点、最高、最低和末端点:默认否False
|
1056
|
-
facecolor:背景颜色,默认'whitesmoke'
|
1057
|
-
loc:图例位置,默认自动'best'
|
1058
|
-
|
1059
|
-
仅支持单国家单指标的参数:
|
1060
|
-
zeroline:是否绘制零线,默认False
|
1061
|
-
average_value:是否绘制均值线,默认否False
|
1062
|
-
datatag:是否标记折线中的各个数据点的数值,默认否False
|
1063
|
-
power:是否绘制趋势线,默认否0
|
1064
|
-
|
1065
|
-
支持多国家单指标、单国家多指标的参数:
|
1066
|
-
annotate:是否在曲线末端标注,默认否False
|
1067
|
-
annotate_value:是否标注曲线末端值,默认否False
|
1068
|
-
|
1069
|
-
仅支持单国家多指标的参数:
|
1070
|
-
band_area:两条曲线之间强调,默认无''
|
1071
|
-
date_range:指定开始结束日期绘图,默认False
|
1072
|
-
date_freq:指定横轴日期间隔,默认False。
|
1073
|
-
可指定'D'、'2D'、'W'、'M'等,横轴一般不超过25个标注,否则会重叠
|
1074
|
-
|
1075
|
-
仅支持多国家单指标的参数:
|
1076
|
-
preprocess:数据预处理,默认无'none'
|
1077
|
-
scaling_option:数据缩放方法,默认'start',仅当preprocess为非'none'时有效
|
1078
|
-
plus_sign:在缩放处理时,纵轴刻度是否带加减号,默认否False
|
1079
|
-
linewidth:曲线宽度,默认1.5
|
1080
|
-
|
1081
|
-
输出:绘图
|
1082
|
-
返回值:数据表
|
1083
|
-
|
1084
|
-
其他:套壳函数
|
1085
|
-
"""
|
1086
|
-
# 判断ticker个数
|
1087
|
-
ticker_num=0
|
1088
|
-
if isinstance(ticker,str):
|
1089
|
-
ticker_num=1
|
1090
|
-
ticker=ticker.upper()
|
1091
|
-
if not check_country_code(ticker=ticker,show_name=False):
|
1092
|
-
print(f" #Warning(economy_trend2): country code {ticker} not found")
|
1093
|
-
return None
|
1094
|
-
|
1095
|
-
if isinstance(ticker,list):
|
1096
|
-
ticker=[x.upper() for x in ticker]
|
1097
|
-
for t in ticker:
|
1098
|
-
if not check_country_code(ticker=t,show_name=False):
|
1099
|
-
ticker.remove(t)
|
1100
|
-
print(f" #Warning(economy_trend2): country code {t} not found")
|
1101
|
-
if len(ticker)==0:
|
1102
|
-
return None
|
1103
|
-
|
1104
|
-
if len(ticker)==1:
|
1105
|
-
ticker_num=1
|
1106
|
-
ticker=ticker[0]
|
1107
|
-
else:
|
1108
|
-
ticker_num=len(ticker)
|
1109
|
-
|
1110
|
-
# 判断indicator个数
|
1111
|
-
indicator_num=0
|
1112
|
-
if isinstance(indicator,str): indicator_num=1
|
1113
|
-
if isinstance(indicator,list):
|
1114
|
-
if len(indicator)==1:
|
1115
|
-
indicator_num=1
|
1116
|
-
indicator=indicator[0]
|
1117
|
-
else:
|
1118
|
-
indicator_num=len(indicator)
|
1119
|
-
|
1120
|
-
# 单国家+单指标
|
1121
|
-
if ticker_num==1 and indicator_num==1:
|
1122
|
-
df=economy_indicator_wb(ticker=ticker,indicator=indicator, \
|
1123
|
-
start=start,end=end,translate=translate, \
|
1124
|
-
attention_value=attention_value, \
|
1125
|
-
attention_value_area=attention_value_area, \
|
1126
|
-
attention_point=attention_point, \
|
1127
|
-
attention_point_area=attention_point_area, \
|
1128
|
-
mark_top=mark_top,mark_bottom=mark_bottom, \
|
1129
|
-
mark_start=mark_start,mark_end=mark_end, \
|
1130
|
-
graph=graph,facecolor=facecolor,loc=loc,maxticks=maxticks, \
|
1131
|
-
|
1132
|
-
power=power,average_value=average_value, \
|
1133
|
-
zeroline=zeroline,datatag=datatag)
|
1134
|
-
return df
|
1135
|
-
|
1136
|
-
# 多国家:仅使用第一个指标
|
1137
|
-
if ticker_num > 1:
|
1138
|
-
df=economy_mtickers_wb(ticker=ticker,indicator=indicator, \
|
1139
|
-
start=start,end=end,translate=translate, \
|
1140
|
-
attention_value=attention_value, \
|
1141
|
-
attention_value_area=attention_value_area, \
|
1142
|
-
attention_point=attention_point, \
|
1143
|
-
attention_point_area=attention_point_area, \
|
1144
|
-
mark_top=mark_top,mark_bottom=mark_bottom, \
|
1145
|
-
mark_start=mark_start,mark_end=mark_end, \
|
1146
|
-
graph=graph,loc=loc,facecolor=facecolor,maxticks=maxticks, \
|
1147
|
-
band_area=band_area, \
|
1148
|
-
annotate=annotate,annotate_value=annotate_value,smooth=smooth, \
|
1149
|
-
|
1150
|
-
preprocess=preprocess,scaling_option=scaling_option, \
|
1151
|
-
plus_sign=plus_sign,linewidth=linewidth, \
|
1152
|
-
axhline_value=axhline_value,axhline_label=axhline_label)
|
1153
|
-
return df
|
1154
|
-
|
1155
|
-
# 单国家:使用多个指标
|
1156
|
-
if ticker_num == 1 and indicator_num > 1:
|
1157
|
-
df=economy_mindicators_wb(ticker=ticker,indicator=indicator, \
|
1158
|
-
start=start,end=end,translate=translate, \
|
1159
|
-
attention_value=attention_value, \
|
1160
|
-
attention_value_area=attention_value_area, \
|
1161
|
-
attention_point=attention_point, \
|
1162
|
-
attention_point_area=attention_point_area, \
|
1163
|
-
mark_top=mark_top,mark_bottom=mark_bottom, \
|
1164
|
-
mark_start=mark_start,mark_end=mark_end, \
|
1165
|
-
graph=graph,facecolor=facecolor,loc=loc,maxticks=maxticks, \
|
1166
|
-
|
1167
|
-
annotate=annotate,annotate_value=annotate_value,smooth=smooth, \
|
1168
|
-
|
1169
|
-
band_area=band_area, \
|
1170
|
-
date_range=date_range,date_freq=date_freq)
|
1171
|
-
return df
|
1172
|
-
|
1173
|
-
print(" #Warning: need at least 1 country and at leats 1 indicator")
|
1174
|
-
|
1175
|
-
return None
|
1176
|
-
|
1177
|
-
|
1178
|
-
#==============================================================================
|
1179
|
-
#==============================================================================
|
1180
|
-
#==============================================================================
|
1181
|
-
#==============================================================================
|
1182
|
-
#==============================================================================
|
1183
|
-
#==============================================================================
|
1184
|
-
|
1185
|
-
|
1186
|
-
def economic_translate(indicator):
|
1187
|
-
"""
|
1188
|
-
===========================================================================
|
1189
|
-
功能:翻译宏观经济指标术语
|
1190
|
-
参数:
|
1191
|
-
indicator: 指标编码,主要是世界银行编码。
|
1192
|
-
注意:部分编码已放弃,可能无数据或无最新数据。
|
1193
|
-
返回值:是否找到,基于语言环境为中文或英文解释。
|
1194
|
-
语言环境判断为check_language()
|
1195
|
-
|
1196
|
-
数据结构:['指标编码','中文解释','英文解释']
|
1197
|
-
"""
|
1198
|
-
DEBUG=False
|
1199
|
-
|
1200
|
-
import pandas as pd
|
1201
|
-
trans_dict=pd.DataFrame([
|
1202
|
-
|
1203
|
-
# NE.CON.PRVT:最终消费支出-家庭及NPISH===================================
|
1204
|
-
['NE.CON.PRVT.CD','家庭及NPISH最终消费(美元现价)',
|
1205
|
-
'Household & NPISHs Final Consumption (current US$)',
|
1206
|
-
'Households and NPISHs Final consumption expenditure (current US$)'],
|
1207
|
-
|
1208
|
-
['NE.CON.PRVT.CN','家庭及NPISH最终消费(本币现价)',
|
1209
|
-
'Household & NPISHs Final Consumption (current LCU)',
|
1210
|
-
'Households and NPISHs Final consumption expenditure (current LCU)'],
|
1211
|
-
|
1212
|
-
['NE.CON.PRVT.CN.AD','家庭及NPISH最终消费(统计口径调整后,本币现价)',
|
1213
|
-
'Household & NPISHs Final Consumption (linked series, current LCU)',
|
1214
|
-
'Households and NPISHs Final consumption expenditure: linked series (current LCU)'],
|
1215
|
-
|
1216
|
-
['NE.CON.PRVT.KD','家庭及NPISH最终消费(2015美元不变价格)',
|
1217
|
-
'Household & NPISHs Final Consumption (constant 2015 US$)',
|
1218
|
-
'Households and NPISHs Final consumption expenditure (constant 2015 US$)'],
|
1219
|
-
|
1220
|
-
['NE.CON.PRVT.KD.ZG','家庭及NPISH最终消费(年增速%)',
|
1221
|
-
'Household & NPISHs Final Consumption (annual % growth)',
|
1222
|
-
'Households and NPISHs Final consumption expenditure (annual % growth)'],
|
1223
|
-
|
1224
|
-
['NE.CON.PRVT.KN','家庭及NPISH最终消费(本币不变价格)',
|
1225
|
-
'Household & NPISHs Final Consumption (constant LCU)',
|
1226
|
-
'Households and NPISHs Final consumption expenditure (constant LCU)'],
|
1227
|
-
|
1228
|
-
['NE.CON.PRVT.PC.KD','人均家庭及NPISH最终消费(2015美元不变价格)',
|
1229
|
-
'Household & NPISHs Final Consumption per capita (constant 2015 US$)',
|
1230
|
-
'Households and NPISHs Final consumption expenditure per capita (constant 2015 US$)'],
|
1231
|
-
|
1232
|
-
['NE.CON.PRVT.PC.KD.ZG','人均家庭及NPISH最终消费(年增速%)',
|
1233
|
-
'Household & NPISHs Final Consumption per capita growth (annual %)',
|
1234
|
-
'Households and NPISHs Final consumption expenditure per capita growth (annual %)'],
|
1235
|
-
|
1236
|
-
['NE.CON.PRVT.PP.CD','家庭及NPISH最终消费(购买力平价,国际美元现价)',
|
1237
|
-
'Household & NPISHs Final Consumption (PPP, current intl $)',
|
1238
|
-
'Households and NPISHs Final consumption expenditure, PPP (current international $)'],
|
1239
|
-
|
1240
|
-
['NE.CON.PRVT.PP.KD','家庭及NPISH最终消费(购买力平价,2021国际美元不变价格)',
|
1241
|
-
'Household & NPISHs Final Consumption (PPP, constant 2021 intl $)',
|
1242
|
-
'Households and NPISHs Final consumption expenditure, PPP (constant 2021 international $)'],
|
1243
|
-
|
1244
|
-
['NE.CON.PRVT.ZS','家庭及NPISH最终消费支出(占GDP%)',
|
1245
|
-
'Household & NPISHs Final Consumption (GDP%)',
|
1246
|
-
'Households and NPISHs Final consumption expenditure (% of GDP)'],
|
1247
|
-
|
1248
|
-
# 币种指标:CD=current US$, KD=constant 2015 US$, CN=current LCU
|
1249
|
-
# KN=constant LCU, ZS=% of GDP, PC=per capita, PP=PPP
|
1250
|
-
|
1251
|
-
# NE.CON.GOVT:最终消费支出-政府=========================================
|
1252
|
-
['NE.CON.GOVT.CD','政府最终消费支出(美元现价)',
|
1253
|
-
'Government final consumption expenditure (current US$)',
|
1254
|
-
'General government final consumption expenditure (current US$)'],
|
1255
|
-
|
1256
|
-
['NE.CON.GOVT.CN','政府最终消费支出(本币现价)',
|
1257
|
-
'Government final consumption expenditure (current LCU)',
|
1258
|
-
'General government final consumption expenditure (current LCU)'],
|
1259
|
-
|
1260
|
-
['NE.CON.GOVT.ZS','政府最终消费支出(占GDP%)',
|
1261
|
-
'Government final consumption expenditure (% of GDP)',
|
1262
|
-
'General government final consumption expenditure (% of GDP)'],
|
1263
|
-
|
1264
|
-
# NE.CON.TOTL:最终消费支出总计==========================================
|
1265
|
-
['NE.CON.TOTL.CD','最终消费支出总计(美元现价)',
|
1266
|
-
'Final consumption expenditure (current US$)',
|
1267
|
-
'Final consumption expenditure (current US$)'],
|
1268
|
-
|
1269
|
-
['NE.CON.TOTL.CN','最终消费支出总计(本币现价)',
|
1270
|
-
'Final consumption expenditure (current LCU)',
|
1271
|
-
'Final consumption expenditure (current LCU)'],
|
1272
|
-
|
1273
|
-
['NE.CON.TOTL.KD','最终消费支出总计(2015美元不变价格)',
|
1274
|
-
'Final consumption expenditure (constant 2015 US$)',
|
1275
|
-
'Final consumption expenditure (constant 2015 US$)'],
|
1276
|
-
|
1277
|
-
['NE.CON.TOTL.KD.ZG','最终消费支出总计年增速%(2015美元不变价格)',
|
1278
|
-
'Final consumption expenditure (annual % growth)',
|
1279
|
-
'Final consumption expenditure (annual % growth)'],
|
1280
|
-
|
1281
|
-
['NE.CON.TOTL.KN','最终消费支出总计(本币不变价格)',
|
1282
|
-
'Final consumption expenditure (constant LCU)',
|
1283
|
-
'Final consumption expenditure (constant LCU)'],
|
1284
|
-
|
1285
|
-
['NE.CON.TOTL.ZS','最终消费支出总计(占GDP%)',
|
1286
|
-
'Final consumption expenditure (% of GDP)',
|
1287
|
-
'Final consumption expenditure (% of GDP)'],
|
1288
|
-
|
1289
|
-
#######################################################################
|
1290
|
-
# NE.CON.TOTL.CD:最终消费支出,包括家庭、非营利机构为家庭服务的支出(NPISHs)以及政府消费支出。
|
1291
|
-
# 它反映了经济中所有部门的消费总支出。
|
1292
|
-
# 涵盖家庭、政府以及非营利机构为家庭服务的支出,是一个全面的消费指标。
|
1293
|
-
# 用于分析一个国家或地区的整体消费水平和消费结构,了解消费在经济中的地位和作用。
|
1294
|
-
# NE.CON.TETC.CD:最终消费支出(总额),通常与 NE.CON.TOTL.CD 类似。
|
1295
|
-
#
|
1296
|
-
# NE.CON.PRVT.CD:家庭和非营利机构为家庭服务的最终消费支出,主要反映私人部门的消费情况。
|
1297
|
-
# 仅包括家庭和非营利机构为家庭服务的消费支出,不包含政府消费支出。
|
1298
|
-
# 用于研究私人消费在经济增长中的贡献,分析家庭消费行为和消费趋势。
|
1299
|
-
# NE.CON.PETC.CD:私人最终消费支出,通常与 NE.CON.PRVT.CD 类似。
|
1300
|
-
#
|
1301
|
-
# NE.CON.GOVT.CD:政府最终消费支出,反映政府在提供公共服务和进行行政管理等方面的消费支出。
|
1302
|
-
# 仅包括政府的消费支出,不包含家庭和非营利机构的支出。
|
1303
|
-
# 用于分析政府消费支出在经济中的作用,了解政府在公共服务和行政管理方面的投入。
|
1304
|
-
#
|
1305
|
-
# NE.CON.TOTL.CD = NE.CON.PRVT.CD + NE.CON.GOVT.CD
|
1306
|
-
#======================================================================
|
1307
|
-
|
1308
|
-
# NY.GDP.MKTP:国内生产总值GDP总量=======================================
|
1309
|
-
['NY.GDP.MKTP.CD','GDP(美元现价)',
|
1310
|
-
'GDP (current US$)',
|
1311
|
-
'GDP (current US$)'],
|
1312
|
-
|
1313
|
-
['NY.GDP.MKTP.CN','GDP(本币现价)',
|
1314
|
-
'GDP (current LCU)',
|
1315
|
-
'GDP (current LCU)'],
|
1316
|
-
|
1317
|
-
['NY.GDP.MKTP.CN.AD','GDP(统计口径调整后,本币现价)',
|
1318
|
-
'GDP: linked series (current LCU)',
|
1319
|
-
'GDP: linked series (current LCU)'],
|
1320
|
-
|
1321
|
-
['NY.GDP.MKTP.KD','GDP(2015美元不变价格)',
|
1322
|
-
'GDP (constant 2015 US$)',
|
1323
|
-
'GDP (constant 2015 US$)'],
|
1324
|
-
|
1325
|
-
['NY.GDP.MKTP.KD.ZG','GDP年增速%(2015美元不变价格)',
|
1326
|
-
'GDP growth (annual %, constant 2015 US$)',
|
1327
|
-
'GDP growth (annual %, constant 2015 US$)'],
|
1328
|
-
|
1329
|
-
['NY.GDP.MKTP.KN','GDP(本币不变价格)',
|
1330
|
-
'GDP (constant LCU)',
|
1331
|
-
'GDP (constant LCU)'],
|
1332
|
-
|
1333
|
-
['NY.GDP.MKTP.PP.CD','GDP(购买力平价,国际美元现价)',
|
1334
|
-
'GDP, PPP (current international $)',
|
1335
|
-
'GDP, PPP (current international $)'],
|
1336
|
-
|
1337
|
-
['NY.GDP.MKTP.PP.KD','GDP(购买力平价,2021国际美元不变价格)',
|
1338
|
-
'GDP, PPP (constant 2021 international $)',
|
1339
|
-
'GDP, PPP (constant 2021 international $)'],
|
1340
|
-
|
1341
|
-
# NY.GDP.PCAP:国内生产总值GDP人均=======================================
|
1342
|
-
['NY.GDP.PCAP.CD','人均GDP(美元现价)',
|
1343
|
-
'GDP per capita (current US$)',
|
1344
|
-
'GDP per capita (current US$)'],
|
1345
|
-
|
1346
|
-
['NY.GDP.PCAP.CN','人均GDP(本币现价)',
|
1347
|
-
'GDP per capita (current LCU)',
|
1348
|
-
'GDP per capita (current LCU)'],
|
1349
|
-
|
1350
|
-
['NY.GDP.PCAP.KD','人均GDP(2015美元不变价格)',
|
1351
|
-
'GDP per capita (constant 2015 US$)',
|
1352
|
-
'GDP per capita (constant 2015 US$)'],
|
1353
|
-
|
1354
|
-
['NY.GDP.PCAP.KD.ZG','人均GDP年增速%(2015美元不变价格)',
|
1355
|
-
'GDP per capita growth (annual %, constant 2015 US$)',
|
1356
|
-
'GDP per capita growth (annual %, constant 2015 US$)'],
|
1357
|
-
|
1358
|
-
['NY.GDP.PCAP.KN','人均GDP(本币不变价格)',
|
1359
|
-
'GDP per capita (constant LCU)',
|
1360
|
-
'GDP per capita (constant LCU)'],
|
1361
|
-
|
1362
|
-
['NY.GDP.PCAP.PP.CD','人均GDP(购买力平价,国际美元现价)',
|
1363
|
-
'GDP per capita, PPP (current international $)',
|
1364
|
-
'GDP per capita, PPP (current international $)'],
|
1365
|
-
|
1366
|
-
['NY.GDP.PCAP.PP.KD','人均GDP(购买力平价,2021国际美元不变价格)',
|
1367
|
-
'GDP per capita, PPP (constant 2021 international $)',
|
1368
|
-
'GDP per capita, PPP (constant 2021 international $)'],
|
1369
|
-
|
1370
|
-
# NY.GNP.MKTP:国民总收入GNI总量=======================================
|
1371
|
-
['NY.GNP.MKTP.CD','GNI(美元现价)',
|
1372
|
-
'GNI (current US$)',
|
1373
|
-
'GNI (current US$)'],
|
1374
|
-
|
1375
|
-
['NY.GNP.MKTP.CN','GNI(本币现价)',
|
1376
|
-
'GNI (current LCU)',
|
1377
|
-
'GNI (current LCU)'],
|
1378
|
-
|
1379
|
-
['NY.GNP.MKTP.CN.AD','GNI(统计口径调整后,本币现价)',
|
1380
|
-
'GNI: linked series (current LCU)',
|
1381
|
-
'GNI: linked series (current LCU)'],
|
1382
|
-
|
1383
|
-
['NY.GNP.MKTP.KD','GNI(2015美元不变价格)',
|
1384
|
-
'GNI (constant 2015 US$)',
|
1385
|
-
'GNI (constant 2015 US$)'],
|
1386
|
-
|
1387
|
-
['NY.GNP.MKTP.KD.ZG','GNI年增速%(2015美元不变价格)',
|
1388
|
-
'GNI growth (annual %, constant 2015 US$)',
|
1389
|
-
'GNI growth (annual %, constant 2015 US$)'],
|
1390
|
-
|
1391
|
-
['NY.GNP.MKTP.KN','GNI(本币不变价格)',
|
1392
|
-
'GNI (constant LCU)',
|
1393
|
-
'GNI (constant LCU)'],
|
1394
|
-
|
1395
|
-
['NY.GNP.MKTP.PP.CD','GNI(购买力平价,国际美元现价)',
|
1396
|
-
'GNI(PPP, current international $)',
|
1397
|
-
'GNI(PPP, current international $)'],
|
1398
|
-
|
1399
|
-
['NY.GNP.MKTP.PP.KD','GNI(购买力平价,2021国际美元不变价格)',
|
1400
|
-
'GNI(PPP, constant 2021 international $)',
|
1401
|
-
'GNI(PPP, constant 2021 international $)'],
|
1402
|
-
|
1403
|
-
# NY.GNP.PCAP:GNI人均=======================================
|
1404
|
-
['NY.GNP.PCAP.CD','人均GNI(美元现价)',
|
1405
|
-
'GNI per capita (current US$)',
|
1406
|
-
'GNI per capita (current US$)'],
|
1407
|
-
|
1408
|
-
['NY.GNP.PCAP.CN','人均GNI(本币现价)',
|
1409
|
-
'GNI per capita (current LCU)',
|
1410
|
-
'GNI per capita (current LCU)'],
|
1411
|
-
|
1412
|
-
['NY.GNP.PCAP.KD','人均GNI(2015美元不变价格)',
|
1413
|
-
'GNI per capita (constant 2015 US$)',
|
1414
|
-
'GNI per capita (constant 2015 US$)'],
|
1415
|
-
|
1416
|
-
['NY.GNP.PCAP.KD.ZG','人均GNI年增速%(2015美元不变价格)',
|
1417
|
-
'GNI per capita growth (annual %, constant 2015 US$)',
|
1418
|
-
'GNI per capita growth (annual %, constant 2015 US$)'],
|
1419
|
-
|
1420
|
-
['NY.GNP.PCAP.KN','人均GNI(本币不变价格)',
|
1421
|
-
'GNI per capita (constant LCU)',
|
1422
|
-
'GNI per capita (constant LCU)'],
|
1423
|
-
|
1424
|
-
['NY.GNP.PCAP.PP.CD','人均GNI(购买力平价,国际美元现价)',
|
1425
|
-
'GNI per capita, PPP (current international $)',
|
1426
|
-
'GNI per capita, PPP (current international $)'],
|
1427
|
-
|
1428
|
-
['NY.GNP.PCAP.PP.KD','人均GNI(购买力平价,2021国际美元不变价格)',
|
1429
|
-
'GNI per capita, PPP (constant 2021 international $)',
|
1430
|
-
'GNI per capita, PPP (constant 2021 international $)'],
|
1431
|
-
|
1432
|
-
#######################################################################
|
1433
|
-
#“International $”(国际美元)是一种标准化的货币单位,用于消除汇率差异,
|
1434
|
-
#使不同国家的经济指标(如 GDP)在购买力平价(PPP)基础上更具可比性。
|
1435
|
-
#它帮助我们更真实地了解各国居民的生活水平。
|
1436
|
-
#
|
1437
|
-
#在 GDP per capita, PPP(按购买力平价计算的人均 GDP)中,
|
1438
|
-
#使用“国际美元”可以更真实地反映一个国家居民的实际生活水平。
|
1439
|
-
#
|
1440
|
-
#例如,如果一个国家的 GDP per capita, PPP 是 20,000 国际美元,
|
1441
|
-
#这意味着该国居民的平均购买力相当于美国居民用 20,000 美元的购买力。
|
1442
|
-
#在这种情况下,1 国际美元的购买力等于在美国用 1 美元的购买力。
|
1443
|
-
#
|
1444
|
-
#再比如,如果一个同样的汉堡在美国售价为 5 美元,在印度售价为 200 卢比,
|
1445
|
-
#那么根据 PPP 理论,1 美元应该等于 40 卢比(200 卢比 / 5 美元)。
|
1446
|
-
#
|
1447
|
-
#为了计算国际美元,需要对各国商品和服务的价格进行比较,并根据其在经济中的重要性分配权重。
|
1448
|
-
#例如,食品、住房、交通等商品和服务的权重可能更高。
|
1449
|
-
#######################################################################
|
1450
|
-
|
1451
|
-
# GFDD.DM:证券市场-股票、权益与债券=====================================
|
1452
|
-
['CM.MKT.LCAP.GD.ZS','国内上市公司市值占GDP%',
|
1453
|
-
'Market cap of domestic listed companies to GDP (%)',
|
1454
|
-
'Market cap of domestic listed companies to GDP (%)'],
|
1455
|
-
|
1456
|
-
['GFDD.DM.01','股票市场总市值占GDP%',
|
1457
|
-
'Stock market capitalization to GDP (%)',
|
1458
|
-
'Stock market capitalization to GDP (%)'],
|
1459
|
-
|
1460
|
-
['GFDD.DM.02','股票市场当年交易额占GDP%',
|
1461
|
-
'Stock market total value traded to GDP (%)',
|
1462
|
-
'Stock market total value traded to GDP (%)'],
|
1463
|
-
# 经济意义:
|
1464
|
-
# 市场流动性:该指标越高,表明股票市场的流动性越强,交易越活跃。高流动性通常意味着市场参与者更容易买卖股票,市场效率较高。
|
1465
|
-
# 经济开放程度:较高的交易总值占GDP比重通常反映出一个国家或地区的经济开放程度较高,资本市场较为发达。
|
1466
|
-
# 金融体系发达程度:该指标还可以反映一个国家或地区的金融体系是否发达,以及股票市场在金融体系中的地位。
|
1467
|
-
# 市场波动性:在某些情况下,过高的交易总值占GDP比重可能反映出市场波动性较大,投资者情绪较为活跃。
|
1468
|
-
#
|
1469
|
-
# 实际应用:
|
1470
|
-
# 比较不同国家的股票市场活跃程度:通过比较不同国家的指标,可以了解各国股票市场的相对活跃程度。
|
1471
|
-
|
1472
|
-
['GFDD.DM.03','未清偿的国内非政府债务证券占GDP%',
|
1473
|
-
'Outstanding domestic private debt securities to GDP (%)',
|
1474
|
-
'Outstanding domestic private debt securities to GDP (%)'],
|
1475
|
-
# 债务证券是政府、公司和金融机构发行的债券和票据等债务工具
|
1476
|
-
# 未清偿的国内私人债务证券占GDP的百分比。
|
1477
|
-
# 该指标反映了国内私人部门(包括公司和金融机构)发行的债务证券在经济中的比重。
|
1478
|
-
# 经济意义:
|
1479
|
-
# 金融市场发达程度:该指标越高,表明一个国家或地区的金融市场越发达,私人部门通过债务证券融资的能力越强。
|
1480
|
-
# 经济风险:较高的私人债务证券占GDP比重可能反映出较高的经济风险,特别是在债务水平超过经济承受能力的情况下。
|
1481
|
-
# 债务可持续性:该指标可以帮助评估私人部门债务的可持续性,了解债务水平是否与经济增长相匹配。
|
1482
|
-
|
1483
|
-
['GFDD.DM.04','未清偿的国内政府债务证券占GDP%',
|
1484
|
-
'Outstanding domestic public debt securities to GDP (%)',
|
1485
|
-
'Outstanding domestic public debt securities to GDP (%)'],
|
1486
|
-
# 经济意义
|
1487
|
-
# 公共债务水平:该指标反映了政府的债务负担,特别是通过国内市场融资的债务水平。
|
1488
|
-
# 债务可持续性:较高的公共债务证券占GDP比重可能反映出较高的债务风险,尤其是在债务水平超过经济承受能力的情况下。
|
1489
|
-
# 财政政策的稳健性:该指标可以用来评估一个国家的财政政策是否稳健,以及政府是否有能力偿还其债务。
|
1490
|
-
# 经济风险:公共债务水平的高低可以反映一个国家的经济风险,尤其是在国际金融市场波动或经济衰退时。
|
1491
|
-
|
1492
|
-
['GFDD.DM.05','未清偿的国际非政府债务证券占GDP%',
|
1493
|
-
'Outstanding international private debt securities to GDP (%)',
|
1494
|
-
'Outstanding international private debt securities to GDP (%)'],
|
1495
|
-
# 经济意义:
|
1496
|
-
# 国际融资能力:该指标反映了私人部门在国际市场上融资的能力,较高的比重通常表明一个国家的私人部门能够更有效地利用国际资本。
|
1497
|
-
# 经济开放程度:较高的国际私人债务证券占GDP比重通常表明一个国家的经济开放程度较高,与国际资本市场的联系较为紧密。
|
1498
|
-
# 经济风险:较高的国际私人债务证券占GDP比重可能反映出较高的经济风险,尤其是在国际金融市场波动或经济衰退时。
|
1499
|
-
# 债务可持续性:该指标可以帮助评估私人部门国际债务的可持续性,了解债务水平是否与经济增长相匹配。
|
1500
|
-
# 资本流动:该指标可以反映国际资本流动的趋势,帮助分析资本流入和流出的动态。
|
1501
|
-
#
|
1502
|
-
# 实际应用:
|
1503
|
-
# 比较不同国家的国际融资能力:通过比较不同国家的“Outstanding international private debt securities to GDP (%)”,可以了解各国私人部门在国际市场上融资的相对能力。
|
1504
|
-
|
1505
|
-
['GFDD.DM.06','未清偿的国际政府债务证券占GDP%',
|
1506
|
-
'Outstanding international public debt securities to GDP (%)',
|
1507
|
-
'Outstanding international public debt securities to GDP (%)'],
|
1508
|
-
|
1509
|
-
['GFDD.DM.07','国际债务发行总额占GDP%',
|
1510
|
-
'International debt issues to GDP (%)',
|
1511
|
-
'International debt issues to GDP (%)'],
|
1512
|
-
|
1513
|
-
['GFDD.DM.08','发行权益工具吸引外资形成的经济责任总额占GDP%',
|
1514
|
-
'Gross portfolio equity liabilities to GDP (%)',
|
1515
|
-
'Gross portfolio equity liabilities to GDP (%)'],
|
1516
|
-
|
1517
|
-
['GFDD.DM.09','通过权益工具持有的国际资产总额占GDP%',
|
1518
|
-
'Gross portfolio equity assets to GDP (%)',
|
1519
|
-
'Gross portfolio equity assets to GDP (%)'],
|
1520
|
-
|
1521
|
-
['GFDD.DM.10','发行债务工具吸引外资形成的经济责任总额占GDP%',
|
1522
|
-
'Gross portfolio debt liabilities to GDP (%)',
|
1523
|
-
'Gross portfolio debt liabilities to GDP (%)'],
|
1524
|
-
|
1525
|
-
['GFDD.DM.11','通过债务工具持有的国际资产总额占GDP%',
|
1526
|
-
'Gross portfolio debt assets to GDP (%)',
|
1527
|
-
'Gross portfolio debt assets to GDP (%)'],
|
1528
|
-
# 注意:总额Gross与净额Net的区别
|
1529
|
-
['GFDD.DM.12','银团贷款发行量占GDP%',
|
1530
|
-
'Syndicated loan issuance volume to GDP (%)',
|
1531
|
-
'Syndicated loan issuance volume to GDP (%)'],
|
1532
|
-
|
1533
|
-
['GFDD.DM.13','公司债券发行量占GDP%',
|
1534
|
-
'Corporate bond issuance volume to GDP (%)',
|
1535
|
-
'Corporate bond issuance volume to GDP (%)'],
|
1536
|
-
|
1537
|
-
['GFDD.DM.14','银团贷款的平均到期年限',
|
1538
|
-
'Syndicated loan average maturity (years)',
|
1539
|
-
'Syndicated loan average maturity (years)'],
|
1540
|
-
|
1541
|
-
['GFDD.DM.15','公司债券的平均到期年限',
|
1542
|
-
'Corporate bond average maturity (years)',
|
1543
|
-
'Corporate bond average maturity (years)'],
|
1544
|
-
|
1545
|
-
['GFDD.DM.16','金融科技和大型科技公司提供的信贷流量占GDP%',
|
1546
|
-
'Credit flows by fintech and bigtech companies to GDP (%)',
|
1547
|
-
'Credit flows by fintech and bigtech companies to GDP (%)'],
|
1548
|
-
# 经济意义:
|
1549
|
-
# 金融创新:该指标反映了金融科技和大型科技公司在信贷市场中的活跃程度,较高的比重通常表明金融创新较为活跃。
|
1550
|
-
# 金融包容性:较高的信贷流量占GDP比重可能表明金融科技和大型科技公司正在帮助提高金融包容性,为更多人提供信贷服务。
|
1551
|
-
# 经济活力:该指标可以反映一个国家或地区的经济活力,特别是在金融技术和科技创新方面的活力。
|
1552
|
-
# 监管挑战:较高的信贷流量可能带来监管挑战,因为金融科技和大型科技公司可能不受传统银行监管的约束。
|
1553
|
-
# 市场竞争力:该指标可以帮助评估金融科技和大型科技公司与传统银行之间的竞争力。
|
1554
|
-
#
|
1555
|
-
# 实际应用:
|
1556
|
-
# 比较不同国家的金融创新程度:通过比较不同国家的“Credit flows by fintech and bigtech companies to GDP (%)”,可以了解各国在金融创新方面的相对程度。
|
1557
|
-
# 评估金融包容性:该指标可以用来评估一个国家的金融包容性,特别是金融科技和大型科技公司在提供信贷服务方面的作用。
|
1558
|
-
|
1559
|
-
# FM.LBL.BMNY:广义货币M2===============================================
|
1560
|
-
['FM.LBL.BMNY.CN','广义货币(本币现价)',
|
1561
|
-
'Broad money (current LCU)',
|
1562
|
-
'Broad money (current LCU)'],
|
1563
|
-
|
1564
|
-
['FM.LBL.BMNY.ZG','广义货币年增速%',
|
1565
|
-
'Broad money growth (annual %)',
|
1566
|
-
'Broad money growth (annual %)'],
|
1567
|
-
|
1568
|
-
['FM.LBL.MQMY.XD','货币流通速度(GDP/M2)',
|
1569
|
-
'Income velocity of money (GDP/M2)',
|
1570
|
-
'Income velocity of money (GDP/M2)'],
|
1571
|
-
|
1572
|
-
['FM.LBL.BMNY.GD.ZS','广义货币(占GDP%)',
|
1573
|
-
'Broad money (% of GDP)',
|
1574
|
-
'Broad money (% of GDP)'],
|
1575
|
-
|
1576
|
-
['FM.LBL.BMNY.IR.ZS','广义货币供应量与总储备的比率',
|
1577
|
-
'Broad money to total reserves ratio',
|
1578
|
-
'Broad money to total reserves ratio'],
|
1579
|
-
# total reserves:总储备,FI.RES.TOTL.CD,指外汇储备和其他国际储备资产。
|
1580
|
-
# 即央行持有的外汇储备、黄金储备、国际货币基金组织(IMF)特别提款权(SDR)等可动用的国际储备资产总和。
|
1581
|
-
# 用于衡量一个国家 货币供应量 相对于其 外汇储备和其他国际储备资产 的充足程度的指标,反映该国应对资本外流或货币危机的能力。
|
1582
|
-
#
|
1583
|
-
# 经济意义与用途:
|
1584
|
-
# 衡量货币体系的脆弱性:
|
1585
|
-
# 比率越高,说明广义货币规模远超储备资产,可能面临资本外流时央行干预能力不足的风险(例如外汇储备无法覆盖货币兑换需求)。
|
1586
|
-
# 典型案例:1997年亚洲金融危机中,泰国、韩国等国因该比率过高(外汇储备不足),导致本币大幅贬值。
|
1587
|
-
# 评估货币政策与汇率稳定性:
|
1588
|
-
# 高比率可能表明:
|
1589
|
-
# 央行依赖资本管制或外债来维持汇率稳定;
|
1590
|
-
# 若遭遇市场恐慌(如外资撤离),本币贬值压力加大。
|
1591
|
-
# 国际比较与预警指标:
|
1592
|
-
# 新兴市场通常关注该比率,因其资本流动波动性大。
|
1593
|
-
# 经验阈值:若比率超过 5倍(500%),可能被视为风险较高(需结合外债、经常账户等指标综合判断)。
|
1594
|
-
#
|
1595
|
-
# 与“M2/GDP”对比:“M2/GDP”反映经济货币化程度,而“M2/总储备”侧重外部风险。
|
1596
|
-
|
1597
|
-
# 国际贸易==============================================================
|
1598
|
-
['TM.TAX.MRCH.SM.AR.ZS','所有商品的实际平均关税%',
|
1599
|
-
'Tariff rate, applied, simple mean, all products (%)',
|
1600
|
-
'Tariff rate, applied, simple mean, all products (%)'],
|
1601
|
-
|
1602
|
-
['TM.TAX.MRCH.SM.FN.ZS','所有商品的最惠国平均关税%',
|
1603
|
-
'Tariff rate, most favored nation, simple mean, all products (%)',
|
1604
|
-
'Tariff rate, most favored nation, simple mean, all products (%)'],
|
1605
|
-
# 注意:最惠国关税是从最惠国进口商品名义上的最高关税水平,不是实际水平。
|
1606
|
-
# 这里是简单平均!
|
1607
|
-
# 因此,实际关税水平很可能低于最惠国名义关税水平。原因在于:
|
1608
|
-
# 最惠国待遇(MFN)与特殊关税安排:
|
1609
|
-
# 最惠国待遇(MFN):最惠国待遇是世界贸易组织(WTO)框架下的基本原则之一,要求成员方给予任何一个成员方的优惠,必须自动给予所有其他成员方。因此,'TM.TAX.MRCH.SM.FN.ZS' 反映的是中国对最惠国待遇下的商品征收的关税水平。
|
1610
|
-
# 特殊关税安排:中国与其他国家或地区之间可能存在自由贸易协定(FTA)、关税优惠协定或其他特殊贸易安排,这些安排允许某些商品享受比最惠国税率更低的关税甚至零关税。这些特殊安排下的商品关税水平被反映在实际关税水平指标'TM.TAX.MRCH.SM.AR.ZS'中。
|
1611
|
-
# 关税配额制度:
|
1612
|
-
# 关税配额:中国可能对某些商品实施关税配额制度,即在一定配额内享受较低的关税税率,超过配额部分则按较高税率征收。这种制度使得实际关税水平低于最惠国税率。
|
1613
|
-
# 非关税壁垒的影响:
|
1614
|
-
# 非关税壁垒:虽然非关税壁垒(如进口配额、技术标准、卫生检疫要求等)不直接降低关税水平,但它们可能间接影响实际关税水平。例如,某些商品可能因为非关税壁垒而进口量较少,从而使得实际关税收入占比较低。
|
1615
|
-
|
1616
|
-
['TM.TAX.MRCH.WM.AR.ZS','所有商品的实际加权平均关税%',
|
1617
|
-
'Tariff rate, applied, weighted mean, all products (%)',
|
1618
|
-
'Tariff rate, applied, weighted mean, all products (%)'],
|
1619
|
-
|
1620
|
-
['TM.TAX.MRCH.WM.FN.ZS','所有商品的最惠国加权平均关税%',
|
1621
|
-
'Tariff rate, most favored nation, weighted mean, all products (%)',
|
1622
|
-
'Tariff rate, most favored nation, weighted mean, all products (%)'],
|
1623
|
-
|
1624
|
-
['NE.EXP.GNFS.ZS','出口商品和服务占GDP%',
|
1625
|
-
'Exports of goods and services (% of GDP)',
|
1626
|
-
'Exports of goods and services (% of GDP)'],
|
1627
|
-
|
1628
|
-
['NE.IMP.GNFS.CD','进口商品和服务总金额(美元现价)',
|
1629
|
-
'Imports of goods and services (current US$)',
|
1630
|
-
'Imports of goods and services (current US$)'],
|
1631
|
-
|
1632
|
-
['NE.EXP.GNFS.CD','出口商品和服务总金额(美元现价)',
|
1633
|
-
'Exports of goods and services (current US$)',
|
1634
|
-
'Exports of goods and services (current US$)'],
|
1635
|
-
|
1636
|
-
['NE.IMP.GNFS.ZS','进口商品和服务占GDP%',
|
1637
|
-
'Imports of goods and services (% of GDP)',
|
1638
|
-
'Imports of goods and services (% of GDP)'],
|
1639
|
-
|
1640
|
-
['NE.TRD.GNFS.ZS','国际贸易占GDP%',
|
1641
|
-
'Trade % of GDP',
|
1642
|
-
'Trade % of GDP'],
|
1643
|
-
# 用来分析一个国家对国际贸易的依赖程度。
|
1644
|
-
# 高贸易占比通常表明一个国家的经济结构以出口和进口为主,而低贸易占比可能表明经济更依赖国内消费或投资。
|
1645
|
-
|
1646
|
-
# 贫困和贫富分化========================================================
|
1647
|
-
['SI.POV.GINI','基尼指数',
|
1648
|
-
'Gini index',
|
1649
|
-
'Gini index'],
|
1650
|
-
# 基尼指数:0-100,用于衡量收入或财富分配的不平等程度。
|
1651
|
-
# 0表示完全平等,100表示完全不平等。基尼系数高通常意味着贫富差距较大。
|
1652
|
-
# 注意不是基尼系数(0-1)。
|
1653
|
-
|
1654
|
-
# 薪酬=================================================================
|
1655
|
-
['GC.GDP.COMP.ZS','劳动者薪酬占GDP%',
|
1656
|
-
'Compensation of employees (% of GDP)',
|
1657
|
-
'Compensation of employees (% of GDP)'],
|
1658
|
-
# 自制指标:= GC.XPN.COMP.ZS: Compensation of employees (% of expense)
|
1659
|
-
# x GC.XPN.TOTL.GD.ZS: Expense (% of GDP) / 100。
|
1660
|
-
# 或 = GC.XPN.COMP.CN: Compensation of employees (current LCU)
|
1661
|
-
# / NY.GDP.MKTP.CN: GDP (current LCU) * 100.
|
1662
|
-
|
1663
|
-
# 储蓄=================================================================
|
1664
|
-
['NY.GNS.ICTR.ZS','国民储蓄总额占GDP%',
|
1665
|
-
'Gross savings (% of GDP)',
|
1666
|
-
'Gross savings (% of GDP)'],
|
1667
|
-
# 国民储蓄:一国居民和政府的总储蓄,包含国内储蓄和来自国外的净收入
|
1668
|
-
# 包含国际要素:计入来自国外的净要素收入(如投资收益、侨汇)。
|
1669
|
-
|
1670
|
-
['NY.GDS.TOTL.ZS','国内储蓄总额占GDP%',
|
1671
|
-
'Gross Domestic Savings (% of GDP)',
|
1672
|
-
'Gross Domestic Savings (% of GDP)'],
|
1673
|
-
# 国内储蓄:仅统计国内经济主体(家庭、企业、政府)的储蓄,不包含国外净收入。
|
1674
|
-
# 仅限国内:不涉及国际收入或支出。
|
1675
|
-
|
1676
|
-
# 投资=================================================================
|
1677
|
-
['NE.GDI.TOTL.ZS','总资本形成占GDP%',
|
1678
|
-
'Gross capital formation (% of GDP)',
|
1679
|
-
'Gross capital formation (% of GDP)'],
|
1680
|
-
# 又名Gross domestic investment国内总投资,包括政府、企业和家庭的投资
|
1681
|
-
|
1682
|
-
['NE.GDI.FTOT.ZS','总固定资本形成占GDP%',
|
1683
|
-
'Gross fixed capital formation (% of GDP)',
|
1684
|
-
'Gross fixed capital formation (% of GDP)'],
|
1685
|
-
# 又名Gross domestic fixed investment国内固定资产总投资,包括政府、企业和家庭的投资
|
1686
|
-
|
1687
|
-
['BX.KLT.DINV.WD.GD.ZS','外国直接投资净额占GDP%',
|
1688
|
-
'Foreign direct investment, net inflows (% of GDP)',
|
1689
|
-
'Foreign direct investment, net inflows (% of GDP)'],
|
1690
|
-
# 等于FDI流入 - FDI流出
|
1691
|
-
|
1692
|
-
# 政府财政==============================================================
|
1693
|
-
['GC.REV.XGRT.GD.ZS','政府总收入(不含国际赠款)占GDP%',
|
1694
|
-
'Revenue, excluding grant (% of GDP)',
|
1695
|
-
'Revenue, excluding grant (% of GDP)'],
|
1696
|
-
# 包括税收和非税收入
|
1697
|
-
|
1698
|
-
['SH.XPD.GHED.GD.ZS','政府卫生支出占GDP%',
|
1699
|
-
'Government health expenditure (% of GDP)',
|
1700
|
-
'Domestic general government health expenditure (% of GDP)'],
|
1701
|
-
# 包括税收和非税收入
|
1702
|
-
|
1703
|
-
['SH.XPD.GHED.CH.ZS','政府卫生支出占当前卫生支出%',
|
1704
|
-
'Government health expenditure (% of health expenditure)',
|
1705
|
-
'Domestic general government health expenditure (% of current health expenditure)'],
|
1706
|
-
# 包括税收和非税收入
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
], columns=['indicator','cword','eword','original_eword'])
|
1722
|
-
|
1723
|
-
found=False; result=indicator
|
1724
|
-
try:
|
1725
|
-
dict_word=trans_dict[trans_dict['indicator']==indicator.upper()]
|
1726
|
-
found=True
|
1727
|
-
except:
|
1728
|
-
#未查到翻译词汇,返回原词
|
1729
|
-
pass
|
1730
|
-
|
1731
|
-
if dict_word is None:
|
1732
|
-
found=False
|
1733
|
-
elif len(dict_word) == 0:
|
1734
|
-
found=False
|
1735
|
-
|
1736
|
-
if found:
|
1737
|
-
lang=check_language()
|
1738
|
-
|
1739
|
-
if DEBUG:
|
1740
|
-
print(f"DEBUG: indicator={indicator}, lang={lang}, dict_word={dict_word}")
|
1741
|
-
|
1742
|
-
if lang == 'Chinese':
|
1743
|
-
result=dict_word['cword'].values[0]
|
1744
|
-
else:
|
1745
|
-
result=dict_word['eword'].values[0]
|
1746
|
-
|
1747
|
-
return result
|
1748
|
-
|
1749
|
-
if __name__=='__main__':
|
1750
|
-
indicator='NE.CON.PRVT.CD'
|
1751
|
-
indicator='NE.CON.PRVT.KD'
|
1752
|
-
|
1753
|
-
indicator='NE.CON.PRVT.CN'
|
1754
|
-
indicator='NE.CON.PRVT.KN'
|
1755
|
-
|
1756
|
-
result=economic_translate(indicator)
|
1757
|
-
economic_translate(indicator)[1]
|
1758
|
-
|
1759
|
-
#==============================================================================
|
1760
|
-
|
1761
|
-
|
1762
|
-
def country_translate(country):
|
1763
|
-
"""
|
1764
|
-
===========================================================================
|
1765
|
-
功能:翻译国家名称
|
1766
|
-
参数:
|
1767
|
-
country: 国家名称英文,并非国家代码。
|
1768
|
-
返回值:是否找到,基于语言环境为中文或英文解释。
|
1769
|
-
语言环境判断为check_language()
|
1770
|
-
|
1771
|
-
数据结构:['国家名称英文','国家名称中文','国家代码2位','国家代码3位']
|
1772
|
-
"""
|
1773
|
-
|
1774
|
-
import pandas as pd
|
1775
|
-
trans_dict=pd.DataFrame([
|
1776
|
-
|
1777
|
-
['China','中国','CN','CHN'],
|
1778
|
-
['United States','美国','US','USA'],
|
1779
|
-
['Japan','日本','JP','JPN'],
|
1780
|
-
['Germany','德国','DE','DEU'],
|
1781
|
-
['India','印度','IN','IND'],
|
1782
|
-
['Brazil','巴西','BR','BRA'],
|
1783
|
-
|
1784
|
-
['France','法国','FR','FRA'],
|
1785
|
-
['United Kingdom','英国','GB','GBR'],
|
1786
|
-
['Russian Federation','俄罗斯','RU','RUS'],
|
1787
|
-
['Canada','加拿大','CA','CAN'],
|
1788
|
-
['Australia','澳大利亚','AU','AUS'],
|
1789
|
-
['Korea, Rep.','韩国','KR','KOR'],
|
1790
|
-
|
1791
|
-
['Italy','意大利','IT','ITA'],
|
1792
|
-
['Mexico','墨西哥','MX','MEX'],
|
1793
|
-
['South Africa','南非','ZA','ZAF'],
|
1794
|
-
['Saudi Arabia','沙特阿拉伯','SA','SAU'],
|
1795
|
-
['Indonesia','印度尼西亚','ID','IDN'],
|
1796
|
-
['Turkiye','土耳其','TR','TUR'],
|
1797
|
-
|
1798
|
-
['Argentina','阿根廷','AR','ARG'],
|
1799
|
-
['Egypt','埃及','EG','EGY'],
|
1800
|
-
['European Union','欧盟','EU','EUU'],
|
1801
|
-
['Hong Kong SAR, China','中国香港','HK','HKG'],
|
1802
|
-
['Taiwan, China','中国台湾','TW','TWN'],
|
1803
|
-
['World','全球','1W','WLD'],
|
1804
|
-
|
1805
|
-
['Singapore','新加坡','SG','SGP'],
|
1806
|
-
['Malaysia','马来西亚','MY','MYS'],
|
1807
|
-
['Thailand','泰国','TH','THA'],
|
1808
|
-
['Israel','以色列','IL','ISR'],
|
1809
|
-
['Vietnam','越南','VN','VNM'],
|
1810
|
-
['Philippines','菲律宾','PH','PHL'],
|
1811
|
-
['Brunei','文莱','BN','BRN'],
|
1812
|
-
['Cambodia','柬埔寨','KH','KHM'],
|
1813
|
-
|
1814
|
-
['Laos','老挝','LA','LAO'],
|
1815
|
-
['Myanmar','缅甸','MM','MMR'],
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
], columns=['ecountry','ccountry','country code2','country code3'])
|
1822
|
-
|
1823
|
-
found=False; result=country
|
1824
|
-
try:
|
1825
|
-
dict_word=trans_dict[trans_dict['ecountry']==country]
|
1826
|
-
found=True
|
1827
|
-
except:
|
1828
|
-
#未查到翻译词汇,返回原词
|
1829
|
-
pass
|
1830
|
-
|
1831
|
-
if dict_word is None:
|
1832
|
-
found=False
|
1833
|
-
elif len(dict_word) == 0:
|
1834
|
-
found=False
|
1835
|
-
|
1836
|
-
if found:
|
1837
|
-
lang=check_language()
|
1838
|
-
if lang == 'Chinese':
|
1839
|
-
result=dict_word['ccountry'].values[0]
|
1840
|
-
else:
|
1841
|
-
#result=dict_word['ecountry'].values[0]
|
1842
|
-
pass
|
1843
|
-
|
1844
|
-
return result
|
1845
|
-
|
1846
|
-
if __name__=='__main__':
|
1847
|
-
country='China'
|
1848
|
-
country='United States'
|
1849
|
-
|
1850
|
-
result=country_translate(country)
|
1851
|
-
|
1852
|
-
#==============================================================================
|
1853
|
-
|