Skip to content

Instantly share code, notes, and snippets.

@brunosaboia
Created October 1, 2015 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunosaboia/90bb106e5382398729f5 to your computer and use it in GitHub Desktop.
Save brunosaboia/90bb106e5382398729f5 to your computer and use it in GitHub Desktop.
A function to remove the RF from the Stocks
remove_risk_free <- function(stocks, risk_free, rf_col_name) {
if(class(risk_free) != class(timeSeries()) || class(stocks) != class(timeSeries())) {
stop("The two first parameters must be timeSeries objects")
}
if(nrow(risk_free) != nrow(stocks)) {
stop("The two time series must be from the same size")
}
ret <- stocks[,1]
ret <- ret[,-1]
for(col in colnames(stocks)) {
ret <- merge(stocks[,col] - risk_free[,rf_col_name], ret)
}
return(ret)
}
### END FUNCTIONS ###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment