Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor addCLV to follow skeleton_TA structure #96

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

erichung0404
Copy link

Refactor addCLV to use skeleton_TA structure. chartCLV function is given to create Close Location Value indicator based on skeleton_TA structure as following:

addTA <- function(arg, ...) {
  lenv <- new.env()
  lenv$chartTA <- function(x, arg, ...) {
    xdata <- x$Env$xdata
    xsubset <- x$Env$xsubset
    # special handling for arguments here

    ta <- TA(xdata, arg, ...)[xsubset]

    # draw indicators here

  }
  mapply(function(name, value) assign(name, value, lenv), names(list(arg = arg, ...)), list(arg = arg, ...))
  exp <- sub("list", "chartTA", as.expression(substitute(list(x = current.chob(), arg = arg, ...)), srcfile = NULL)
  exp <- c(exp, expression.to.add.legend)
  exp <- c(expression.to.add.background.and.horizontal.ticks, exp)
  lchob <- current.chob()
  x <- lchob$Env$xdata
  xsubset <- lchob$Env$xsubset
  ta <- TA(x, arg, ...)[xsubset]
  lchob$Env$ta <- ta
  lchob$add_frame(ylim, asp = 1, fixed = TRUE)
  lchob$next_frame()
  lchob$replot(exp, env = c(lenv, lchob$Env), expr = TRUE)
  lchob
}

As chartSeries is now a wrapper for chart_Series and chartSeries.chob
is deprecated, code of add* functions that manipulate chob and chobTA
objects breaks. So add* functions are refactored to use skeleton_TA
structure to coordinate with chart_Series called by chartSeries.

For those add* functions, however, quantmod::chart* functions are
untouched. New chart* functions are passed to lenv environment in add*
based on skeleton_TA structure.

quantmod::chart* functions will be deprecated.
When subset is specified in chartSeries, addVo() doesn't apply correct
subset volume to the chart. To fix this issue, subset setting is applied
to chartVo function in chartSeries and pass subset volume to the
environment.

y-axis limit of the frame is expanded to reserve space from the top.
When reChart is called to draw subset volume, bar colors are wrong and
subset functionality fails. The volume chart starts from the first day
of the series no matter what subset period is specified.

Pull out the panel settings from chartVo and wrap in expression.
Function y_grid_lines is not exported and is in plot_object$Env. chart*
functions called in add* are passed to "lenv" environment so y_grid_lines
cannot be found.

y_grid_lines function is defined in chart* by
y_grid_lines <- plot_object$Env$y_grid_lines.

For add*MA functions, x.tmp should not be passed by x.tmp[xsubset] because
when zoomChart is called, series used to calculate moving averages will
change with the subset period if we pass x.tmp[xsubset] to x.tmp. Moving
avrage indicators are passed to ma by ma <- *MA(x.tmp, ...)[xsubset] so
x.tmp should always be the initial series and should not change with the
subset period.
@erichung0404 erichung0404 force-pushed the refactor_add_CLV_chart branch 4 times, most recently from 4643b6b to 048a875 Compare August 12, 2016 14:04
To coordinate with functions that manipulate TA such as swapTA(), moveTA()
and dropTA(), TA values is passed to a new name list "TA" and function
calls are passed to call_list.
Pass subsetted bar.color to the histogram.
Updating the last price displayed on chart when zoomChart is
called to view subset series.
Pass color settings to addTA functions except for addSAR, addMACD,
addShading, addLines, addPoints and add*MA functions that have
their own 'col' argument.

Users can call chartTheme(addTA = list(...)) colors and pass
chart.theme object to chartSeries to manage desired chart colors.
@erichung0404 erichung0404 force-pushed the refactor_add_CLV_chart branch 6 times, most recently from bd3fbec to 6913356 Compare August 19, 2016 06:50
This commit is mainly for updating bug and cleaning up code for
addTA functions.

Originally, addTA functions' frame was set to be fixed so y limit
value was unchanged when zoomChart was called to zoom up the
indicators. The issue is not apparent in small data (~1000) and
indicators that have upper and lower limits such as RSI and Aroon.
But as the data grows bigger, TA's range will be larger. When
zoomChart is called to view a shorter period, say, a month, y limit
will be much greater than the value of the subset series, which makes
the chart diffcult to read.

Remove duplicated calculation for TA in lenv$chartTA.

Move the expression of adding border and grid lines to lenv$chartTA.

Add well-calculated TA to lenv to avoid duplicated calculation and
use lenv$TA to create the y limit for new frame.

Set TA's frame to be nonfixed.

Divide BBands settings into col and lty.

For addVo, minimum volume used to draw bars is replaced by the lower
y limit.

For addPoints, xts object is now allowed to be specified to x.
Fix the bug that points' location will change when zoomChart is
called.
Originally, argument "x" is mixed up with the x representing current
chart passed to chartPoints and chartLines, which makes points and
lines change with "x" continuously whenever new addPoints() and
addLines() are called.

New arguments are specified to chartPoints and chartLines to
distinguish from x representing the current chart.
Apply "col" setting to shading regime.
Match the laegend color of last volume in subset period with
the last bar color.

Update the legend volume to be in millions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants