public static float RealRateOfReturn <TSource>(this IEnumerable <TSource> source, Func <TSource, float> nominalRateOfReturnSelector, Func <TSource, float> inflationRateSelector) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (nominalRateOfReturnSelector == null) { throw new ArgumentNullException(nameof(nominalRateOfReturnSelector)); } if (inflationRateSelector == null) { throw new ArgumentNullException(nameof(inflationRateSelector)); } checked { var nominalRateOfReturn = source.AccumulateCompoundInterest(nominalRateOfReturnSelector); var inflationRate = source.AccumulateCompoundInterest(inflationRateSelector); return(nominalRateOfReturn.RealRateOfReturn(inflationRate)); } }
public static double SharpeRatio <TSource>(this IEnumerable <TSource> source, Func <TSource, double> portfolioReturnSelector, Func <TSource, double> riskFreeRateSelector) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (portfolioReturnSelector == null) { throw new ArgumentNullException(nameof(portfolioReturnSelector)); } if (riskFreeRateSelector == null) { throw new ArgumentNullException(nameof(riskFreeRateSelector)); } checked { var portfolioReturn = source.AccumulateCompoundInterest(portfolioReturnSelector) / 100; var riskFreeRate = source.AccumulateCompoundInterest(riskFreeRateSelector) / 100; var standardDeviation = source.StandardDeviation(portfolioReturnSelector); return(portfolioReturn.SharpeRatio(riskFreeRate, standardDeviation)); } }