There's no automatic function for this sort of request that I know of, but
it shouldn't be hard to write one:

require(quantmod)
getSymbols('^GSPC',from='1990-01-01')

CollapseOpCl <- function(P){
    stopifnot(all(has.Op(P),has.Cl(P)))
    O <- Op(P); time(O) <- as.POSIXlt(time(O)); time(O)$hour <- 9;
time(O)$min <- 30
    C <- Cl(P); time(C) <- as.POSIXlt(time(C)); time(C)$hour <- 16;
time(C)$min <- 00
    ans <- rbind(O,C);
    names(ans) <- unlist(strsplit(names(O),"\\."))[1]
    ans
}
plot(Out <- CollapseOpCl(GSPC))

It's a little brute force, but it seems to work. More generally, if you just
use rbind(Op(P),Cl(P)) you can get an xts with non-unique time stamps, but
you loose some info that way.

Hope this helps,

Michael

On Fri, Sep 23, 2011 at 5:50 AM, Costas Vorlow <costas.vorlow@gmail.com>wrote:

> Hello,
>
> I want to put in order (preferably as a zoo or xts object with a suitable
> timestamp)
> the open anc closing prices of an (say) index downloaded from YAHOO
> finance:
>
> require(quantmod)
> getSymbols('^GSPC',from='1990-**01-01')
>
> medata<- tail((GSPC),400)
> opens<-Op(medata)
> closes<-Cl(medata)
>
> i.e., I want  asingle sequence of  1095.89,    1105.24 , 1101.24 ,
> 1102.94, and so on ... preferably with a timestamp (morning - evening of
> same day as for daily prices zoo does not like the same date in two
> consecutive prices...
>
> > head(merge(opens,closes))
>           GSPC.Open GSPC.Close
> 2010-02-24   1095.89    1105.24
> 2010-02-25   1101.24    1102.94
> 2010-02-26   1103.10    1104.49
> 2010-03-01   1105.36    1115.71
> 2010-03-02   1117.01    1118.31
> 2010-03-03   1119.36    1118.79
> >
> >
> Probably I could use the OpCl in quantmod and caclulate the Cl price from
> Op, though Is there any easy way using some implicit zoo/xts function for
> this? I have problems in puting the timestamps in the xts vobject.
>
> Thanks,
> Costas
>
> ______________________________**_________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-sig-finance<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.
>

	[[alternative HTML version deleted]]

