Created
October 1, 2015 13:38
-
-
Save brunosaboia/90bb106e5382398729f5 to your computer and use it in GitHub Desktop.
A function to remove the RF from the Stocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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