[R-SIG-Finance] yahooSeries - how to access the date field?
Jeff Ryan
jeff.a.ryan at gmail.com
Mon Jul 7 03:40:58 CEST 2008
An alternate method that offers a bit of simplicity for plotting -- as
well as the use of true time-indexing:
library(quantmod)
getSymbols("^NDX;UYG", from='2006-01-01')
# will load 2 objects - NDX and UYG into your environment
# then you can plot any component by selecting the column, or
alternately the whole OHLCV series:
plot(NDX) #plots the Open, and a warning :)
plot(as.zoo(NDX)) # plots O,H,L,C,V
plot(Cl(UYG)) # plots the Close
# or
barChart(NDX)
candleChart(UYG)
See http://www.quantmod.com/examples for some additional quantmod
tools that may be of use.
HTH
Jeff
On Sun, Jul 6, 2008 at 7:51 PM, bina <binabina at bellsouth.net> wrote:
> hello, extracting data sets from the yahooSeries function, see below. I
> return a data frame successfully, however how do i access the date
> field. When viewing the structure i don't see the field, but using head
> i do see the date field.
>
> Can someone provide me some example plot code to plot the data in a time
> series format, with the dates going across the X axis labels?
> -zubin
>
>
>
> zdata <- yahooSeries(symbols = c("^NDX","UYG"), from = '2006-01-01',
> to = '2008-07-06', quote = c("Open", "High", "Low", "Close",
> "Volume"), aggregation = c("d"), returnClass = c("data.frame"))
>
> str(zdata)
> 'data.frame': 653 obs. of 10 variables:
> $ X.NDX.Open : num 1654 1684 1698 1718 1734 ...
> $ X.NDX.High : num 1687 1697 1708 1736 1745 ...
> $ X.NDX.Low : num 1634 1682 1697 1711 1730 ...
> $ X.NDX.Close : num 1680 1696 1705 1735 1742 ...
> $ X.NDX.Volume: num 2.00e+09 1.88e+09 1.89e+09 2.23e+09 1.95e+09 ...
> $ UYG.Open : num NA NA NA NA NA NA NA NA NA NA ...
> $ UYG.High : num NA NA NA NA NA NA NA NA NA NA ...
> $ UYG.Low : num NA NA NA NA NA NA NA NA NA NA ...
> $ UYG.Close : num NA NA NA NA NA NA NA NA NA NA ...
> $ UYG.Volume : num NA NA NA NA NA NA NA NA NA NA ...
>
> head(zdata)
> X.NDX.Open X.NDX.High X.NDX.Low
> 2006-01-03 1654.39 1686.59 1633.62
> 2006-01-04 1684.05 1696.83 1681.85
> 2006-01-05 1697.80 1707.71 1697.33
> 2006-01-06 1718.17 1735.50 1710.86
> 2006-01-09 1734.50 1745.12 1729.60
> 2006-01-10 1732.25 1744.47 1730.25
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> 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.
>
--
Jeffrey Ryan
jeffrey.ryan at insightalgo.com
ia: insight algorithmics
www.insightalgo.com
More information about the R-SIG-Finance
mailing list