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);
        }
        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);
        }
        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);
        }
예제 #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));
        }