# NOT RUN {
# Realized semi-variance/semi-covariance for prices aligned
# at 5 minutes.
data(sampleTData)
data(sample5MinPricesJumps)
# Univariate:
rSV = rSemiCov(rData = sampleTData$PRICE, alignBy = "minutes",
alignPeriod = 5, makeReturns = TRUE)
# Multivariate single day:
rSC = rSemiCov(rData = sample5MinPricesJumps['2010-01-04'], makeReturns=TRUE)
# }
# NOT RUN {
# Multivariate multi day:
rSC <- rSemiCov(sample5MinPrices, makeReturns = TRUE) # rSC is a list of lists
# We extract the covariance between stock 1 and stock 2 for all three covariances.
mixed <- do.call(rbind, lapply(rSC, function(x) x[["mixed"]][1,2]))
neg <- do.call(rbind, lapply(rSC, function(x) x[["negative"]][1,2]))
pos <- do.call(rbind, lapply(rSC, function(x) x[["positive"]][1,2]))
covariances <- xts(cbind(mixed, neg, pos), as.Date(rownames(pos)))
colnames(covariances) <- c("mixed", "neg", "pos")
# We make a quick plot of the different covariances
plot(covariances)
addLegend(lty = 1) # Add legend so we can distinguish the series.
# }
Run the code above in your browser using DataLab