예제 #1
0
        private (decimal?NInSystem, decimal?highestPriceInSystem, decimal?lowestPriceInSystem) DailyPriceCalculationSystem(BuySellStrategyType type, IReadOnlyList <IStockPriceHistory> recentStockPriceHistory, decimal todayATR, IStockQuoteFromDataSource todayPriceDataFromDataSource)
        {
            decimal[]  lowPrices    = null;
            decimal[]  highPrices   = null;
            decimal?[] ATRs         = null;
            decimal?   lowestPrice  = null;
            decimal?   highestPrice = null;
            decimal?   todayN       = null;

            if (recentStockPriceHistory.Count >= type.GetSellIntValue())
            {
                lowPrices = recentStockPriceHistory.Take(type.GetSellIntValue()).Select(a => a.LowPrice).ToArray();
                ATRs      = recentStockPriceHistory.Take(type.GetSellIntValue() - 1).Select(a => a.ATR).ToArray();
            }
            if (recentStockPriceHistory.Count() >= type.GetBuyIntValue())
            {
                highPrices = recentStockPriceHistory.Take(type.GetBuyIntValue()).Select(a => a.HighPrice).ToArray();
                ATRs       = recentStockPriceHistory.Take(type.GetBuyIntValue() - 1).Select(a => a.ATR).ToArray();
            }

            if (lowPrices != null)
            {
                lowestPrice = _baseData.CalculateLowestPrice(lowPrices, todayPriceDataFromDataSource.LowPrice);
            }

            if (highPrices != null)
            {
                highestPrice = _baseData.CalculateHighestPrice(highPrices, todayPriceDataFromDataSource.HighPrice);
            }

            if (ATRs != null)
            {
                List <decimal> validATRList = new List <decimal>();

                foreach (decimal?item in ATRs)
                {
                    if (item.HasValue)
                    {
                        validATRList.Add(item.Value);
                    }
                }

                if (validATRList.Count() == type.GetBuyIntValue() - 1)
                {
                    todayN = _baseData.CalculateTodayN(validATRList.ToArray(), todayATR);
                }
            }

            return(todayN, highestPrice, lowestPrice);
        }