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 chart_Series() function to use xts::plot.xts #94

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

Conversation

erichung0404
Copy link

Since chart_Series() function is now a wrapper for xts::plot.xts, there is no need to call new.replot() to recreate the framework that is closer to plot.xts. The main change is matching the parameters created by chart_theme() function with the new plot object created by plot.xts. Besides, as chartSeries() function is now the wrapper for chart_Series(), multi.col argument of chartSeries() that doesn't share with chart_Series() is handled in range.bars to have multiple bar and border colors.

In zoom_Chart() function, when plot_object$subset() function is called it throws an error: 'x' and 'y' lengths differ and creates wrong chart. The first problem is in xts:::chart.lines which calls lines() function to draw lines but the value for x doesn't change with the subset value of y. So a new chart.lines() function is given and passed to the .plotxtsEnv environment. The other problem is that y limit value doesn't change after subsetting so it is reset whenever subset period is specified.

As graphical parameter in .chob() environment are similar to .xts_chob()
in plot.xts, those parameter settings are replaced by plot.xts and
range.bars is called at the end to create candlesticks wrapped in
expression. In chart_Series.R, the add_* functions are also refactored
to obtain current plot object by calling xts:::current.xts_chob instead
of quantmod:::current.chob.
Update current.chob to call xts:::current.xts_chob

This avoids changing multiple calls to current.chob with calls to
xts:::current.xts_chob, by simply calling xts:::current.xts_chob inside
the current.chob function call.

grid.ticks.on and major.ticks should be drawn based on the data length
instead of specifying "weeks" directly.

Signed-off-by: Eric Hung <[email protected]>

Revert trailing whitespace changes

Signed-off-by: Eric Hung <[email protected]>

Revert unnecessary changes to text() call

Signed-off-by: Eric Hung <[email protected]>

Move stuff

Signed-off-by: Eric Hung <[email protected]>

Assign using <- instead of =

Signed-off-by: Eric Hung <[email protected]>

Use more informative name than 'type0'

Signed-off-by: Eric Hung <[email protected]>
Pass cex and mar arguments created by chart_pars() to plot.xts.
Use the original code of chart_Series to enable apply TA argument.

There is no special handling for TA in the previous commits. The original
code of chart_Series is used to handle TA but use 'seq_along' instead of
':' in loop.

If TA is zero length, 'for' loop still runs one iteration as 1:length(TA)
returns 1:0. So 'seq_along' is applied to avoid this issue.

To avoid getting 'expression()' or entering parse environment, if-else
statement is specified.
Add if-else statement to handle multi.col setting.

As chartSeries is going to be the wrapper for chart_Series which doesn't
share multi.col argument with chartSeries, special handling for multi.col
from quantmod:::chartSeries.chob is applied to range.bars which is called
by chart_Series.
As chartSeries is now a wrapper for chart_Series which calls range.bars
to chart, line.type is passed to range.bars to handle different line types
when set type='l' or type='line' in chartSeries.
When subset is assigned, y limit doesn't change with the range of subset of
the series. So the candlesticks will be smaller or bigger because y limit
doesn't change.

Subset x to update y limit.
New chart.lines function is given to fix error: 'x' and 'y' lengths
differ.

As x-axis and y-axis will not change with the subset series when using
plot_object$subset(), x-axis is fixed first.

x.pos is passed to x limit to control the number of subset series.
y limit is reset by specifying structured range of subset series.
Pass fade() to the environment of the plot object created by xts::plot.xts.
@erichung0404 erichung0404 force-pushed the refactor_chart_series branch 2 times, most recently from 90a419c to 4c1a341 Compare August 10, 2016 08:41
Since chart_Series defaults to have axis labels on both sides, RHS labels
will overlap the existing RHS labels. Moreover, when blotter::chart.Posn
function is called, RHS labels of add_TA sometimes different from the
existing ones because it is added based on "Buys", and "Sells" series.
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