예제 #1
0
        /// <summary>
        /// Calculate
        /// </summary>
        /// <returns></returns>
        public virtual double Calculate()
        {
            var input  = Values.FirstOrDefault();
            var output = Values.LastOrDefault();

            if (input == null || output == null)
            {
                return(0.0);
            }

            var cagr = new CAGR
            {
                Values = Values
            };

            var values            = Values.Select((o, i) => o.Value - Values.ElementAtOrDefault(i - 1)?.Value ?? 0.0);
            var excessGain        = cagr.Calculate() - InterestRate;
            var days              = output.Time.Subtract(input.Time).Duration().Days + 1.0;
            var downsideDeviation = values.DownsideDeviation(0);
            var annualDeviation   = (double.IsNaN(downsideDeviation) ? 0.0 : downsideDeviation) * Math.Sqrt(days);

            if (annualDeviation == 0)
            {
                return(0.0);
            }

            return(excessGain / annualDeviation);
        }
예제 #2
0
        /// <summary>
        /// Calculate
        /// </summary>
        /// <returns></returns>
        public virtual double Calculate()
        {
            var cagr = new CAGR
            {
                Values = Values
            };

            var maxLoss = 0.0;
            var count   = Values.Count();

            if (count == 0)
            {
                return(0.0);
            }

            for (var i = 1; i < count; i++)
            {
                var currentValue  = Values.ElementAtOrDefault(i)?.Value ?? 0;
                var previousValue = Values.ElementAtOrDefault(i - 1)?.Value ?? 0;

                if (previousValue > currentValue)
                {
                    maxLoss = Math.Max(maxLoss, previousValue - currentValue);
                }
            }

            if (maxLoss == 0)
            {
                return(0.0);
            }

            return(cagr.Calculate() / maxLoss);
        }
예제 #3
0
        /// <summary>
        /// Calculate
        /// </summary>
        /// <returns></returns>
        public virtual double Calculate()
        {
            var cagr = new CAGR
            {
                Values = Values
            };

            var count  = Values.Count();
            var losses = new List <double>();

            if (count == 0)
            {
                return(0.0);
            }

            for (var i = 1; i < count; i++)
            {
                var currentValue  = Values.ElementAtOrDefault(i)?.Value ?? 0;
                var previousValue = Values.ElementAtOrDefault(i - 1)?.Value ?? 0;

                if (previousValue > currentValue)
                {
                    losses.Add(Math.Pow(previousValue - currentValue, 2));
                }
            }

            var averageLoss = losses.Any() ? losses.Average() : 1.0;

            return((cagr.Calculate() - InterestRate.Value) / Math.Sqrt(averageLoss));
        }
예제 #4
0
        /// <summary>
        /// Calculate
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        public virtual double CalculateCompoundRatio(int?option = 0)
        {
            var input  = Values.FirstOrDefault();
            var output = Values.LastOrDefault();

            if (input == null || output == null)
            {
                return(0.0);
            }

            var score = new CAGR
            {
                Values = Values
            };

            var excessGain = score.Calculate() - InterestRate;
            var days       = output.Time.Subtract(input.Time).Duration().Days + 1;
            var deviation  = Values.Select(o => o.Value).StandardDeviation() * Math.Sqrt(days);

            if (deviation == 0)
            {
                return(0.0);
            }

            return(excessGain / deviation);
        }