An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20080706/a4721526/attachment.pl>
yahooSeries - how to access the date field?
3 messages · zubin, Moshe Olshansky, Jeff Ryan
Try rownames(zdata)
--- On Mon, 7/7/08, bina <binabina at bellsouth.net> wrote:
From: bina <binabina at bellsouth.net>
Subject: [R-SIG-Finance] yahooSeries - how to access the date field?
To: r-sig-finance at stat.math.ethz.ch
Received: Monday, 7 July, 2008, 10:51 AM
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.
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