コード例 #1
0
        /// <summary>
        /// 나머지 금액을 내림차순으로 최대한 분배
        /// </summary>
        /// <param name="before"></param>
        /// <param name="rest"></param>
        /// <returns></returns>
        private static List <ReblancingItemReq> SetByRest(List <ReblancingItemReq> before, decimal rest, RestOptionTypes restOptionType)
        {
            List <ReblancingItemReq> result = new List <ReblancingItemReq>();

            switch (restOptionType)
            {
            case RestOptionTypes.Unknown:
            case RestOptionTypes.MinRest:
            {
                // 큰 가격순 정렬
                if (before?.Any() ?? false)
                {
                    before = before.OrderByDescending(x => x.CurrentPrice).ToList();

                    foreach (ReblancingItemReq entity in before)
                    {
                        ReblancingItemReq one = new ReblancingItemReq();
                        one.Name         = entity.Name;
                        one.CurrentPrice = entity.CurrentPrice;
                        one.TargetWeight = entity.TargetWeight;

                        if (entity.CurrentPrice < rest)
                        {
                            int plusQty = (int)(rest / entity.CurrentPrice);
                            one.CurrentQty = entity.CurrentQty + plusQty;
                            rest           = rest - (entity.CurrentPrice * plusQty);
                        }
                        else
                        {
                            one.CurrentQty = entity.CurrentQty;
                        }

                        result.Add(one);
                    }
                }
            }
            break;
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// 리밸런싱
        /// </summary>
        /// <param name="before"></param>
        /// <param name="additionalMoney"></param>
        /// <returns></returns>
        private static List <ReblancingItemReq> RebalancingStockItem(List <ReblancingItemReq> before, decimal additionalMoney, RestOptionTypes restOptionType)
        {
            #region 변수 선언

            List <ReblancingItemReq> result = new List <ReblancingItemReq>();
            decimal rest = 0;
            #endregion

            #region  라메터 유효성 검사

            if (!(before?.Any() ?? false))
            {
                return(result);
            }

            #endregion

            #region 행동 정의

            // 비중 분배
            result = SetByWeight(before, additionalMoney);

            // 나머지 계산
            rest = SumPriceQty(before) + additionalMoney - SumPriceQty(result);

            // 나머지 분배
            result = SetByRest(result, rest, restOptionType);

            #endregion

            #region 결과 값 생성

            return(result);

            #endregion
        }
コード例 #3
0
        public static RebalancingRes Rebalancing(List <ReblancingItemReq> before, decimal additionalMoney, RestOptionTypes restOptionType)
        {
            #region 변수선언

            RebalancingRes           result = new RebalancingRes();
            List <ReblancingItemReq> after  = new List <ReblancingItemReq>();
            #endregion

            #region  라메터 유효성 검사
            if (!(before?.Any() ?? false))
            {
                return(result);
            }

            #endregion

            #region 행동 정의

            // 리밸런싱
            after = RebalancingStockItem(before, additionalMoney, restOptionType);

            // 잔액 계산
            result.RestAmount = SumPriceQty(before) + additionalMoney - SumPriceQty(after);

            // 변경점 계산
            result.ChangeSummary = MakeChangeSummary(before, after);

            #endregion

            #region 결과값 생성

            return(result);

            #endregion
        }