powered by
Calculates Sharpe ratio from vector of gains or prices. The formula is: (mean(gains) - rf) / sd(gains), where rf is some risk-free rate of return.
(mean(gains) - rf) / sd(gains)
rf
sharpe(gains = NULL, prices = NULL, rf = 0)
Numeric matrix with 1 column of gains for each investment (can be a vector if there is only one).
Numeric matrix with 1 column of prices for each investment (can be a vector if there is only one).
Numeric value.
# NOT RUN { # Simulate daily gains over a 5-year period set.seed(123) stock.gains <- rnorm(252 * 5, 0.0005, 0.01) # Calculate Sharpe ratio using risk-free return of 0 sharpe(stock.gains) # }
Run the code above in your browser using DataLab