FWIW, I misread the docs for getSymbols.yahoo which says

     In the case of xts objects, the indexing will be by Date. This can
     be altered with the ‘index.class’ argument.  See ‘indexClass’ for
     more information on changing index classes.

So, this should be perfectly acceptable as well:

medata <- getSymbols("^GSPC",
        from=Sys.Date()-400,
        index.class='POSIXct',
        auto.assign=FALSE)
opens <- Op(medata)
closes <- Cl(medata)
index(opens) <- index(opens) + (60*60*8) + (60*30)
index(closes) <- index(closes) + (60*60*15)
newdata <- rbind(opens,closes)
colnames(newdata) <- "GSPC.OC"
> tail(newdata)

                    GSPC.OC
2011-09-20 08:30:00 1204.50
2011-09-20 15:00:00 1202.09
2011-09-21 08:30:00 1203.63
2011-09-21 15:00:00 1166.76
2011-09-22 08:30:00 1164.55
2011-09-22 15:00:00 1129.56


On Fri, Sep 23, 2011 at 8:25 AM, G See <gsee000@gmail.com> wrote:

> Hi Costas,
>
> You need an indexClass that can handle times.  By default getSymbols.yahoo
> gives you an object with 'Date' indexClass which you need to change to
> something like 'POSIXct' or 'POSIXlt'
>
> (You *can* do this directly in your getSymbols call using the argument
> index.class='POSIXct', but the documentation says only "Date" is supported,
> so I'll do it the other way)
>
> require(quantmod)
> getSymbols("^GSPC",from='1990-01-01')
> medata <- tail(GSPC, 400)
> indexClass(medata) <- "POSIXct"
> opens <- Op(medata)
> closes <- Cl(medata)
> index(opens) <- index(opens) + (60*60*8) + (60*30)
> index(closes) <- index(closes) + (60*60*15)
> newdata <- rbind(opens,closes)
> colnames(newdata) <- "GSPC.OC"
> > tail(newdata)
>                     GSPC.OC
> 2011-09-20 08:30:00 1204.50
> 2011-09-20 15:00:00 1202.09
> 2011-09-21 08:30:00 1203.63
> 2011-09-21 15:00:00 1166.76
> 2011-09-22 08:30:00 1164.55
> 2011-09-22 15:00:00 1129.56
>
> Regards,
> Garrett
>
> On Fri, Sep 23, 2011 at 4: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]]

