MyNixOS website logo
Description

Public Economic Data and Quantitative Analysis.

Provides an interface to access public economic and financial data for economic research and quantitative analysis. The data sources including NBS, FRED, Sina, Eastmoney and etc. It also provides quantitative functions for trading strategies based on the 'data.table', 'TTR', 'PerformanceAnalytics' and etc packages.

pedquant

CRANstatus

pedquant (Public Economic Data and QUANTitative analysis) provides an interface to access public economic and financial data for economic research and quantitative analysis. The functions are grouped into three main categories,

  • ed_* (economic data) functions load economic data from NBS and FRED;
  • md_* (market data) functions load the forex, money, bond, stock, future market data from public data sources, including 163, Sina, qq finance and etc.
  • pq_* (quantitative analysis) functions create technical indicators, visualization charts and industrial index etc for time series data.

The functions in this package are designed to write minimum codes for some common tasks in quantitative analysis process. Since the parameters to get data can be interactively specify, it’s very easy to start. The loaded data have been carefully cleansed and provided in a unified format.

pedquant package has advantages on multiple aspects, such as the format of loaded data is a list of data frames, which can be easily manipulated in data.table or tidyverse packages; high performance on speed by using data.table and TTR; and interactive charts by using echarts4r. Similar works including tidyquant or quantmod.

Installation

  • Install the release version of pedquant from CRAN with:
install.packages("pedquant")
  • Install the developing version of pedquant from github with:
devtools::install_github("shichenxie/pedquant")

Example

The following examples show you how to import data.

library(pedquant)
packageVersion('pedquant')
#> [1] '0.2.4'
# loading data
## import eocnomic data
dat1 = ed_fred('GDPCA')
#> 1/1 GDPCA
dat2 = ed_nbs(geo_type='nation', freq='quarterly', symbol='A010101')

## import market data
FAAG = md_stock(c('META', 'AMZN', 'AAPL', 'GOOG'), date_range = '10y')
#> 1/4 meta
#> 2/4 amzn
#> 3/4 aapl
#> 4/4 goog
INDX = md_stock(c('^000001','^399001'), date_range = '10y')
#> 1/2 ^000001
#> 2/2 ^399001

# double moving average strategy
## add technical indicators
data("dt_banks")
dtbnkti = pq_addti(dt_banks, x='close_adj', sma=list(n=200), sma=list(n=50))

## crossover signals
library(data.table)
dtorders = copy(dtbnkti[['601988.SH']])[
   sma_50 %x>% sma_200, `:=`(side = 1,  prices = close_adj)
 ][sma_50 %x<% sma_200, `:=`(side = -1, prices = close_adj)
 ][order(date)
 ][, (c('side', 'prices')) := lapply(.SD, shift), .SDcols = c('side', 'prices')
 ][,.(symbol, name, date, side, prices)
 ][!is.na(side)]
head(dtorders)
#>       symbol     name       date side prices
#> 1: 601988.SH 中国银行 2021-04-20    1   5.76
#> 2: 601988.SH 中国银行 2021-08-19   -1   5.67
#> 3: 601988.SH 中国银行 2021-11-18    1   5.70
#> 4: 601988.SH 中国银行 2021-11-25   -1   5.71
#> 5: 601988.SH 中国银行 2022-01-18    1   5.72

# charting
e = pq_plot(setDT(dt_banks)[symbol=='601988.SH'],  y='close_adj', addti = list(sma=list(n=200), sma=list(n=50)), orders = dtorders)
# e[['601988.SS']]

Issues and Contributions

This package still on the developing stage. If you have any issue when using this package, please update to the latest version from github. If the issue still exists, report it at github page. Contributions in any forms to this project are welcome.

Metadata

Version

0.2.4

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows