/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <param name="riskFreeRate">Risk-free rate of return specified as a fractional value, e.g. 0.05 for 5%</param> /// <returns></returns> public static double SharpeRatio(ITimeSeries <double> portfolio, double riskFreeRate = 0) { // Check parameters if (riskFreeRate >= 1 || riskFreeRate < 0) { throw new ArgumentException("The risk-free rate should be a value between 0 and 1"); } return(Math.Round((portfolio.AnnualisedMean() - riskFreeRate) / portfolio.AnnualisedStdDev(), DecimalDigits)); }
/// <summary> /// Calculates the anualised standard deviation of the given time series /// </summary> /// <param name="timeseries">A time series of returns</param> /// <returns>Annualised standard deviation</returns> public static double AnnualisedStdDev(ITimeSeries <double> timeseries) { return(Math.Round(timeseries.AnnualisedStdDev(), DecimalDigits)); }