## data -
# Microsoft Data:
setRmetricsOptions(myFinCenter = "GMT")
MSFT = as.timeSeries(data(msft.dat))
head(MSFT)
## timeSeries -
# Create a timeSeries Objec - The Direct Way ...
Close = MSFT[, 5]
head(Close)
# From Scratch ...
data = as.matrix(MSFT[, 4])
charvec = rownames(MSFT)
Close = timeSeries(data, charvec, units = "Close")
head(Close)
c(start(Close), end(Close))
## window -
# Cut out April Data from 2001:
tsApril01 = window(Close, "2001-04-01", "2001-04-30")
tsApril01
## returns -
# Continuous Returns:
returns(tsApril01)
# Discrete Returns:
returns(tsApril01, type = "discrete")
# Don't trim:
returns(tsApril01, trim = FALSE)
# Use Percentage Values:
tsRet = returns(tsApril01, percentage = TRUE, trim = FALSE)
tsRet
## applySeries -
# Aggregate weekly:
GoodFriday(2001)
to = timeSequence(from = "2001-04-11", length.out = 3, by = "week")
from = to - 6*24*3600
from
to
applySeries(tsRet, from, to, FUN = sum)
Run the code above in your browser using DataLab