### Get CCTV News Data via Specific Interface Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches CCTV news data using a dedicated news_cctv interface. Supports specifying start and end dates, defaulting to the latest available news. ```python #也可以使用新闻联播数据接口获取,start和end默认为最新日期 df=qs.news_cctv(start='20221016',end='20221016') df.head() ``` -------------------------------- ### Get Main Business Composition Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches the main business composition of a company using its stock code or name. ```Python df=qs.main_business('丰元股份') ``` -------------------------------- ### Get CCTV News Data Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves news data for CCTV using the news_data function. Allows specifying start and end dates. If no dates are provided, it defaults to the latest news. ```python #参数start起始日期,end结束日期,使用默认参数输出最新日期新闻联播 df=qs.news_data('cctv',start='20221016',end='20221016') #df.head() ``` -------------------------------- ### Visualize Global Index Cumulative Returns Source: https://github.com/tkfy920/qstock/blob/master/README.md Plots the cumulative returns of various global stock market indices from a specified start date, normalized to show relative performance. ```python #常见的全球指数名称 global_indexs=['sh','cyb','恒生指数','道琼斯','标普500','纳斯达克','英国富时100','法国CAC40','德国DAX30','日经225','韩国KOSPI', '澳大利亚标普200','印度孟买SENSEX','台湾加权','俄罗斯RTS','加拿大S&P/TSX','巴西BOVESPA'] index_data=qs.get_price(global_indexs,start='2012-01-01').dropna() plot.line(index_data/index_data.iloc[0],title='全球指数累计涨幅(2012-2022)') ``` -------------------------------- ### Get Financial News Data (Python) Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves financial news data. The 'news_type' parameter can filter by source: 'cctv' or '新闻联播' (CCTV or Xinwen Lianbo), 'js' or '金十数据' (J10 Data), 'stock' or '个股新闻' (Stock News). If no parameters are provided, it defaults to financial news from Cailianshe. Start and end dates can be specified, and a stock code is required for 'stock' news type. ```Python import qstock as qs # Get Cailianshe telegram news data (default) df = qs.news_data() # print(df.tail()) ``` ```Python import qstock as qs # Get J10 Data news df = qs.news_data('js') # print(df.tail()) ``` -------------------------------- ### Get Macroeconomic Indicators (Python) Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches common macroeconomic indicators. Accepts a 'flag' parameter to specify the indicator: 'lpr' (Loan Prime Rate), 'ms' (Money Supply), 'cpi' (Consumer Price Index), 'ppi' (Producer Price Index), 'pmi' (Purchasing Managers' Index). Defaults to GDP data if no flag is provided. Specific interfaces like qs.cpi(), qs.gdp(), etc., are also available. ```Python import qstock as qs # Get GDP data df = qs.macro_data('gdp') # print(df) ``` ```Python import qstock as qs # Get CPI data df = qs.macro_data('cpi') # print(df) ``` ```Python import qstock as qs # Get PPI data df = qs.macro_data('ppi') # print(df) ``` ```Python import qstock as qs # Get PMI data df = qs.macro_data('pmi') # print(df) ``` ```Python import qstock as qs # Get Money Supply data df = qs.macro_data('ms') # print(df) ``` ```Python import qstock as qs # Get LPR data df = qs.macro_data('lpr') # print(df) ``` -------------------------------- ### Get Detailed Stock Financial Indicators Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches all historical financial analysis indicators for a given stock code over past reporting periods. ```Python df=qs.stock_indicator('中国平安') ``` -------------------------------- ### Get Stock Real-time Trading Snapshot Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves a real-time trading snapshot for a specific stock in the Shanghai and Shenzhen markets. The function requires the stock code as input. ```Python qs.stock_snapshot('中国平安') ``` -------------------------------- ### Get EPS Forecast Data Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves earnings per share (EPS) forecast data. ```Python df=qs.eps_forecast() ``` -------------------------------- ### Get Historical Fund Flow Data Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches historical fund inflow and outflow data for stocks, bonds, futures, and other financial instruments. ```Python df=qs.hist_money('中国平安') ``` -------------------------------- ### Get Stock Billboard Data Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves stock billboard data for a specified date range. The start and end dates default to None, indicating the latest data. The date format should be 'YYYY-MM-DD'. ```Python df=qs.stock_billboard('20220901','20221011') ``` -------------------------------- ### Get Historical K-line Data (Single Stock) Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches historical K-line (candlestick) data for a single stock. Users can specify the start and end dates, data frequency (daily, minute, etc.), and复权 (ex-right) type. The default is daily frequency with前复权 (forward adjustment). ```Python #默认日频率、前复权所有历史数据 #open:开盘价,high:最高价,low:最低价,close:收盘价 #vol:成交量,turnover:成交金额,turnover_rate:换手率 #在notebook上输入"qs.get_data?"可查看数据接口的相应参数 df=qs.get_data('601318') df.tail() ``` ```Python #个股code_list可以输入代码或简称或多个股票的list #获取中国平安2022年9月28日至今的5分钟数据,默认前复权 df=qs.get_data('中国平安',start='20220928',freq=5) df.tail() ``` -------------------------------- ### Get Major Shareholder Change Details Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches detailed information on changes in holdings by major shareholders. ```Python df=qs.stock_holder_change() df.head() ``` -------------------------------- ### Get Real-time Market Data (All Stocks) Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches the latest real-time market data for all securities in a specified market. The 'market' parameter accepts various predefined market types like '沪深A股' (A-shares), '期货' (futures), '概念板块' (concept sectors), and 'ETF'. If no 'code' is provided, it returns data for the entire market. ```Python #获取沪深A股最新行情指标 df=qs.realtime_data() #查看前几行 df.head() ``` ```Python #获取期货最新行情指标 df=qs.realtime_data('期货') #查看前几行 df.head() ``` ```Python #获取概念板块最新行情指标 df=qs.realtime_data('概念板块') #查看前几行 df.head() ``` ```Python #获取ETF最新行情指标 df=qs.realtime_data('ETF') #查看前几行 df.head() ``` -------------------------------- ### Get Historical Price Data (Multiple Securities) Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches historical closing prices for multiple securities (stocks, funds, bonds, futures) and returns them as a DataFrame. Users provide a list of security codes or names. ```Python code_list=['中国平安','300684','锂电池ETF','BK0679','上证指数'] df=qs.get_price(code_list) df.tail() ``` -------------------------------- ### Get Top 10 Shareholders Information Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches the top 10 shareholder information for a given stock code in the Shanghai and Shenzhen markets. It allows specifying the number of recent quarters for which to retrieve data. ```Python df=qs.stock_holder_top10('中国平安', n=2) ``` -------------------------------- ### Get Concept/Industry Board Names Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves names of concept or industry boards from Tonghuashun. The 'flag' parameter can be set to '概念板块' or '行业板块'. ```Python name_list=qs.ths_index_name('行业') name_list[:5] ``` ```Python name_list=qs.ths_index_name('概念') name_list[:5] ``` -------------------------------- ### Get Historical K-line Data (Futures) Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches historical K-line data for futures contracts. The function requires the futures contract name, including the contract month and year. ```Python df=qs.get_data('棕榈油2210') df.tail() ``` -------------------------------- ### Get Basic Stock Financial Indicators Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves basic financial indicators for one or multiple stocks, including net profit, total market value, circulating market value, industry, P/E ratio, P/B ratio, ROE, gross profit margin, and net profit margin. ```Python code_list=['300139','中国平安','西部建设','贵州茅台','丰元股份','002432'] df=qs.stock_basics(code_list) ``` -------------------------------- ### Get Concept/Industry Board Index Data Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves index market data (open, high, low, close, volume) for Tonghuashun concept or industry boards using their code or name. ```Python df=qs.ths_index_data('有机硅概念') ``` -------------------------------- ### Get Index Constituent Stocks Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves constituent stocks for common indices by providing the index name or code. ```Python df=qs.index_member('sz50') ``` ```Python qs.index_member('hs300') ``` -------------------------------- ### Get Stock Data Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches historical stock data for a given stock code and date range, including adjusted prices. The 'tail()' method displays the last few rows of the data. ```python #获取中国平安2022年至今前复权的数据 df=qs.get_data('中国平安',start='2022-06-01',end='2022-10-20') df.tail() ``` -------------------------------- ### Get Institutional Holdings Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves institutional holdings data from Sina Finance. The 'quarter' parameter specifies the reporting period, e.g., '20221' for Q1 2022. ```Python df=qs.institute_hold('20222') ``` -------------------------------- ### Get Concept Board Constituent Stocks Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches constituent stocks for a given Tonghuashun concept or industry board. Note that the Tonghuashun data interface can be unstable. ```Python df=qs.ths_index_member('种植业与林业') ``` ```Python df=qs.ths_index_member('有机硅概念') ``` -------------------------------- ### Get Shareholder Numbers Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves the changes in the number of shareholders for A-shares in the Shanghai and Shenzhen markets. Users can specify a particular reporting period or default to the latest. ```Python df=qs.stock_holder_num('20220930') ``` -------------------------------- ### Get Northbound Funds Data (Python) Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves northbound funds data. By default, it returns daily net inflow data. It can also provide rankings for industries, concepts, or individual stocks based on northbound fund increases over specified periods (1, 3, 5, 10 days, or monthly, quarterly, yearly). ```Python import qstock as qs # Get daily northbound funds net inflow data df = qs.north_money() # print(df.tail()) ``` ```Python import qstock as qs # Get 5-day rankings for industries based on northbound fund increases df = qs.north_money('行业', 5) # print(df.tail()) ``` ```Python import qstock as qs # Get 5-day rankings for concepts based on northbound fund increases df = qs.north_money('概念', 5) # print(df.tail()) ``` ```Python import qstock as qs # Get 5-day rankings for individual stocks based on northbound fund increases # Note: There's a known bug with column names in this specific call that will be fixed in a future version. df = qs.north_money('个股', 5) # print(df.tail()) ``` -------------------------------- ### Get Tonghuashun Fund Flow Data (Python) Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches fund flow data from Tonghuashun for stocks, concepts, or industries over specified periods (1, 3, 5, 10, 20 days). The 'flag' parameter specifies the data type (stock, concept, industry), and 'n' specifies the number of days. ```Python import qstock as qs # Get 20-day fund flow data for stocks df = qs.ths_money('个股', n=20) # print(df.tail()) ``` ```Python import qstock as qs # Get 10-day fund flow data for industries df = qs.ths_money('行业', n=10) # print(df.tail()) ``` ```Python import qstock as qs # Get 5-day fund flow data for concepts df = qs.ths_money('概念', n=5) # print(df.tail()) ``` -------------------------------- ### Get Intraday Trading Data Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches intraday trading data for a given security, which can be a stock, bond, future, or fund. The 'code' parameter accepts the security's name or code. The output includes details of the day's trading activity. ```Python #股票日内交易数据 df=qs.intraday_data('中国平安') df.head() ``` ```Python #基金日内交易数据 df=qs.intraday_data('有色50ETF') df.head() ``` -------------------------------- ### Get Historical K-line Data (US Stocks) Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves historical K-line data for US stocks. The function uses the stock ticker symbol as the identifier. ```Python #获取苹果公司股票数据 df=qs.get_data('AAPL') df.tail() ``` -------------------------------- ### Get Real-time Data for Specific Securities Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves real-time market data for specific securities identified by their names or codes. This function allows fetching data for individual stocks, multiple stocks, or even ETFs and indices by passing a list of identifiers to the 'code' parameter. ```Python qs.realtime_data(code=['中国平安','300684','锂电池ETF','BK0679','上证指数']) ``` -------------------------------- ### Get Stock News Data Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves news related to a specific stock using the news_data function with '个股' type and stock code. Alternatively, uses the stock_news function for the same purpose. ```python #使用新闻统一接口 df=qs.news_data('个股',code='天瑞仪器') df.head() ``` ```python #使用个股新闻接口 df=qs.stock_news('天瑞仪器') df.head() ``` -------------------------------- ### Get Stock Daily Fund Flow (Python) Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves the daily fund flow for a given stock code or name over a specified number of days. The default period is 3, 5, 10, and 20 days. Accepts stock name or code as input. ```Python import qstock as qs # Get fund flow for '中国平安' with default ndays=[3, 5, 10, 20] df = qs.stock_money('中国平安') # print(df.tail()) ``` ```Python import qstock as qs # Get fund flow for '中国平安' for 10 and 30 days df = qs.stock_money('中国平安', [10, 30, 60]) # print(df.tail()) ``` -------------------------------- ### Get Real-time Market Change Data Source: https://github.com/tkfy920/qstock/blob/master/README.md Fetches real-time market data based on specific 'anomalies' or changes, similar to a market monitoring tool. The 'flag' parameter allows filtering by types of changes like '火箭发射' (rocket launch), '快速反弹' (quick rebound), '封涨停板' (limit up), etc. A numerical index can also be used for the flag. ```Python df=qs.realtime_change('60日新高') #查看前几行 df.head() ``` ```Python #异动类型:火箭发射 df=qs.realtime_change(1) #查看前几行 df.head() ``` -------------------------------- ### Get Intraday Fund Flow Data Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves intraday minute-level fund inflow and outflow data for a single stock or bond on the latest trading day. This data is only available during trading hours on a trading day. ```Python df=qs.intraday_money('中国平安') ``` -------------------------------- ### Get Interbank Lending Rates (Python) Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves interbank lending rates for various markets and currencies. The 'market' parameter specifies the market (e.g., 'sh' for Shanghai, 'ch' for China, 'l' for London, 'eu' for Europe, 'hk' for Hong Kong, 's' for Singapore). The 'fc' parameter specifies the foreign currency (e.g., 'USD', 'EUR', 'GBP', 'JPY', 'HKD', 'SGD', 'CNY'). ```Python import qstock as qs # Get Shanghai Interbank Offered Rate (default) df = qs.ib_rate() # print(df) ``` ```Python import qstock as qs # Get China Interbank Offered Rate df = qs.ib_rate(market='ch') # print(df) ``` ```Python import qstock as qs # Get London Interbank Offered Rate for GBP df = qs.ib_rate(market='l', fc='GBP') # print(df) ``` ```Python import qstock as qs # Get London Interbank Offered Rate for USD df = qs.ib_rate('l', 'USD') # print(df) ``` ```Python import qstock as qs # Get London Interbank Offered Rate for EUR df = qs.ib_rate('l', 'EUR') # print(df) ``` ```Python import qstock as qs # Get London Interbank Offered Rate for JPY df = qs.ib_rate('l', 'JPY') # print(df) ``` ```Python import qstock as qs # Get European Interbank Offered Rate for EUR df = qs.ib_rate('eu') # print(df) ``` ```Python import qstock as qs # Get Hong Kong Interbank Offered Rate for USD df = qs.ib_rate('hk', 'USD') # print(df) ``` ```Python import qstock as qs # Get Hong Kong Interbank Offered Rate for HKD df = qs.ib_rate('hk', 'HKD') # print(df) ``` ```Python import qstock as qs # Get Hong Kong Interbank Offered Rate for CNY df = qs.ib_rate('hk', 'CNY') # print(df) ``` ```Python import qstock as qs # Get Singapore Interbank Offered Rate for USD df = qs.ib_rate('s', 'usd') # print(df) ``` ```Python import qstock as qs # Get Singapore Interbank Offered Rate for SGD df = qs.ib_rate('s', 'SGD') # print(df) ``` -------------------------------- ### Get Financial Statement Data Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves various financial statement data, including earnings reports, quick reports, forecasts, balance sheets, income statements, and cash flow statements. The 'flag' parameter specifies the report type, and 'date' can be used to filter by reporting period. ```Python df=qs.financial_statement('业绩报表',date='20220930') ``` ```Python df=qs.financial_statement('yjyg') ``` ```Python df=qs.financial_statement('yjkb') ``` ```Python df=qs.financial_statement('资产负债表') ``` ```Python df=qs.financial_statement('利润表') ``` ```Python df=qs.financial_statement('现金流量表') ``` -------------------------------- ### Get Historical K-line Data (Indices) Source: https://github.com/tkfy920/qstock/blob/master/README.md Retrieves historical K-line data for various stock market indices. For Chinese indices, it's recommended to use their Chinese abbreviations or pinyin (e.g., 'sh' for Shanghai Composite). Global indices can also be fetched using their common names. ```Python code_list=['sh','sz','cyb','zxb','hs300','sz50','zz500'] df=qs.get_data(code_list) df ``` ```Python global_indexs=['道琼斯','标普500','纳斯达克','恒生指数','英国富时','法国CAC40','德国DAX', '日经225','韩国KOSPI','澳大利亚标普200','印度孟买SENSEX','俄罗斯RTS','加拿大S&P', '台湾加权','美元指数','路透CRB商品指数'] ``` ```Python qs.get_data(global_indexs) ``` -------------------------------- ### Create Histogram with KDE Source: https://github.com/tkfy920/qstock/blob/master/README.md Generates a histogram and optionally overlays a Kernel Density Estimate (KDE) curve. Allows customization of the statistical measure (count, frequency, density, probability). ```Python plot.hist_kde(data, kde=True, stat='count', figsize=(15, 7)) ``` ```Python stat可选参数:count:观测数(默认);frequency:频数;density:密度;probability:概率 plot.hist_kde(data.close,stat='probability') ``` -------------------------------- ### Import qstock and Plotting Modules Source: https://github.com/tkfy920/qstock/blob/master/README.md Imports the qstock library and its plotting submodule for data analysis and visualization. ```python import qstock as qs from qstock import plot ``` -------------------------------- ### Import qstock Module Source: https://github.com/tkfy920/qstock/blob/master/README.md This snippet demonstrates how to import the qstock library for use in Python scripts. It's the initial step before accessing any of qstock's functionalities. ```Python #导入qstock模块 import qstock as qs ``` -------------------------------- ### Create Heatmap Source: https://github.com/tkfy920/qstock/blob/master/README.md Generates a heatmap to visualize data in a matrix format, often used for correlation matrices or time-series data. Requires x, y, and value data. ```Python plot.chart_heatmap(x, y, v, title=None, notebook=True) ``` ```Python sh0=qs.get_data('上证指数').close['2011':'2021'] sh=(sh0/sh0.shift(1)-1).to_period('M') sh=sh.groupby(sh.index).apply(lambda x: ((((1+x).cumprod()-1).iloc[-1])*100).round(2)) ``` ```Python x=[str(i) for i in range(2011,2022)] y=[str(i)+'月' for i in range(1,13)] v= [[i,j,sh[str(2011+i)+'-'+str(1+j)]] for i in range(11) for j in range(12)] plot.chart_heatmap(x,y,v,title='上证指数月度收益率') ``` -------------------------------- ### Create Histogram Source: https://github.com/tkfy920/qstock/blob/master/README.md Generates a histogram to show the distribution of a dataset. Supports logarithmic axes, orientation, and normalization options (percent, probability, density). ```Python plot.hist(data=None, x=None, y=None, title=None, color=None, legend=False, orientation=None, log_x=False, log_y=False, barmode='group', histnorm=None) ``` ```Python #1:'percent',2:'probability',3:'density',4:'probability density' code='晓程科技' data=qs.get_data(code,fqt=2) plot.hist(data,x='close',histnorm=3,title=code+'股价直方图') ``` -------------------------------- ### Create Heatmap with Color Source: https://github.com/tkfy920/qstock/blob/master/README.md Generates a heatmap with specific color mapping, likely for enhanced visual representation of data values. ```Python plot.chart_heatmap_color(x,y,v,title=None,notebook=True) ``` ```Python plot.chart_heatmap_color(x,y,v,title='上证综指月度收益率') ``` -------------------------------- ### Plot Stock Price and Moving Average Source: https://github.com/tkfy920/qstock/blob/master/README.md Creates a line chart comparing a stock's closing price with its 20-day moving average, providing insights into trend and momentum. ```python df['ma20']=df.close.rolling(20).mean() title='中国平安股价与20日均线' plot.line(df[['close','ma20']],title=title) ``` -------------------------------- ### Create Treemap for Concept Performance Source: https://github.com/tkfy920/qstock/blob/master/README.md Visualizes concept performance using a treemap, similar to sector performance, with size representing weight and color indicating performance. Excludes concepts with zero change. ```python #获取东方财富概念板块实时涨跌幅数据 data=qs.realtime_data('概念')[['名称','涨幅']] data['权重']=abs(data['涨幅']) data=data[data['涨幅']!=0] params={'data':data,'label':['名称'],'weight':'权重','value':'涨幅'} plot.treemap(**params) ```