Suppose I want to calculate the Sharpe ratio given a risk free rate of 0.05 for a portfolio consisting of assets from 500 ETFs. How can I do so in R given the data I've collected thus far in my R code? The following is a part of my code:

#To extract ETF-prices for each column
prices <- data.frame(ETF=ETF,row.names = dates) 
# Function for calculating continous returns & log returns
returnscalc <- function(x){
returns <- apply(prices, 2, returnscalc)
# Function for calculating geometric mean
geomAveCalc <- function(x){

weeklymean <- apply(returns, 2, geomAveCalc)
yearlymean <- matrix((1+weeklymean)^52-1)
yearlystd <-  sqrt (52 * apply(returns, 2, var))
yearlycov <- 52 * cov(returns)

where ETF is the data extracted from the .csv file containing the ETFs data.

Some help will be deeply appreciated.


1 Answer 1



SharpeRatio.annualized(Returns, Rf = 0.05, scale = 252, geometric = TRUE)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.