[R-SIG-Finance] quantmod newTA passes a matrix?

Brian Lee Yung Rowe brian at muxspace.com
Wed Dec 10 05:11:53 CET 2008


preFUN worked as advertised. Thanks.


On Tue, 2008-12-09 at 09:26 -0600, Jeff Ryan wrote:
> Brian,
> 
> The reason is mostly historical (pre-xts code)
> 
> > head(myIndicator)
> 
> 1 function (..., on = -1, legend = "auto")
> 2 {
> 3     lchob <- quantmod:::get.current.chob()
> 4     x <- as.matrix(lchob at xdata)
> 5     x <- dummy.indicator(x = x)
> 6     yrange <- NULL
> 
> If you need an xts object, you can hand edit the function produced by
> newTA (either dump() and source(), or fix()) or you can add a preFUN
> argument in the newTA call.
> 
> > myIndicator <- newTA(dummy.indicator, preFUN=as.xts, on=-1, col='#3333333', border=NA)
> > head(myIndicator)
> 
> 1 function (..., on = -1, legend = "auto")
> 2 {
> 3     lchob <- quantmod:::get.current.chob()
> 4     x <- as.matrix(lchob at xdata)
> 5     x <- as.xts(x)
> 6     x <- dummy.indicator(x = x)
> 
> The data is indeed stored as an xts object internally in the 'chob'.
> 
> > str(quantmod:::get.current.chob()@xdata)
> An 'xts' object from 2007-01-03 to 2008-12-08 containing:
>   Data: num [1:488, 1:6] 43.5 43.3 44 43.9 44 ...
>  - attr(*, "dimnames")=List of 2
>   ..$ : NULL
>   ..$ : chr [1:6] "QQQQ.Open" "QQQQ.High" "QQQQ.Low" "QQQQ.Close" ...
>   Indexed by objects of class: [POSIXct]
>    xts Attributes:
> List of 3
>  $ src     : chr "yahoo"
>  $ updated : POSIXct[1:1], format: "2008-12-09 15:24:20"
>  $ .RECLASS: logi FALSE
> 
> Jeff
> 
> On Tue, Dec 9, 2008 at 5:30 AM, Brian Lee Yung Rowe <brian at muxspace.com> wrote:
> > Hi Jeff,
> >
> > This is what I am talking about:
> >
> > dummy.indicator <- function(x) cat("input class:",class(x),"\n")
> > myIndicator <- newTA(dummy.indicator, on=-1, col='#3333333', border=NA)
> >
> >> chartSeries(QQQQ)
> >> myIndicator()
> > input class: matrix
> >
> > I wasn't expecting to see the input (extracted from the chob) as matrix
> > (I thought it would be xts/zoo).
> >
> > Brian
> >
> >
> > On Sat, 2008-12-06 at 11:34 -0600, Jeff Ryan wrote:
> >> Hi Brian,
> >>
> >> There are quite a few operations that take place internal to the
> >> chartSeries plotting process.
> >>
> >> If you mean that your function that is creating the data isn't
> >> returning an xts object, I would say that you should do one of two
> >> things:
> >>
> >> 1) write a wrapper that returns it as an xts object, either by
> >> reconstructing the xts object from the data, or by trying the Reclass
> >> function in xts.  Reclass is theory will do exactly what I think you
> >> need, but it can't always guess correctly. Use THIS function as the
> >> FUN argument to ?newTA.
> >>
> >> 2) using ?fix you can simply modify/fine-tune the function object you
> >> get/have from newTA to modify the results.
> >>
> >> If you could send your code off-list (if need be) or on list, I can help more.
> >>
> >> Thanks,
> >> Jeff
> >>
> >> On Sat, Dec 6, 2008 at 7:51 AM, Brian Lee Yung Rowe <brian at muxspace.com> wrote:
> >> > Hi Brian,
> >> >
> >> > Are you referring to the addTA function that takes a boolean xts object?
> >> > Yes, that works fine, but I want my own function that wraps up some of the
> >> > details in drawing the shaded regions. Jeff and I spoke about using newTA to
> >> > do this, and I'm trying to work through some of the specifics.
> >> >
> >> > FWIW I already have a working function based on newTA, but I have to pass in
> >> > the original time series as an option because the series extracted from the
> >> > chob does not preserve the date information. It's a minor inconvenience, and
> >> > I wanted to know if there was a more elegant solution to the problem.
> >> >
> >> > Brian
> >> >
> >> >
> >> > ----- Original message -----
> >> > Sent: 2008/12/06 06:58:37
> >> > Subject: Re:Re: [R-SIG-Finance] quantmod newTA passes a matrix?
> >> >
> >> > I'm not at a machine where I can easily look up the function, but quantmod
> >> > already has a function for adding shaded sections to charts that takes a
> >> > vector of date ranges as the argument. Check the chart documentation and
> >> > Jeff's excellent examples on quantmod.com
> >> >
> >> > Regards,
> >> >
> >> > - Brian
> >> >
> >> > Brian Lee Yung Rowe wrote:
> >> >
> >> >>_______________________________________________
> >> >>R-SIG-Finance at stat.math.ethz.ch mailing list
> >> >>https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> >> >>-- Subscriber-posting only.
> >> > _______________________________________________
> >> > R-SIG-Finance at stat.math.ethz.ch mailing list
> >> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> >> > -- Subscriber-posting only.
> >> > -- If you want to post, subscribe first.
> >> >
> >>
> >>
> >>
> >
> >
> 
> 
>



More information about the R-SIG-Finance mailing list