md_stock provides an interface to query EOD (end of date) stock prices.

md_stock(symbol, source = "163", type = "history", freq = "daily",
  date_range = "3y", from = NULL, to = Sys.Date(), adjust = NULL,
  print_step = 1L, ...)



symbols of stock shares.


the available data sources are 'yahoo' ( and '163' (


the data type, including history, adjfactor, spot and info. Default is history.


default is daily. It supports daily, weekly and monthly for yahoo data; daily for 163 data.


date range. Available value including '1m'-'11m', 'ytd', 'max' and '1y'-. Default is '3y'.


the start date. Default is NULL.


the end date. Default is current system date.


whether to adjust the OHLC prices, defaults to NULL. If it is NULL, return the original data; if it is FALSE, create a close_adj column if not exist; if it is TRUE, adjust all open, high, low, close columns. For the yahoo data, the adjustment is based on the close_adj; for the 163 data, the adjustment is based on the cumulative products of close/close_prev.


A non-negative integer. Print symbol name by each print_step iteration. Default is 1L.


Additional parameters.


if (FALSE) {
# Example I
# query history prices from yahoo
# dt_yahoo1 = md_stock(symbol=c("^GSPC", "000001.SS"), source = 'yahoo')

# FAANG = md_stock(c('FB', 'AMZN', 'AAPL', 'NFLX', 'GOOG'), date_range = 'max', source = 'yahoo')

# for Chinese shares/fund
## the symbol without suffix
dt_yahoo2 = md_stock(c("000001", "^000001", "512510"))
## the symbol with suffix
dt_yahoo3 = md_stock(c("", ""))

# adjust factors, splits and dividend
dt_adj = md_stock(symbol=c("000001.SZ", "000001.SS"), 
                    type='adjfactor', date_range='max', source = '163')

# Example II
# query history prices from 163
dt1 = md_stock(symbol=c('600000', '000001', '^000001', '^399001'), 

# valuation ratios (pe, pb, ps)
# only available for stock shares in sse and szse
dt2 = md_stock(symbol=c('600000', '000001', '^000001', '^399001'), 
               source="163", valuation = TRUE)
# Example III
# query spot prices
dt_spot1 = md_stock(symbol=c('600000.SS', '000001.SZ', '000001.SS', '399001.SZ'), 
                    type='spot', source="163")

# query spot prices of all A shares in sse and szse
dt_spot2 = md_stock(symbol='a', source="163", type='spot')
# query spot prices of all A/B shares and index in sse and szse
dt_spot3 = md_stock(symbol=c('a', 'b', 'index'), source="163", type='spot')

# show spot prices and sector/industry
dt_spot4 = md_stock(symbol = c('a', 'b', 'index', 'fund'), source = '163', 
  type = 'spot', show_tags = TRUE)

# Example IV
# query company information (profile/ipo), revenue and staff
dt_info1 = md_stock('600036', type = 'info')

# query history revenue 
dt_info2 = md_stock('600036', type = 'info', rev_hist = TRUE)