Esempio n. 1
0
        public static double GetSharpeRatio(IEnumerable <double> data)
        {
            double result = double.NaN;

            if (data.Any())
            {
                var returns = data.Take(data.Count() - 1).Zip(data.Skip(1), (oldValue, newValue) => (newValue - oldValue) / oldValue * 100);

                if (returns.Any())
                {
                    var returnsStd = StdCalculator.GetStd(returns, true);

                    result = returns.Average() / returnsStd;
                }
            }

            return(result);
        }
        public static double GetSortinoRatio(IEnumerable <double> data)
        {
            double result = double.NaN;

            if (data.Any())
            {
                var returns = data.Take(data.Count() - 1).Zip(data.Skip(1), (oldValue, newValue) => (newValue - oldValue) / oldValue * 100);

                var negativeReturns = returns.Where(iReturn => iReturn < 0);

                if (negativeReturns.Any())
                {
                    var negativeReturnsStd = StdCalculator.GetStd(negativeReturns, true);

                    result = returns.Average() / negativeReturnsStd;
                }
            }

            return(result);
        }