Securities Bao Www.baostock.com is a free, open-source securities data platform.
Provide a large number of accurate and complete securities historical market data, listed company financial data, real-time securities market push services.
Acquisition of securities data information through the Python API, to meet quantitative trading investors, quantitative financial enthusiasts, metering economic practitioners data needs.
This introduction interface: Get quarterly profitability data :query_profit_data ()
(The following code from the official website, invasion and deletion )
Method Description: Query quarterly profitability information, can be set by the parameters of the corresponding year, quarter data, to provide 2007 to date data.
return type: The Dataframe type of pandas.
The sample code is as follows:
IMPORT BAOSTOCK AS BSIMPORT PANDAS AS PD # Landing System Lg = bs.login (user_id= "Anonymous", password= "123456") # display login return information print (' Login respond error_code: ' +lg.error_code ' Print (' login respond error_msg: ' +lg.error_msg) # Query quarterly Estimation index profitability Profit_list = []rs_profit = bs.query_profit_data (code= "sh.600000", year=2017, quarter=2) while (rs_profit.error_code == ' 0 ') & rs_profit.next (): profit_list.append (Rs_profit.get_row_data ()) result_profit = pd. DataFrame (profit_list, columns=rs_profit.fields) # printed output print (result_profit) # result set Output to CSV file Result_ Profit.to_csv ("D:\\profit_data.csv", encoding= "GBK", index=false) # logout system bs.logout ()
parameter meaning:
Code: Stock code, SH or sz.+6 digit code, or index code, such as: sh.601398. SH: Shanghai; SZ: Shenzhen. This parameter is not nullable;
Year: Statistic year, default current year for empty;
Quarter: Statistic quarter, can be empty, default current quarter. When not empty, there are only 4 values: 1,2,3,4.
Return Data Description
parameter name |
parameter description |
code |
security code |
pubdate |
date of publication of the company's earnings |
statdate |
Last day of the quarter of the earnings statistics, such as 2017-03-31, 2017-06-30 |
roeavg |
Return on equity (%) |
npmargin |
Net sales interest rate (%) |
gpmargin |
Gross sales margin (%) |
netprofit |
net profit (million yuan) |
epsttm |
earnings per share |
mbrevenue |
main operating income (million yuan) |
Sample data:
These profitability data are not a small help for stock selection.
Baostock: Use Python's Baostock interface to query quarterly profitability