[R-SIG-Finance] Empty indicator / plot.window: need finite 'ylim' values

Joshua Ulrich jo@h@m@u|r|ch @end|ng |rom gm@||@com
Sun Aug 23 14:34:55 CEST 2020


I don't think this is possible with chart_Series() currently.

It looks similar to
https://github.com/joshuaulrich/quantmod/issues/81

Could you please file an issue on the GitHub tracker?  I'm not sure
when I'll have a chance to take a closer look, but the tracker issue
will make sure I don't lose track of it.

Best,
Josh

On Mon, Aug 17, 2020 at 4:46 PM Daniel Cegiełka
<daniel.cegielka using gmail.com> wrote:
>
>
>
> > On 17 Aug 2020, at 22:42, Mike <mike9 using posteo.nl> wrote:
>
> > Like Joshua wrote, indeed, I use chart_Series within a function.
> >
> >> But your problem is here:
> >>
> >> sample.xts[subset, 2]
> >
> > Yes, not the main window is the issue, but the indicator is. So I
> > have to ask more specific:
> >
> > Can I plot a subset of chart and indicator where the indicator's
> > subset is completely NA resulting in the indicator's plot region
> > being left blank?
> >
>
> you can try to force a value for ylim in the quantmod’s chart object:
>
> x <- chart_Series (sample.xts[,1], subset=subset, TA=ta)
>
> > x$Env$ylim
> [[1]]
> [1] 0 1
> attr(,"fixed")
> [1] FALSE
>
> [[2]]
> [1] 49.88096 50.67835
> attr(,"fixed")
> [1] FALSE
>
> [[3]]
> [1] 0 1
> attr(,"fixed")
> [1] FALSE
>
> [[4]]
> [1] -Inf  Inf
> attr(,"fixed")
> [1] FALSE
>
>
> e.g.:
>
> > x$Env$ylim[[4]] <- structure(c(0, 1), 'fixed' = FALSE)
> >
> > x$Env$ylim[[4]]
> [1] 0 1
> attr(,"fixed")
> [1] FALSE
>
> however, it is still overwritten:
>
> > x  # or plot(x)
> Error in plot.window(c(1, 21), c(NaN, NaN)) : need finite 'ylim' values
> In addition: Warning messages:
> 1: In min(x) : no non-missing arguments to min; returning Inf
> 2: In max(x) : no non-missing arguments to max; returning -Inf
> > x$Env$ylim[[4]]
> [1] -Inf  Inf
> attr(,"fixed")
> [1] FALSE
>
>
>
> > Mike
> >
> >
> > The new minimal reproducible:
> >
> > library(quantmod)
> >
> > my_plot_function <- function () {
> >  data (sample_matrix)
> >  sample.xts <- as.xts (sample_matrix[1:50,'Close'], dateFormat="POSIXct")
> >  sample.xts <- cbind (sample.xts, NA)
> >  sample.xts[50,2] <- 0
> >  colnames (sample.xts) <- c('Close', 'Stops')
> >
> >  ta <- list ("add_TA(sample.xts[,2])")
> >
> >  # In the range to be plotted ta is completely NA
> >  subset <- '2007-01-10::2007-01-30'
> >
> >  plot (chart_Series (sample.xts[,1], subset=subset, TA=ta))
> > }
> >
> > my_plot_function ()
> >
> > _______________________________________________
> > R-SIG-Finance using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > -- Subscriber-posting only. If you want to post, subscribe first.
> > -- Also note that this is not the r-help list where general R questions should go.
>
> _______________________________________________
> R-SIG-Finance using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com



More information about the R-SIG-Finance mailing list