示例#1
0
        public ReturnResult CalculateReturn(
            CalculateReturnRequest request)
        {
            var monthRange = MonthYearRange.CreateForEndMonthAndMonthsBack(request.EndMonth, request.NumberOfMonths);

            var returnsInRange = _monthlyReturns.GetMonthsInRange(monthRange).ToArray();

            var result = new ReturnResult();

            if (returnsInRange.Any())
            {
                if (returnsInRange.WeDoNotHaveExactlyOneReturnPerMonth(monthRange))
                {
                    result.SetError("Could not find a complete / unique set of months.");
                    return(result);
                }

                result = PerformReturnCalculation(request, returnsInRange, result);
            }
            else
            {
                result.SetError("Could not find return(s) for month(s).");
            }

            return(result);
        }
示例#2
0
        private ReturnResult PerformReturnCalculation(
            CalculateReturnRequest request,
            MonthlyReturn[] returnsInRange,
            ReturnResult result)
        {
            var linkingResult = returnsInRange.PerformGeometricLiking();

            result.SetValue(linkingResult.Value, linkingResult.Calculation);

            result = AnnaulizeIfNeeded(request, result);

            return(result);
        }
示例#3
0
        private ReturnResult AnnaulizeIfNeeded(
            CalculateReturnRequest request,
            ReturnResult result)
        {
            if (request.MonthsIsMoreThanYearAndAnnualizeActionSet())
            {
                var annualizedResult = _financialMath.AnnualizeByMonth(result.Value, request.NumberOfMonths);

                result.AppendToCalculation(annualizedResult.Value, annualizedResult.Calculation);
            }

            return(result);
        }
示例#4
0
        public ReturnResult CalculateReturn(
            CalculateReturnRequest request,
            FeeType feeType)
        {
            var netSeries = GetReturnSeries(feeType);

            if (netSeries == null)
            {
                var errorMessage = string.Format("Could not find '{0}' return series.", feeType.DisplayName);

                return(ReturnResult.CreateWithError(errorMessage));
            }

            return(netSeries.CalculateReturn(request));
        }