Macroeconomic data
A wide range of domestic macroeconomic data can be obtained from the Tushare platform using Tushare's built-in functions, such as money supply, reserve requirement ratio, deposit and loan rates, GDP, consumer price index and ex-factory industrial price index for multiple periods.
Money supply
The ts.get_money_supply() function allows you to obtain data on our money supply for each of the last 30 years.
import tushare as ts
df = ts.get_money_supply()
df.head()
df.columns
Return value description.
Parameter | Explanation |
---|---|
month | Statistics time |
m2 | Monetary and quasi-monetary (broad money M2) (billion yuan) |
m2_yoy | Monetary and quasi-monetary (broad money M2) year-on-year growth (%) |
m1 | Money (Narrow Money M1) (billions of yuan) |
m1_yoy | Money (narrow money M1) year-on-year growth (%) |
m0 | Cash in circulation (M0) ($bn) |
m0_yoy | Cash in circulation (M0) year-on-year growth (%) |
cd | Demand deposits ($bn) |
cd_yoy | Demand deposits growth (%) |
qm | Quasi-currency ($bn) |
qm_yoy | Quasi-currency growth (%) |
ftd | Time deposits ($bn) |
ftd_yoy | Year-on-year growth in time deposits (%) |
sd | Savings deposits ($bn) |
sd_yoy | Savings deposits growth (%) |
rests | Other deposits ($bn) |
rests_yoy | Year-on-year growth in other deposits (%) |
Deposit rates and loan rates
Tushare provides corresponding interface functions for different types of interest rates in order for developers to obtain the required interest rate data. The deposit rate function get_deposit_rate() and the loan rate function get_loan_rate() can be used to obtain the deposit rate and loan rate data issued by the People's Bank of China since 1989 respectively.
import tushare as ts
df = ts. get_loan_rate()
df.head()
Shibor Rate
The Shanghai Interbank Offered Rate (Shibor) is the arithmetic average of the RMB interbank offered rates calculated and determined by a quotation group of banks with high credit ratings, using the National Interbank Offered Rate Centre in Shanghai as the technical platform to calculate, publish and name the rate.
import tushare as ts
pro = ts.pro_api('用户tushare token')
df=pro.shibor()
df.head()
Other interest rate pro interface functions.
(1) pro.shibor_quote():Shibor quoted data
(2) pro.shibor_lpr():LPR lending base rate
(3) pro.libor():LIBOR
(4) pro.Hibor():Hong Kong Interbank Offered Rate
Stock Quote Data
From the Tushare platform, users can access the stock trading data of all listed companies on the Shanghai Stock Exchange and Shenzhen Stock Exchange, as well as the data of various stock indices (e.g. SSE Composite Index, SZSE Component Index, GEM Index, CSI 300 Index and SMB Index, etc.) of these two markets. The following commands can be executed in sequence to obtain historical daily ticker data for stock code 600848.
import tushare as ts
df = ts.get_hist_data('600848', ktype = 'D')
df.head()
Return value description.
Parameter | Explanation |
---|---|
date | Date |
open | Opening price |
high | Highest price |
close | Closing price |
low | Lowest price |
volume | volume |
price_change | price change |
p_change | price_change |
ma5 | 5-day average |
ma10 | 10 Day Average |
ma20 | 20 Day Average |
v_ma5 | 5-day average volume |
v_ma10 | 10 Day Average |
v_ma20 | 20 Day Average |
turnover | turnover |
The Tushare package provides a number of pro interface functions to return historical stock data. Registered users of the platform can use the pro interface functions to obtain stock quotes, but most of the pro interface functions require users to have a certain number of points before they can be called. The operation of the pro interface function to obtain daily stock quotes is as follows.
import tushare as ts
pro = ts.pro_api()
df = pro.daily(ts_code = '600008.SH', start_date = '20000501', end_date = '20190808')
df.head()
There are some structural differences between the quotation data obtained with the pro interface function pro.daily() and the quotation data obtained with the get_hist_data() function. The return data from the pro.daily() function uses the default index, with the date of the transaction as a field (column) data item, whereas the return data from the get_hist_data() function uses the date of the transaction as an index.
Given that the structure of the data returned by the different interface functions differs to a greater or lesser extent, it is important to design programs that process this data in such a way that the appropriate processing method is chosen based on the structure of the data returned, or that the data items returned are modified as necessary to meet the formatting requirements of other data processing statements.
Tushare also provides real-time data on stock trading quotes, i.e. data on the prices of stocks that are being traded on that day. For example, the real time stock trading data obtained through the get_realtime_quotes() function can include information such as the list of quotes and transaction prices of the stock at the current moment, the five buy quotes and five sell prices and other data items, with a total of more than 30 items of information. The operation process is as follows.
import tushare as ts
df = ts.get_realtime_quotes('300274')
df[['code','name','price','bid','ask','volume','amount','time']]
Partial return value description.
Parameter | Explanation |
---|---|
code | Stock code |
name | Name of the stock |
price | Current price |
high | Today's high price |
low | Today's low price |
bid | The bid price, i.e. "buy one" offer |
ask | bid to sell, i.e. "sell one" offer |
volume | volume maybe you need do volume/100 amount, amount traded ($ CNY) |
Fundamental data of listed companies
The Tushare platform provides fundamental data on listed companies, including financial position, profitability, market share, management structure, talent composition and more. In addition to stock price data, financial analysts often need fundamental data on listed companies to understand the value of a company's investment.
Tushare provides the interface functions for listed companies' fundamental data as shown in the table.
Stock Index Data
A stock index is a composite price value of stocks compiled by a stock exchange or financial services institution that reflects the price movements of a particular group (class) of stocks.
Stock exchanges and some financial services institutions have compiled and publicly released dozens of stock price indices, and stock investors are accustomed to using stock indices as an observational indicator of stock market price movements.
The pro.index_basic () function can be used to obtain the various stock indices published by the SSE.
import tushare as ts
pro = ts.pro_api('用户tushare token')
df = pro.index_basic(market = 'SSE')
df.head()
The following two tables list the input and output parameters of the Tushare platform pro version interface function index_basic().