Skip to content
Permalink
Browse files

0.1.0

  • Loading branch information...
ShichenXie committed Mar 9, 2019
1 parent 28bde64 commit dd3b97411f8e9f7eb16797f90e4c6cfc3ee02a65
Showing with 4,561 additions and 394 deletions.
  1. +1 −0 .Rbuildignore
  2. +5 −0 .travis.yml
  3. +3 −3 DESCRIPTION
  4. +1 −1 NEWS.md
  5. +12 −0 R/condition_helper_fun.R
  6. +1 −1 R/dim_0pd_code.R
  7. +5 −4 R/ed_fred.R
  8. +2 −2 R/ed_nbs.R
  9. +5 −0 R/md_0cate.R
  10. +5 −0 R/md_1forex.R
  11. +6 −0 R/md_2bond.R
  12. +7 −1 R/md_2money.R
  13. +1 −0 R/md_3index.R
  14. +4 −0 R/md_4commodity.R
  15. +2 −0 R/md_future.R
  16. +8 −5 R/md_stock1_.R
  17. +9 −4 R/md_stock1_163.R
  18. +5 −4 R/md_stock1_yahoo.R
  19. +1 −0 R/md_stock_adj.R
  20. +32 −24 R/md_stock_fs.R
  21. +7 −1 R/md_stock_symbol.R
  22. +3 −0 R/pq_addti.R
  23. +2 −2 R/pq_index.R
  24. +17 −9 R/pq_plot.R
  25. +19 −7 R/pq_return.R
  26. +5 −4 R/pq_to_freq.R
  27. +22 −22 R/z_md.R
  28. +37 −25 README.Rmd
  29. +84 −85 README.md
  30. +21 −20 _pkgdown.yml
  31. +609 −15 docs/LICENSE-text.html
  32. +14 −13 docs/authors.html
  33. +109 −29 docs/index.html
  34. +18 −17 docs/news/index.html
  35. +8 −4 docs/pkgdown.css
  36. +12 −7 docs/pkgdown.js
  37. +4 −4 docs/pkgdown.yml
  38. +185 −0 docs/reference/ed_fred.html
  39. +174 −0 docs/reference/ed_fred_symbol.html
  40. +207 −0 docs/reference/ed_nbs.html
  41. +167 −0 docs/reference/ed_nbs_subregion.html
  42. +167 −0 docs/reference/ed_nbs_symbol.html
  43. BIN docs/reference/figures/README-charts-1.png
  44. BIN docs/reference/figures/README-charts-2.png
  45. BIN docs/reference/figures/README-charts-3.png
  46. BIN docs/reference/figures/README-charts-4.png
  47. BIN docs/reference/figures/README-charts-5.png
  48. BIN docs/reference/figures/README-charts1-1.png
  49. BIN docs/reference/figures/README-charts2-1.png
  50. BIN docs/reference/figures/README-charts2-2.png
  51. BIN docs/reference/figures/README-example-1.png
  52. BIN docs/reference/figures/README-example-2.png
  53. BIN docs/reference/figures/README-example-3.png
  54. BIN docs/reference/figures/README-example-4.png
  55. BIN docs/reference/figures/README-p-alipay.jpg
  56. BIN docs/reference/figures/README-p-wechat.jpg
  57. +78 −65 docs/reference/index.html
  58. +183 −0 docs/reference/md_cate.html
  59. +187 −0 docs/reference/md_future.html
  60. +150 −0 docs/reference/md_future_symbol.html
  61. +237 −0 docs/reference/md_stock.html
  62. +182 −0 docs/reference/md_stock_financials.html
  63. +172 −0 docs/reference/md_stock_symbol.html
  64. +163 −0 docs/reference/pd_code.html
  65. +183 −0 docs/reference/pq_addti.html
  66. +187 −0 docs/reference/pq_index.html
  67. +180 −0 docs/reference/pq_perf.html
  68. +260 −0 docs/reference/pq_plot.html
  69. +195 −0 docs/reference/pq_return.html
  70. +167 −0 docs/reference/pq_to_freq.html
  71. BIN man/.DS_Store
  72. +2 −0 man/ed_fred_symbol.Rd
  73. BIN man/figures/.DS_Store
  74. BIN man/figures/README-charts-3.png
  75. BIN man/figures/README-charts-4.png
  76. BIN man/figures/README-charts-5.png
  77. BIN man/figures/README-charts1-1.png
  78. BIN man/figures/README-charts2-1.png
  79. BIN man/figures/README-charts2-2.png
  80. BIN man/figures/README-p-alipay.jpg
  81. BIN man/figures/README-p-wechat.jpg
  82. +2 −0 man/md_cate.Rd
  83. +8 −5 man/md_stock.Rd
  84. +1 −1 man/md_stock_symbol.Rd
  85. +1 −1 man/pd_code.Rd
  86. +10 −4 man/pq_plot.Rd
  87. +7 −5 man/pq_return.Rd
@@ -1,3 +1,4 @@
^\.travis\.yml$
^README\.Rmd$
^.*\.Rproj$
^\.Rproj\.user$
@@ -0,0 +1,5 @@
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
sudo: false
cache: packages
@@ -1,5 +1,5 @@
Package: pedquant
Version: 0.0.1
Version: 0.1.0
Title: public economic data and quantitative analysis
Description:
The `pedquant` provides an interface to access public economic data and
@@ -21,8 +21,8 @@ Suggests:
knitr,
rmarkdown
License: GPL-3 + file LICENSE
URL: https://github.com/ShichenXie/pedar
BugReports: https://github.com/ShichenXie/pedar/issues
URL: https://github.com/ShichenXie/pedquant
BugReports: https://github.com/ShichenXie/pedquant/issues
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 6.1.1
@@ -1,4 +1,4 @@
# getpedr 0.0.1
# pedquant 0.1.0

* Added a `NEWS.md` file to track changes to the package.

@@ -90,6 +90,8 @@ get_fromto = function(date_range, from, to, min_date, default_date_range = 'max'

# this function has been removed
tags_symbol_stockcn = function(symbol, mkt) {
syb = syb3 = NULL

sm = data.table(
syb = sub(".*?(\\d+).*","\\1", symbol), mkt = mkt
)[nchar(syb)==6, syb3 := substr(syb,1,3)
@@ -138,6 +140,8 @@ tags_symbol_stockcn = function(symbol, mkt) {
}
# tags of SSE/SZSE shares symbols
tags_dt = function() {
tags = exchg_code = NULL

setDT(list(
mkt = c('stock','stock','stock','stock','stock','stock','stock','stock','stock','stock','stock','stock','index','index'),
syb3 = c("600","601","603","900","000","001","002","003","004","300","200","201","000","399"),
@@ -148,6 +152,8 @@ tags_dt = function() {
][, exchg_code := toupper(substr(tags,1,2))][]
}
check_symbol_cn = function(symbol, mkt = NULL) {
exchg_code = syb3 = syb = syb_code = NULL

tags = tags_dt()[, exchg_code := tolower(exchg_code)][]

cn_dt = setDT(list(symbol = tolower(symbol)))
@@ -173,6 +179,8 @@ check_symbol_cn = function(symbol, mkt = NULL) {
}
# check SSE/SZSE share symbols to download data from 163/tx/yahoo
check_symbol_for_163 = function(symbol, mkt = NULL) {
syb_163 = city_code = syb = tags = NULL

symbol_163 = check_symbol_cn(
symbol, mkt
)[, syb_163 := paste0(city_code,syb)
@@ -182,6 +190,8 @@ check_symbol_for_163 = function(symbol, mkt = NULL) {
return(symbol_163)
}
check_symbol_for_tx = function(symbol, mkt = NULL) {
syb_tx = city = syb = tags = NULL

symbol_tx = check_symbol_cn(
symbol, mkt
)[, syb_tx := paste0(city,syb)
@@ -191,6 +201,8 @@ check_symbol_for_tx = function(symbol, mkt = NULL) {
return(symbol_tx)
}
check_symbol_for_yahoo = function(symbol, mkt = NULL) {
syb_yh = syb = exchg_code = tags = NULL

if (all(grepl('[0-9]{6}', symbol))) {
symbol = check_symbol_cn(
symbol, mkt
@@ -16,7 +16,7 @@
#' }
#'
#' @export
pd_code = function(cate=NULL, ...) {
pd_code = function(cate=NULL) {
code_category = c('country', 'currency', 'stock_exchange', 'commodity_exchange')

# market category
@@ -18,7 +18,7 @@
#' @import data.table
#' @importFrom jsonlite fromJSON
ed_fred1 = function(symbol1, from="1776-07-04", to="9999-12-31", na_rm=FALSE) {
. = title = value = NULL
group_id = name = . = title = value = NULL

key = api_key("fred")
base_url = "https://api.stlouisfed.org/fred/%sapi_key=%s&file_type=json"
@@ -99,7 +99,7 @@ ed_fred = function(symbol=NULL, date_range='10y', from=NULL, to=Sys.Date(), na_r
#' @importFrom jsonlite fromJSON
#' @import data.table
ed_fred_symbol_keywords = function(keywords, ...) {
. = name = popularity = series_count = frequency = id = title = observation_start = observation_end = seasonal_adjustment = last_updated = NULL
group_id = . = name = popularity = series_count = frequency = id = title = observation_start = observation_end = seasonal_adjustment = last_updated = NULL

key = api_key("fred")
base_url = "https://api.stlouisfed.org/fred/%sapi_key=%s&file_type=json"
@@ -132,7 +132,7 @@ ed_fred_symbol_keywords = function(keywords, ...) {
}

ed_fred_symbol_category = function(category=NULL, ...) {
. = name = popularity = series_count = frequency = id = title = observation_start = observation_end = seasonal_adjustment = last_updated = parent_id = sybs_search = NULL
symbol = group_id = . = name = popularity = series_count = frequency = id = title = observation_start = observation_end = seasonal_adjustment = last_updated = parent_id = sybs_search = NULL

key = api_key("fred")
base_url = "https://api.stlouisfed.org/fred/%sapi_key=%s&file_type=json"
@@ -210,6 +210,7 @@ ed_fred_symbol_category = function(category=NULL, ...) {
#'
#' @param category the category id. If it is NULL, then search symbols from the top categories step by step.
#' @param keywords the query text. If it is NULL, the function will search symbols by category.
#' @param ... ignored parameters
#'
#' @examples
#' \dontrun{
@@ -226,7 +227,7 @@ ed_fred_symbol_category = function(category=NULL, ...) {
#'
#' @export
ed_fred_symbol = function(category=NULL, keywords = NULL, ...) {
. = symbol = name = last_updated = NULL
frequency = . = symbol = name = last_updated = NULL

if (is.null(keywords)) {
series = ed_fred_symbol_category(category = category, ...)
@@ -188,7 +188,7 @@ ed1_nbs = function(nbs_geo, symbol1, subregion=NULL, from, eng=FALSE) {
# transform json data into dataframe
# symbol, variable, date, value, unit, desc
nbs_jsondat_format = function(jsondat) {
code = . = unit = cname = strdata = NULL
symbol=name=value=geo_code=geo = code = . = unit = cname = strdata = NULL

# data
dat = jsondat$returndata$datanodes$data
@@ -276,7 +276,7 @@ nbs_jsondat_format = function(jsondat) {
#' @import data.table
#' @export
ed_nbs = function(symbol=NULL, freq=NULL, geo_type=NULL, subregion=NULL, date_range='10y', from=NULL, to=Sys.Date(), na_rm=FALSE, eng=FALSE) {
# dim_region = dim_geo_type = dim_freq = dim_sta_db = value = NULL
code=dim_geo_type=dim_freq=dim_sta_db=geo_code=value=NULL

# arguments
## geography type
@@ -3,6 +3,8 @@ mkt_cate = setDT(list(
name = c('foregin exchange rate', 'Interbank offered rate', 'government bond yield', 'stock market index', 'commodity price')
))
func_md_symbol = function() {
.=symbol=name=main=NULL

rbindlist(list(
forex = func_forex_symbol(), # fred, oanda
money = func_ibor_symbol(), # fred, shibor
@@ -12,6 +14,7 @@ func_md_symbol = function() {
), idcol = 'category', fill = TRUE)
}


#' query main market data by category
#'
#' \code{md_cate} provides an interface to access main market data in five categories, including forex, money, bond, index, commodity.
@@ -22,6 +25,7 @@ func_md_symbol = function() {
#' @param from the start date. Default is NULL. If it is NULL, then calculate using date_range and end date.
#' @param to the end date. Default is the current date.
#' @param print_step a non-negative integer, which will print symbol name by each print_step iteration. Default is 1L.
#' @param ... ignored parameters
#'
#' @examples
#' \dontrun{
@@ -30,6 +34,7 @@ func_md_symbol = function() {
#'
#' @export
md_cate = function(cate=NULL, symbol=NULL, date_range = "3y", from = NULL, to = Sys.Date(), print_step = 1L, ...) {
category = NULL
# md_symbol = func_md_symbol()
# market category
if (!is.null(cate)) cate = check_arg(cate, mkt_cate$category)
@@ -84,6 +84,8 @@ forex_symbol_oanda = setDT(list(
# query forex historical data from oanda
# https://www.oanda.com/fx-for-business/historical-rates
md_forex1_oanda = function(symbol, from, to) {
name = NULL

syb = tolower(symbol)
# symbol
syb1 = substr(syb,1,3)
@@ -107,6 +109,8 @@ md_forex1_oanda = function(symbol, from, to) {
}
# query forex from FRED
md_forex1_fred = function(syb, from, to) {
symbol = symbol_fred = . = name = value = geo = NULL

syb_fred = forex_symbol_fred[symbol == tolower(syb), symbol_fred]
if (length(syb_fred) == 0) return(NULL)
# libor in history
@@ -125,6 +129,7 @@ md_forex1_fred = function(syb, from, to) {
#
# @export
md_forex = function(symbol=NULL, date_range = '3y', from=NULL, to=Sys.Date(), print_step=1L, ...) {
. = name = NULL

# arguments
syb = tolower(symbol)
@@ -59,6 +59,8 @@ urls_bond_chinabond = function() {
}
#' @import data.table
md_bond_chinabond = function(symbol, from=NULL, to=Sys.Date(), print_step=1L) {
value = . = maturity = NULL

symbol = tolower(symbol)
syb_len = length(symbol)
# years between from and to
@@ -105,6 +107,8 @@ md_bond_chinabond = function(symbol, from=NULL, to=Sys.Date(), print_step=1L) {

# query bond from FRED
md_bond1_fred = function(syb, from, to) {
symbol = symbol_fred = . = name = value = geo = NULL

# libor in history
dt_bond_hist = ed_fred(
bond_symbol_fred[symbol == syb, symbol_fred], from=from, to=to, print_step=0L
@@ -133,6 +137,8 @@ md_bond_fred = function(symbol, from=NULL, to=Sys.Date(), print_step=1L) {
#
# @export
md_bond = function(symbol=NULL, date_range = '3y', from=NULL, to=Sys.Date(), print_step=1L, ...) {
. = name = NULL

# arguments
syb = tolower(symbol)
## symbol
@@ -22,7 +22,7 @@ func_ibor_symbol = function() ibor_symbol
# shanghai interbank offered rate, shibor
#' @import data.table xml2
md_shibor = function(symbol, from=NULL, to=Sys.Date(), print_step=1L) {
V1 = NULL
. = name = value = V1 = NULL

# arguments
## symbols
@@ -78,6 +78,8 @@ md_shibor = function(symbol, from=NULL, to=Sys.Date(), print_step=1L) {

# london interbank offered rate, libor
md_libor1_last5 = function(currency) {
symbol = value = . = name = NULL

# libor in recent 5 days
# from # https://www.global-rates.com

@@ -102,6 +104,8 @@ md_libor1_last5 = function(currency) {
return(dt_libor_5)
}
md_libor1_hist = function(syb, from, to) {
symbol = symbol_fred = . = name = value = geo = NULL

# libor in history
dt_libor_hist = ed_fred(
libor_symbol[symbol == syb, symbol_fred], from=from, to=to, print_step=0L
@@ -149,6 +153,8 @@ md_libor = function(symbol, from=NULL, to=Sys.Date(), print_step=1L) {
#
# @export
md_money = function(symbol=NULL, date_range = '3y', from=NULL, to=Sys.Date(), print_step=1L, ...) {
. = name = NULL

# arguments
## symbol
if (is.null(symbol)) {
@@ -18,6 +18,7 @@ func_indices_symbol = function() index_symbol_yahoo
#
# @export
md_index = function(symbol=NULL, date_range = '3y', from=NULL, to=Sys.Date(), print_step=1L, ...) {
. = name = NULL
# arguments
# ## from/to
# ft = get_fromto(date_range, from, to, min_date = "1000-01-01", default_date_range = '3y')
@@ -7,6 +7,8 @@ func_commodity_symbol = function() commodity_symbol_fred

# query commodity price from FRED
md_commodity1_fred = function(syb, from, to) {
symbol=symbol_fred=.=name=value=NULL

syb_fred = commodity_symbol_fred[symbol == tolower(syb), symbol_fred]
if (length(syb_fred) == 0) return(NULL)
# libor in history
@@ -27,6 +29,8 @@ md_commodity1_fred = function(syb, from, to) {
#
# @export
md_commodity = function(symbol=NULL, date_range = '3y', from=NULL, to=Sys.Date(), print_step=1L, ...) {
. = name = NULL

# arguments
syb = tolower(symbol)
## symbol
@@ -14,6 +14,8 @@
#'
#' @export
md_future_symbol = function() {
.=board=symbol=name=exchange=NULL

# type = check_arg(type, c('financial', 'energy', 'metal', 'grain', 'soft', 'other'), default = NULL, arg_name = 'future type')

# cat('More commodity symbols go to\n', 'http://vip.stock.finance.sina.com.cn/quotes_service/view/qihuohangqing.html\n\n')
@@ -31,25 +31,28 @@
#' 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')
#' 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')
#' 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")
#' 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)
#' 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")
#' 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')

0 comments on commit dd3b974

Please sign in to comment.
You can’t perform that action at this time.