-
-
Notifications
You must be signed in to change notification settings - Fork 224
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
erichung0404
wants to merge
12
commits into
joshuaulrich:master
Choose a base branch
from
erichung0404:refactor_chart_series
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor chart_Series() function to use xts::plot.xts #94
erichung0404
wants to merge
12
commits into
joshuaulrich:master
from
erichung0404:refactor_chart_series
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
force-pushed
the
refactor_chart_series
branch
2 times, most recently
from
August 10, 2016 08:41
90a419c
to
4c1a341
Compare
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.