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/},
}