Hi there,
Using a quantmod function, I calculate the daily change between two points
in a time series. However, I don't think I am using the data correctly.
Code:
getSymbols("^GSPC", src="yahoo")
CloseData <- Cl(GSPC)
Delta <- diff(CloseData, lag=1)
for (i in 3:length(Delta)) {
if (Delta[i]>Del
On Aug 3, 2009, at 10:48 AM, ehxpieterse wrote:
Using a quantmod function, I calculate the daily change between two
points
in a time series. However, I don't think I am using the data
correctly.
Code:
getSymbols("^GSPC", src="yahoo")
CloseData <- Cl(GSPC)
Delta <- diff(CloseData, lag=1)
for
It's because Delta isn't a number. Or, more accurately, Delta[1] and
Delta[i-1] are not numbers. The are objects that have a class, and
therefore an internal structure:
class(Delta[1])
[1] "xts" "zoo"
To understand what's going on, you need to understand the structure
of these classes, an
Something like this should work:
tmp <- as.Numeric(Delta)
tmp3 <- tmp[ -c(1,2)] ## elements 3 through
last (the "i" in the loop)
tmp2 <- tmp[ -c(1,length(tmp)) ] ## elements 2 through next
to last (the "i-1" in the loop)
mysum <- sum( tmp3[tmp3 > tmp2]) ##
4 matches
Mail list logo