网站首页 > 币百科 >

cmd虚拟货币

2023-06-17 00:37:13 币百科 阅读 0

Bitget下载

注册下载Bitget下载,邀请好友,即有机会赢取 3,000 USDT

APP下载   官网注册

银行存款利率普涨 大额存单利率创近一年新高

银行利率普遍上涨,创一年新高!

"据融360最新发布的监测数据显示,2019年3月份,银行各期限定期存款利率均值均比2月份有所上涨。其中2年期、3年期、5年期定期存款利率上涨幅度均超过1BP,涨幅最高的是3年期利率,环比上涨了2.26BP。而20万元起购的大额存单各期限利率继续上涨,均较基准上浮50%以上,创出自去年3月份以来的最高值。"

从这里有个商机,就是自动计算各大银行的存款利率,对于多金的朋友,自然就有办法赚钱了。

可惜,中国银行们没有对外的利率公布,就只好先看看用欧洲的公开接口了。

在下面文章里,我们将用Jupyter 笔记本从欧洲中央银行(ECB)检索数据。欧洲央行通过欧洲开放数据门户网站发布。

在深入研究代码之前,请快速浏览以下网站,了解我们将要处理的内容。


欧盟门户网站:https://data.europa.eu/euodp/en/data/publisher/ecb

ECB SDMX 2.1 RESTful Web服务:https://sdw-wsrest.ecb.europa.eu/help/

SDMX文档:https://sdmx.org

欧洲央行统计数据:https://www.ecb.europa.eu/stats/ecb_statistics/html/index.en.html

统计数据仓库:https://sdw.ecb.europa.eu


在本教程中,使用Python 3专门研究外汇(FX)汇率。与往常一样,我们首先导入一些我们将用于本练习的包。

import requests # 2.18.4import pandas as pd # 0.23.0import io

在这个程序,将检索从2000到今的欧元/瑞士法郎(EURCHF)汇率时间序列。要检索数据,我们需要构建一个我们可以使用的URL一个HTTP请求。幸运的是,这很简单。

查询字符串基本上是:

protocol://wsEntryPoint/resource/flowRef/key?parameters

参数定义如下:startPeriod = value&endPeriod = value&updatedAfter = value&firstNObservations = value&lastNObservations = value&detail = value&includeHistory = value

来动手实践下:

# Building blocks for the URLentrypoint = 'https://sdw-wsrest.ecb.europa.eu/service/' # Using protocol 'https'resource = 'data' # The resource for data queries is always'data'flowRef ='EXR' # Dataflow describing the data that needs to be returned, exchange rates in this casekey = 'D.CHF.EUR.SP00.A' # Defining the dimension values, explained below# Define the parametersparameters = { 'startPeriod': '2000-01-01', # Start date of the time series 'endPeriod': '2018-10-01' # End of the time series}

密钥(维度)解释:

  • 测量频率:D为每日
  • 被衡量的货币:瑞士法郎的瑞士法郎
  • 衡量货币的货币:欧元兑换欧元
  • 汇率类型:外汇参考汇率有SP00
  • 系列变异(如 平均 要么 标准化测量给定频率):代码A.

对于这个例子,只使用两个参数, startPerdiod 和 endPeriod, 但如果你愿意,你可以添加更多。

现在我们必须将所有这些组合在一起构建URL:

# Construct the URL: https://sdw-wsrest.ecb.europa.eu/service/data/EXR/D.CHF.EUR.SP00.Arequest_url = entrypoint + resource + '/'+ flowRef + '/' + key# Make the HTTP requestresponse = requests.get(request_url, params=parameters)# Check if the response returns succesfully with response code 200print(response)# Print the full URLprint(response.url)<回复[200]>https://sdw-wsrest.ecb.europa.eu/service/data/EXR/D.CHF.EUR.SP00.A?startPeriod=2000-01-01&endPeriod=2018-10-01

请求/响应已成功。如果单击此链接,它将以文件形式下载数据。它没有有用的扩展名,但如果要检查其内容,可以将其作为文本文件打开。但是,当然,也可以直接在Python命令行中完成此操作。让我们先看看收到的数据。

# Print the first 1000 characters of the responseprint(response.text[0:1000])<?xml version="1.0" encoding="UTF-8"?><message:GenericData xmlns:message="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message" xmlns:common="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:generic="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/generic" xsi:schemaLocation="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message https://sdw-wsrest.ecb.europa.eu:443/vocabulary/sdmx/2_1/SDMXMessage.xsd http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common https://sdw-wsrest.ecb.europa.eu:443/vocabulary/sdmx/2_1/SDMXCommon.xsd http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/generic https://sdw-wsrest.ecb.europa.eu:443/vocabulary/sdmx/2_1/SDMXDataGeneric.xsd"><message:Header><message:ID>fc64a350-0e32-4b02-a0a6-844bfee9764f</message:ID><message:Test>false</message:Test><message:Prepared>2018-10-15T20:36:58.177+02:00</message:Prepared><message:Sender id="ECB"/><message:Structure structureID="

嗯,响应是XML格式的。并非不可能,但也不是Pandas中最简单的格式。幸运的是,ECB的API允许我们通过在请求的标头中指定数据来获取CSV格式的数据。

# Make the HTTP request again, now requesting for CSV formatresponse = requests.get(request_url, params=parameters, headers={'Accept': 'text/csv'})# Response succesful? (Response code 200)print(response)<Response [200]># Print the first 1000 characters to inspect the responseresponse.text[0:1000]'KEY,FREQ,CURRENCY,CURRENCY_DENOM,EXR_TYPE,EXR_SUFFIX,TIME_PERIOD,OBS_VALUE,OBS_STATUS,OBS_CONF,OBS_PRE_BREAK,OBS_COM,TIME_FORMAT,BREAKS,COLLECTION,COMPILING_ORG,DISS_ORG,DOM_SER_IDS,PUBL_ECB,PUBL_MU,PUBL_PUBLIC,UNIT_INDEX_BASE,COMPILATION,COVERAGE,DECIMALS,NAT_TITLE,SOURCE_AGENCY,SOURCE_PUB,TITLE,TITLE_COMPL,UNIT,UNIT_MULT\r\nEXR.D.CHF.EUR.SP00.A,D,CHF,EUR,SP00,A,2000-01-03,1.6043,A,,,,P1D,,A,,,,,,,,,,4,,4F0,,Swiss franc/Euro,"ECB reference exchange rate, Swiss franc/Euro, 2:15 pm (C.E.T.)",CHF,0\r\nEXR.D.CHF.EUR.SP00.A,D,CHF,EUR,SP00,A,2000-01-04,1.6053,A,,,,P1D,,A,,,,,,,,,,4,,4F0,,Swiss franc/Euro,"ECB reference exchange rate, Swiss franc/Euro, 2:15 pm (C.E.T.)",CHF,0\r\nEXR.D.CHF.EUR.SP00.A,D,CHF,EUR,SP00,A,2000-01-05,1.606,A,,,,P1D,,A,,,,,,,,,,4,,4F0,,Swiss franc/Euro,"ECB reference exchange rate, Swiss franc/Euro, 2:15 pm (C.E.T.)",CHF,0\r\nEXR.D.CHF.EUR.SP00.A,D,CHF,EUR,SP00,A,2000-01-06,1.6068,A,,,,P1D,,A,,,,,,,,,,4,,4F0,,Swiss franc/Euro,"ECB reference exchange rate, Swiss franc/Euro, '

Good!现在我们只需要在Pandas DataFrame中加载此响应。我们可以使用'StringIO'将字符串作为文件读取。这样我们就不需要先保存它,我们可以直接使用它。

# Read the response as a file into a Pandas DataFramedf = pd.read_csv(io.StringIO(response.text))# Check the DataFrame's informationdf.info()<class'pandas.core.frame.DataFrame'>RangeIndex:4859个条目,0到4858数据列(共32列):KEY 4859非空对象FREQ 4859非空对象CURRENCY 4859非空对象CURRENCY_DENOM 4859非空对象EXR_TYPE 4859非空对象EXR_SUFFIX 4859非空对象TIME_PERIOD 4859非空对象OBS_VALUE 4798非null float64OBS_STATUS 4859非空对象OBS_CONF 238非空对象OBS_PRE_BREAK 0非null float64OBS_COM 0非null float64TIME_FORMAT 4859非空对象BREAKS 0非null float64COLLECTION 4859非空对象COMPILING_ORG 0非null float64DISS_ORG 0非null float64DOM_SER_IDS 0非null float64PUBL_ECB 0非null float64PUBL_MU 0非null float64PUBL_PUBLIC 0非null float64UNIT_INDEX_BASE 0非null float64COMPILATION 0非null float64COVERAGE 0非null float64DECIMALS 4859非null int64NAT_TITLE 0非null float64SOURCE_AGENCY 4859非空对象SOURCE_PUB 0非null float64TITLE 4859非null对象TITLE_COMPL 4859非空对象UNIT 4859非空对象UNIT_MULT 4859非null int64dtypes:float64(15),int64(2),object(15)内存使用量:1.2+ MB

可以看到有4858行,这对于近19年的每日价格是有意义的。有32列,可能比需要的更多。可以检查DataFrame以查看我们需要哪些列。

#显示DataFrame df.tail(5)
   KEY FREQ CURRENCY CURRENCY_DENOM EXR_TYPE EXR_SUFFIX TIME_PERIOD OBS_VALUE OBS_STATUS OBS_CONF ... COMPILATION COVERAGE DECIMALS NAT_TITLE SOURCE_AGENCY SOURCE_PUB TITLE TITLE_COMPL UNIT UNIT_MULT4854 EXR.D.CHF.EUR.SP00.A D CHF EUR SP00 A 2018-09-25 1.1376 A F ... NaN NaN 4 NaN 4F0 NaN Swiss franc/Euro ECB reference exchange rate, Swiss franc/Euro,... CHF 04855 EXR.D.CHF.EUR.SP00.A D CHF EUR SP00 A 2018-09-26 1.1369 A F ... NaN NaN 4 NaN 4F0 NaN Swiss franc/Euro ECB reference exchange rate, Swiss franc/Euro,... CHF 04856 EXR.D.CHF.EUR.SP00.A D CHF EUR SP00 A 2018-09-27 1.1371 A F ... NaN NaN 4 NaN 4F0 NaN Swiss franc/Euro ECB reference exchange rate, Swiss franc/Euro,... CHF 04857 EXR.D.CHF.EUR.SP00.A D CHF EUR SP00 A 2018-09-28 1.1316 A F ... NaN NaN 4 NaN 4F0 NaN Swiss franc/Euro ECB reference exchange rate, Swiss franc/Euro,... CHF 04858 EXR.D.CHF.EUR.SP00.A D CHF EUR SP00 A 2018-10-01 1.1414 A F ... NaN NaN 4 NaN 4F0 NaN Swiss franc/Euro ECB reference exchange rate, Swiss franc/Euro,... CHF 0

5行×32列

需要的列是“TIME_PERIOD”的日期和“OBS_VALUE”的价格。我们也要对'OBS_VALUE'中的价格进行健全性检查。

#检查价格。平均值,最小值和最大值是否有意义?df [ 'OBS_VALUE' ].describe()count 4798.000000mean 1.379459std 0.193938min 0.98160025% 1.20550050% 1.46730075% 1.547200max 1.680300Name: OBS_VALUE, dtype: float64

现在将使用日期和EURCHF价格创建一个名为'ts'(时间序列)的新DataFrame。

# Create a new DataFrame called 'ts'ts = df.filter(['TIME_PERIOD', 'OBS_VALUE'], axis=1)# 'TIME_PERIOD' was of type 'object' (as seen in df.info). Convert it to datetime firstts['TIME_PERIOD'] = pd.to_datetime(ts['TIME_PERIOD'])# Set 'TIME_PERIOD' to be the indexts = ts.set_index('TIME_PERIOD')# Print the last 5 rows to screents.tail()
 OBS_VALUETIME_PERIOD  2018-09-25 1.13762018-09-26 1.13692018-09-27 1.13712018-09-28 1.13162018-10-01 1.1414

最后,可视化时间序列图表:

%matplotlib inlinets.plot()<matplotlib.axes._subplots.AxesSubplot at 0x11d9beba8>

奖励:pandaSDMX

通常,您可以在互联网上使用方便的Python软件包。例如,如果您在互联网上搜索“Python ECB SDMX”,您将会undoubtly找到'pandaSDMX'包。正如他们所说的那样,它是一个“Python客户端,用于检索和获取SDMX 2.1中传播的统计数据和元数据,SDMX 2.1是统计局,中央银行和国际机构广泛使用的ISO标准。组织“。

有趣的是,pandaSDMX内置了对以下代理商的支持:

  • 澳大利亚统计局(ABS)
  • 欧洲中央银行(ECB)
  • 欧盟统计局
  • 法国国家统计研究所(INSEE)
  • Instituto Nacional delaEstadìsticayGeografìa - INEGI(墨西哥)
  • 国际货币基金组织(IMF) - 仅限SDMX中心
  • 国际劳工组织(ILO)
  • 意大利统计局(ISTAT)
  • 挪威银行(挪威)
  • 组织 经济合作与发展组织(经合组织)
  • 联合国统计司(UNSD)
  • UNESCO(需要免费注册)
  • 世界银行 - 世界综合贸易解决方案(WITS)

可以找到更多信息 在: https://pandasdmx.readthedocs.io/en/latest/index.html

在最后一节中,我们将使用此包检索相同的数据(EURCHF每日汇率)。 第一 但是,您需要通过'pip'(通过命令行)安装软件包:

pip install pandasdmx

现在获取数据!

from pandasdmx import Request# Define the sourceecb = Request('ECB')# Retrieve the data (we start at 2016, because are requesting a larger dataset (including other frequencies))data_response = ecb.data(resource_id = 'EXR', key={'CURRENCY': ['CHF', 'EUR']}, params = {'startPeriod': '2016'})data = data_response.data# The data will be a pandaSDMC 'DataSet'type(data)pandasdmx.model.DataSet# Show which frequencies are available ('D' is 'daily', you can probably guess the other ones)set(s.key.FREQ for s in data.series){'A', 'D', 'H', 'M', 'Q'}# Filter the the daily data and 'write' it to a DataFramedaily = (s for s in data.series if s.key.FREQ == 'D')ts2 = data_response.write(daily)ts2.tail()
FREQDCURRENCYCHFCURRENCY_DENOMEUREXR_TYPESP00EXR_SUFFIXATIME_PERIOD 2018-10-091.13812018-10-101.14122018-10-111.14302018-10-121.14702018-10-151.1428
%matplotlib inlinets2.plot()<matplotlib.axes._subplots.AxesSubplot at 0x12235c080>

pandaSDMX pacakage是另一种检索利率数据的简便方法。如果觉得不错,点个赞。

相关内容

cmd虚拟货币文档下载.: PDF DOC TXT

猜你喜欢