diff --git a/NEWS.md b/NEWS.md index 9496725..a876c69 100755 --- a/NEWS.md +++ b/NEWS.md @@ -3,10 +3,12 @@ * fixed a bug in pq_plot function to support candle chart * the md_stock_symbol supports to query the constituent symbols of Chinese securities index * fixed a bug in md_moneycn function to query lpr +* fixed a bug in md_stock_symbol supports to query stock symbol constituent of index +* pq_plot supports order with multiple terms # pedquant 0.2.4 -* fixed mutual bugs +* fixed several bugs # pedquant 0.2.3 @@ -21,7 +23,7 @@ # pedquant 0.2.2 * replace stock data source from the 163 to the Eastmoney -* fixed mutual bugs +* fixed several bugs # pedquant 0.2.1 @@ -46,7 +48,7 @@ # pedquant 0.1.7 -* fixed mutual bugs in the functions such as get_fromto, md_stock_divsplit1_163, md_stock_symbol etc. +* fixed several bugs in the functions such as get_fromto, md_stock_divsplit1_163, md_stock_symbol etc. * modified stock adjust method for 163 data * md_stock function supports to query listed company information, such as profile, IPO, structure of income, structure of employee diff --git a/R/md_2chinamoney.R b/R/md_2chinamoney.R index 700d0f1..2426ac9 100644 --- a/R/md_2chinamoney.R +++ b/R/md_2chinamoney.R @@ -57,7 +57,7 @@ md_moneycn_symbol = function() { ) } md_moneycn_widelong = function(dt) { - . = name = symbol = NULL + . = name = symbol = value = NULL melt(dt, id.vars = 'date', variable.name = 'symbol', value.name = 'value')[ md_moneycn_symbol()[], on = 'symbol', nomatch = 0 @@ -83,6 +83,8 @@ md_cnshibor = function(date_range = '3y', from=NULL, to=Sys.Date(), ...) { # loan prime rate, lpr md_cnlpr = function(date_range = 'max', from=NULL, to=Sys.Date(), ...) { + cn1ylpr = cn5ylpr = value = symbol = NULL + ## from/to to = check_to(to) from = check_from(date_range, from, to, default_from = "1997-01-01", default_date_range = '3y') diff --git a/R/pq_orders.R b/R/pq_orders.R index 00a0349..da2b920 100644 --- a/R/pq_orders.R +++ b/R/pq_orders.R @@ -11,7 +11,7 @@ # current prices: # current values check_odr = function(orders) { - . = symbol = side = prices = values = quantity = NULL + . = symbol = side = prices = values = quantity = side_term = n = term = NULL if (is.null(orders)) return(orders) # symbol, date, side, prices, quantity, values @@ -34,10 +34,25 @@ check_odr = function(orders) { ][, side := ifelse(values >= 0, 1, -1)] } - orders = orders[ - data.table(side=c(1,-1, 1.1,-1.1), side_bs = c('buy', 'sell', 'buy_short', 'sell_short')), - on='side', nomatch=0 - ][] + # side level + if (!('side_term' %in% names(orders))) { + if ('n' %in% names(orders)) { + orders = orders[, side_term := n] + } else if ('term' %in% names(orders)) { + orders = orders[, side_term := term] + } else { + orders = orders[, side_term := 10] + } + } + + # side type + if (!('side_bs' %in% names(orders))) { + orders = orders[ + data.table(side=c(1,-1, 1.1,-1.1), side_bs = c('buy', 'sell', 'buy_short', 'sell_short')), + on='side', nomatch=0 + ][] + } + } return(orders) diff --git a/R/pq_plot2.R b/R/pq_plot2.R index f720ae7..e76315c 100644 --- a/R/pq_plot2.R +++ b/R/pq_plot2.R @@ -8,7 +8,7 @@ pp_yrng = function(dt, y, yb, yrng=NULL, ...) { pp_dtpre = function(dt, x='date', y='close', addti = NULL, markline = TRUE, - orders = NULL, order_y = 'prices', order_type = 'side_bs') { + orders = NULL, order_y = 'prices', order_type = 'side_bs', order_term = 'side_term') { sybnam = symbol = name = markline_value = NULL dt = setorderv(copy(dt), c('symbol', x))[, sybnam := sprintf('%s %s', symbol, name[.N]), by = 'symbol'] @@ -31,10 +31,11 @@ pp_dtpre = function(dt, x='date', y='close', dt = merge( dt, dcast(orders, - sprintf('%s ~ %s', paste0(dtodr_cols,collapse='+'), order_type), + sprintf('%s ~ %s + %s', paste0(dtodr_cols,collapse='+'), order_type, order_term), value.var = order_y), by = dtodr_cols, all.x = TRUE ) + } return(dt) @@ -101,14 +102,31 @@ p_markline = function(e, dt, markline = TRUE) { } # orders p_orders = function(e, orders, color_up = "#CF002F", color_down = "#000000", orders_ml=FALSE, ...) { + side_term = side_bs = NULL + if (is.null(orders)) return(e) - # long - if ('buy' %in% unique(orders$side_bs)) e = e_scatter_(e, 'buy', symbol = 'triangle', symbolSize = 12, color = color_up, legend = FALSE) - if ('sell' %in% unique(orders$side_bs)) e = e_scatter_(e, 'sell', symbol = 'triangle', symbolSize = 12, symbolRotate=180, color = color_down, legend = FALSE) - # short - if ('buy_short' %in% unique(orders$side_bs)) e = e_scatter_(e, 'buy_short', symbol = 'triangle', symbolSize = 12, color = color_up, legend = FALSE) - if ('sell_short' %in% unique(orders$side_bs)) e = e_scatter_(e, 'sell_short', symbol = 'triangle', symbolSize = 12, symbolRotate=180, color = color_down, legend = FALSE) + lvls = orders[order(-side_term)][,unique(side_term)] + sybs = rep_len(c('triangle', 'arrow', 'diamond'), length(lvls)) + cols = orders[, unique(paste(side_bs, side_term, sep = '_'))] + + for (i in seq_along(lvls) ) { + sybi = sybs[i] + sybsize = 12 - (i*i-1) + + # long + col1 = sprintf('buy_%s', lvls[i]) + if (col1 %in% cols) e = e_scatter_(e, col1, symbol = sybi, symbolSize = sybsize, color = color_up, legend = FALSE) + col2 = sprintf('sell_%s', lvls[i]) + if (col2 %in% cols) e = e_scatter_(e, col2, symbol = sybi, symbolSize = sybsize, symbolRotate=180, color = color_down, legend = FALSE) + + # short + col3 = sprintf('buy_short_%s', lvls[i]) + if (col3 %in% cols) e = e_scatter_(e, col3, symbol = sybi, symbolSize = sybsize, color = color_up, legend = FALSE) + col4 = sprintf('sell_short_%s', lvls[i]) + if (col4 %in% cols) e = e_scatter_(e, col4, symbol = sybi, symbolSize = sybsize, symbolRotate=180, color = color_down, legend = FALSE) + } + if (isFALSE(orders_ml)) return(e) for (o in split(orders,by='side_bs')) { @@ -414,8 +432,11 @@ pp_candle = function( #' #' # orders #' b2 = dt_banks[symbol %in% c('601988.SH', '601398.SH')] -#' b2orders = b2[sample(.N, 10), .(symbol, date, prices=close, -#' side=sample(c(-1, 1), 10, replace=TRUE))] +#' b2orders = b2[sample(.N, 20), .( +#' symbol, date, prices=close, +#' side = sample(c(-1, 1), 20, replace=TRUE), +#' term = sample(c(10, 20), 20, replace=TRUE) +#' )] #' #' e5 = pq_plot(b2, orders=b2orders) #' e5[[1]] diff --git a/docs/404.html b/docs/404.html index 6f52691..6b0e595 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,7 +32,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/LICENSE.html b/docs/LICENSE.html index b2e1748..5d9e04b 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/authors.html b/docs/authors.html index e79d551..1f8f1e9 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 @@ -74,14 +74,13 @@

Citation

Xie S (2024). pedquant: Public Economic Data and Quantitative Analysis. -R package version 0.2.4, https://github.com/ShichenXie/pedquant. +https://github.com/ShichenXie/pedquant, https://pedquant.com/.

@Manual{,
   title = {pedquant: Public Economic Data and Quantitative Analysis},
   author = {Shichen Xie},
   year = {2024},
-  note = {R package version 0.2.4},
-  url = {https://github.com/ShichenXie/pedquant},
+  note = {https://github.com/ShichenXie/pedquant, https://pedquant.com/},
 }
diff --git a/docs/index.html b/docs/index.html index 8104807..d09ba2e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -38,7 +38,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/news/index.html b/docs/news/index.html index 79547fc..fa91c40 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 @@ -59,8 +59,16 @@

Changelog

- -
+
+ +
@@ -75,7 +83,7 @@
diff --git a/docs/reference/dt_banks.html b/docs/reference/dt_banks.html index f1baaee..02b6ad1 100644 --- a/docs/reference/dt_banks.html +++ b/docs/reference/dt_banks.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/dt_ssec.html b/docs/reference/dt_ssec.html index dfa1656..2d55b45 100644 --- a/docs/reference/dt_ssec.html +++ b/docs/reference/dt_ssec.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/ed_code.html b/docs/reference/ed_code.html index 5a98b27..b1febf8 100644 --- a/docs/reference/ed_code.html +++ b/docs/reference/ed_code.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/ed_fred.html b/docs/reference/ed_fred.html index 7216a47..62424f6 100644 --- a/docs/reference/ed_fred.html +++ b/docs/reference/ed_fred.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/ed_fred_symbol.html b/docs/reference/ed_fred_symbol.html index 5dd8f6f..8c9a832 100644 --- a/docs/reference/ed_fred_symbol.html +++ b/docs/reference/ed_fred_symbol.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/ed_nbs.html b/docs/reference/ed_nbs.html index 7f5b8e5..a075ef4 100644 --- a/docs/reference/ed_nbs.html +++ b/docs/reference/ed_nbs.html @@ -1,5 +1,5 @@ -query NBS economic data — ed_nbs • pedquantquery NBS economic data — ed_nbs • pedquant @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 @@ -60,7 +60,7 @@

query NBS economic data

-

ed_nbs provides an interface to query economic data from National Bureau of Statistics of China (NBS, http://www.stats.gov.cn/).

+

ed_nbs provides an interface to query economic data from National Bureau of Statistics of China (NBS, https://www.stats.gov.cn/).

diff --git a/docs/reference/ed_nbs_subregion.html b/docs/reference/ed_nbs_subregion.html index 64e3c51..7f4c6bc 100644 --- a/docs/reference/ed_nbs_subregion.html +++ b/docs/reference/ed_nbs_subregion.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999
diff --git a/docs/reference/ed_nbs_symbol.html b/docs/reference/ed_nbs_symbol.html index dbda8df..1c64e2f 100644 --- a/docs/reference/ed_nbs_symbol.html +++ b/docs/reference/ed_nbs_symbol.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/index.html b/docs/reference/index.html index e596f0f..c20c2bf 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/md_bond.html b/docs/reference/md_bond.html index 3cad8d7..bd9b5c3 100644 --- a/docs/reference/md_bond.html +++ b/docs/reference/md_bond.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/md_forex.html b/docs/reference/md_forex.html index 9fc04de..10f3513 100644 --- a/docs/reference/md_forex.html +++ b/docs/reference/md_forex.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/md_future.html b/docs/reference/md_future.html index 9e2369e..76942be 100644 --- a/docs/reference/md_future.html +++ b/docs/reference/md_future.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/md_future_symbol.html b/docs/reference/md_future_symbol.html index fb86b57..89eb65b 100644 --- a/docs/reference/md_future_symbol.html +++ b/docs/reference/md_future_symbol.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/md_money.html b/docs/reference/md_money.html index 4e1acb4..b0abc40 100644 --- a/docs/reference/md_money.html +++ b/docs/reference/md_money.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/md_moneycn.html b/docs/reference/md_moneycn.html index 9fa3cc7..601467b 100644 --- a/docs/reference/md_moneycn.html +++ b/docs/reference/md_moneycn.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/md_stock.html b/docs/reference/md_stock.html index b1b4adf..ea05410 100644 --- a/docs/reference/md_stock.html +++ b/docs/reference/md_stock.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/md_stock_adjust.html b/docs/reference/md_stock_adjust.html index 4cb0b60..1a78bbd 100644 --- a/docs/reference/md_stock_adjust.html +++ b/docs/reference/md_stock_adjust.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/md_stock_financials.html b/docs/reference/md_stock_financials.html index 15f514e..238f871 100644 --- a/docs/reference/md_stock_financials.html +++ b/docs/reference/md_stock_financials.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/md_stock_symbol.html b/docs/reference/md_stock_symbol.html index 6f66bdf..b0d9029 100644 --- a/docs/reference/md_stock_symbol.html +++ b/docs/reference/md_stock_symbol.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 @@ -88,6 +88,8 @@

Examples

## choose exchanges interactivly ex_syb2 = md_stock_symbol() +# constituent stock symbol of index +dtidx = md_stock_symbol(index = c('930050', '000300', '000905', '000852')) } diff --git a/docs/reference/md_symbol.html b/docs/reference/md_symbol.html index ce5bde7..82b59de 100644 --- a/docs/reference/md_symbol.html +++ b/docs/reference/md_symbol.html @@ -1,5 +1,5 @@ -symbol of market data — md_symbol • pedquantsymbol of market data — md_symbol • pedquant @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 @@ -60,7 +60,7 @@

symbol of market data

-

md_stock_symbol returns all symbols by market category, including forex, money, bond, stock, future.

+

md_symbol returns all symbols by market category, including forex, money, bond, stock, future.

diff --git a/docs/reference/pq_addti.html b/docs/reference/pq_addti.html index 6c5db7f..7e7ac39 100644 --- a/docs/reference/pq_addti.html +++ b/docs/reference/pq_addti.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999
diff --git a/docs/reference/pq_addti_funs.html b/docs/reference/pq_addti_funs.html index d3270ab..080ff99 100644 --- a/docs/reference/pq_addti_funs.html +++ b/docs/reference/pq_addti_funs.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/pq_freq.html b/docs/reference/pq_freq.html index 1233799..5ccaaf9 100644 --- a/docs/reference/pq_freq.html +++ b/docs/reference/pq_freq.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/pq_opr.html b/docs/reference/pq_opr.html index 3f8a3fa..759d4c5 100644 --- a/docs/reference/pq_opr.html +++ b/docs/reference/pq_opr.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/pq_performance.html b/docs/reference/pq_performance.html index 00af18a..1b7f968 100644 --- a/docs/reference/pq_performance.html +++ b/docs/reference/pq_performance.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/pq_performance_funs.html b/docs/reference/pq_performance_funs.html index db87db0..37b8f46 100644 --- a/docs/reference/pq_performance_funs.html +++ b/docs/reference/pq_performance_funs.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/pq_plot.html b/docs/reference/pq_plot.html index c24e1a6..71edb0d 100644 --- a/docs/reference/pq_plot.html +++ b/docs/reference/pq_plot.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 @@ -174,8 +174,11 @@

Examples

# orders b2 = dt_banks[symbol %in% c('601988.SH', '601398.SH')] -b2orders = b2[sample(.N, 10), .(symbol, date, prices=close, - side=sample(c(-1, 1), 10, replace=TRUE))] +b2orders = b2[sample(.N, 20), .( + symbol, date, prices=close, + side = sample(c(-1, 1), 20, replace=TRUE), + term = sample(c(10, 20), 20, replace=TRUE) +)] e5 = pq_plot(b2, orders=b2orders) e5[[1]] diff --git a/docs/reference/pq_portfolio.html b/docs/reference/pq_portfolio.html index 101952c..baaa279 100644 --- a/docs/reference/pq_portfolio.html +++ b/docs/reference/pq_portfolio.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/docs/reference/pq_return.html b/docs/reference/pq_return.html index 879bd16..f09c32f 100644 --- a/docs/reference/pq_return.html +++ b/docs/reference/pq_return.html @@ -17,7 +17,7 @@ pedquant - 0.2.4 + 0.2.4.999 diff --git a/man/pq_plot.Rd b/man/pq_plot.Rd index 73154d7..2149822 100644 --- a/man/pq_plot.Rd +++ b/man/pq_plot.Rd @@ -79,8 +79,11 @@ e4[[1]] # orders b2 = dt_banks[symbol \%in\% c('601988.SH', '601398.SH')] -b2orders = b2[sample(.N, 10), .(symbol, date, prices=close, - side=sample(c(-1, 1), 10, replace=TRUE))] +b2orders = b2[sample(.N, 20), .( + symbol, date, prices=close, + side = sample(c(-1, 1), 20, replace=TRUE), + term = sample(c(10, 20), 20, replace=TRUE) +)] e5 = pq_plot(b2, orders=b2orders) e5[[1]]