当前位置: 首页>>代码示例>>C#>>正文


C# SortedList.FirstOrDefault方法代码示例

本文整理汇总了C#中SortedList.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.FirstOrDefault方法的具体用法?C# SortedList.FirstOrDefault怎么用?C# SortedList.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedList的用法示例。


在下文中一共展示了SortedList.FirstOrDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessNumbers

        static void ProcessNumbers(SortedList<Int64, Operator> numbers, int numIndex, int resultIndex, FileInfo fileInfoIn)
        {
            using (var package = new ExcelPackage(fileInfoIn))
            {
                ExcelWorkbook workBook = package.Workbook;
                if (workBook != null)
                {
                    if (workBook.Worksheets.Count > 0)
                    {
                        ExcelWorksheet currentWorksheet = workBook.Worksheets.First();

                        for (int i = 2; i <= currentWorksheet.Cells.Rows && currentWorksheet.Cells[i, numIndex].Value != null; i++)
                        {
                            Int64 inNumber;
                            if (Int64.TryParse(currentWorksheet.Cells[i, numIndex].Value.ToString(), out inNumber))
                            {
                                inNumber = inNumber % 10000000000; //сокращаем до 10 цифр

                                var oper = numbers.FirstOrDefault(k => k.Value.From <= inNumber && k.Value.To >= inNumber);
                                if (oper.Value != null)
                                {
                                    currentWorksheet.Cells[i, resultIndex].Value = oper.Value.Name;
                                    currentWorksheet.Cells[i, resultIndex + 1].Value = oper.Value.Region;
                                }
                            }
                        }
                    }
                }
                package.Save();
            }
        }
开发者ID:wonderu,项目名称:telecomparser,代码行数:31,代码来源:Program.cs

示例2: Subscribe

        public override void Subscribe(string[] epics, IHandyTableListener tableListener)
        {
            Dictionary<string, List<CqlQuote>> priceData = GetReplayData(epics);
            if (priceData.Count == 0)
                return;

            Calendar dayCalendar = new Calendar(priceData.First().Value[0].t);

            foreach(var epic in epics){
                // for each quote, associate the observed gains in the near future
                var mktData = new MarketData(epic);
                var wmaLow = new IndicatorEMA(mktData, 2);
                var wmaMid = new IndicatorEMA(mktData, 10);
                var wmaHigh = new IndicatorEMA(mktData, 30);
                var wmaVeryHigh = new IndicatorEMA(mktData, 90);
                var rsiShort = new IndicatorRSI(mktData, 1, 14);
                var rsiLong = new IndicatorRSI(mktData, 2, 14);
                var trendShort = new IndicatorTrend(mktData, 90, 14, false);
                var trendLong = new IndicatorTrend(mktData, 180, 14, false);
                var wmvolLow = new IndicatorWMVol(mktData, wmaLow, 60, 90);
                var wmvolHigh = new IndicatorWMVol(mktData, wmaMid, 60, 90);
                var volTrendLow = new IndicatorTrend(wmvolLow, 30, 6, true);
                var volTrendHigh = new IndicatorTrend(wmvolHigh, 60, 6, true);
                var allIndicators = new List<IndicatorWMA>();
                allIndicators.Add(wmaLow);
                allIndicators.Add(wmaMid);
                allIndicators.Add(wmaHigh);
                allIndicators.Add(wmaVeryHigh);
                allIndicators.Add(rsiShort);
                allIndicators.Add(rsiLong);
                allIndicators.Add(trendShort);
                allIndicators.Add(trendLong);
                allIndicators.Add(wmvolLow);
                allIndicators.Add(wmvolHigh);
                allIndicators.Add(volTrendLow);
                allIndicators.Add(volTrendHigh);

                foreach (var quote in priceData[epic])
                {
                    var mktDataValue = new Price(quote.MidPrice());
                    mktData.Process(quote.t, mktDataValue);
                    foreach (var ind in allIndicators)
                        ind.Process(quote.t, mktDataValue);
                }

                var expectations = new Dictionary<DateTime, KeyValuePair<CqlQuote, decimal>>();
                var gainDistribution = new SortedList<int, DateTime>();
                KeyValuePair<int, DateTime> minProfit = new KeyValuePair<int, DateTime>(1000000, DateTime.MinValue);
                KeyValuePair<int, DateTime> maxProfit = new KeyValuePair<int, DateTime>(-1000000, DateTime.MinValue);
                var rnd = new Random(155);
                var tradingStart = Config.ParseDateTimeLocal(Config.Settings["TRADING_START_TIME"]);
                var tradingStop = Config.ParseDateTimeLocal(Config.Settings["TRADING_STOP_TIME"]);
                var wmaVeryHighStart = wmaVeryHigh.Average(tradingStart);
                var amplitude = 100.0m;
                foreach (var quote in priceData[epic])
                {
                    if (quote.t.TimeOfDay < tradingStart.TimeOfDay || quote.t.TimeOfDay > tradingStop.TimeOfDay)
                        continue;
                    string evtName = "";
                    if (dayCalendar.IsNearEvent(mktData.Name, quote.t, ref evtName))
                        continue;
                    var futureVal = (mktData.TimeSeries.Max(quote.t.AddMinutes(5), quote.t.AddMinutes(20)) +
                        mktData.TimeSeries.Min(quote.t.AddMinutes(5), quote.t.AddMinutes(20))) / 2m;
                    var profit = (int)Math.Round(futureVal - quote.MidPrice());
                    expectations.Add(quote.t, new KeyValuePair<CqlQuote, decimal>(quote, profit));
                    if (gainDistribution.ContainsKey(profit))
                    {
                        if ((quote.t - gainDistribution[profit]).Hours > 3 && (rnd.Next(100) == 0))
                            gainDistribution[profit] = quote.t;
                    }
                    else
                        gainDistribution[profit] = quote.t;
                    if (profit < minProfit.Key)
                        minProfit = new KeyValuePair<int, DateTime>(profit, gainDistribution[profit]);
                    if (profit > maxProfit.Key)
                        maxProfit = new KeyValuePair<int, DateTime>(profit, gainDistribution[profit]);
                    quote.b = (quote.b - wmaVeryHighStart.Bid) / amplitude;
                    quote.o = (quote.o - wmaVeryHighStart.Offer) / amplitude;
                }
                gainDistribution = new SortedList<int,DateTime>((from elt in gainDistribution
                                                                 where !isTooClose(elt, gainDistribution)
                                                                 select elt).ToDictionary(keyVal => keyVal.Key, keyVal => keyVal.Value));
                int nbPoints = 10;
                int idxProfit = 0;
                KeyValuePair<int, DateTime> nextProfit = minProfit;
                var selection = new SortedList<DateTime, KeyValuePair<int, CqlQuote>>();
                while (idxProfit++ < nbPoints)
                {
                    selection.Add(gainDistribution[nextProfit.Key], new KeyValuePair<int, CqlQuote>(nextProfit.Key, expectations[gainDistribution[nextProfit.Key]].Key));
                    var nextKeyVal = gainDistribution.FirstOrDefault(keyVal => keyVal.Key > nextProfit.Key &&
                        keyVal.Key >= ((decimal)minProfit.Key + (decimal)idxProfit * (decimal)(maxProfit.Key - minProfit.Key) / (decimal)nbPoints));
                    if (nextKeyVal.Equals(default(KeyValuePair<int, DateTime>)))
                        break;
                    nextProfit = nextKeyVal;
                }
                foreach (var dt in selection.Keys)
                {
                    bool allValid = true;
                    foreach (var ind in allIndicators)
                    {
//.........这里部分代码省略.........
开发者ID:JBetser,项目名称:MiDax,代码行数:101,代码来源:MarketSelector.cs


注:本文中的SortedList.FirstOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。