md_stock: query stock market data

Description Usage Arguments Examples

Description

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

Usage

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

Arguments

symbol

symbols of stock shares.

source

the available data sources are 'yahoo' (http://finance.yahoo.com) and '163' (http://money.163.com).

freq

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

date_range

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

from

the start date. Default is NULL.

to

the end date. Default is current system date.

type

the data type, including history, dividend and split. Default is history.

adjust

logical, whether to adjust the prices for dividend. The price data already adjust for splits by default.

print_step

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

...

Additional parameters.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Example I
# query history prices from yahoo
dt_yahoo1 = md_stock(symbol=c("^GSPC", "000001.SS"))

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

# for Chinese shares
## the symbol without suffix
dt_yahoo2 = md_stock(c("000001", "^000001"))
## the symbol with suffix
dt_yahoo3 = md_stock(c("000001.sz", "000001.ss"))

# split
dt_split = md_stock(symbol=c("AAPL", "000001.SZ", "000001.SS"), 
                    type='split', date_range='max')
# dividend
dt_dividend = md_stock(symbol=c("AAPL", "000001.SZ", "000001.SS"), 
                       type='dividend', date_range='max')

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

# 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 index in sse and szse
dt_spot3 = md_stock(symbol='index', source="163", type='spot')

ShichenXie/getpedr documentation built on May 28, 2019, 8:26 a.m.