Description Usage Arguments Value Examples
Calculates the returns from a prices dataset.
1 |
prices |
a numerical vector or an nxp data matrix with stock prices. |
type |
a character vector, indicating which type of returns are to be calculated. type="d" calculates the discrete returns (default) and type="c" calculates the continuous returns. |
a numerical vector or an (n-1)xp data matrix with returns.
1 2 3 4 5 6 7 8 9 10 11 12 | data(sp500)
sp500[,1] <- as.Date(sp500[,1],format="%d.%m.%Y",stringsAsFactors=FALSE)
sp500 <- sp500[,-which(substr(colnames(sp500),1,7)=="X.ERROR")]
NYSE_hol <- as.Date(timeDate::holidayNYSE(as.numeric(unique(format(sp500[,1],format="%Y")))))
no_trades <- sort(c(NYSE_hol, as.Date(c("2001-09-11","2001-09-12","2001-09-13","2001-09-14"),
format="%Y-%m-%d")))
sp500 <- sp500[-match(no_trades,sp500[,1]),]
nonas <- which(apply(is.na(sp500[,-1]),2,sum)==0)
sp500 <- sp500[,c(1, nonas+1)]
repindex <- find_repval(sp500[,-1])
sp500_prices <- sp500[,-c(1, repindex+1)]
sp500_ret <- rets_calc(sp500_prices)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.