コード例 #1
0
        private void AddSectorTrendPanel(TrendIndex trend)
        {
            var pnl = SectorTrendPanels.AddAndReturn(new SectorTrendPanel()
            {
                Size = _defaultChartPanelSize
            });
            int      row       = (SectorTrendPanels.Count - 1) / 7;
            int      col       = (SectorTrendPanels.Count - 1) % 7;
            DateTime trendDate = dateTrendIndexDate.Value;

            pnl.LoadTrendIndex(trend, trendDate);
            pnl.Location = new System.Drawing.Point(_defaultChartPanelSize.Width * col, _defaultChartPanelSize.Height * row);
            pnlMain.Controls.Add(pnl);
        }
コード例 #2
0
        private void UpdateSectorTrendIndex(string sectorName, PriceBarSize priceBarSize)
        {
            Log(new LogMessage("IndexManager", $"Updating Trend Index [{sectorName} {priceBarSize.ToString()} {Settings.Instance.Sector_Trend_Bar_Count}]"));

            //
            // Find existing trend to update, or skip if none is found
            //
            var existingTrendIndex =
                SectorTrends.Find(x => x.IndexName == sectorName &&
                                  x.TrendPriceBarSize == priceBarSize &&
                                  x.IndexSwingpointBarCount == Settings.Instance.Sector_Trend_Bar_Count);

            TrendIndex updateIndexTrend = null;

            //
            // If the index exists, remove from local list, update, and re-add; otherwise create a new one and add
            //
            if (existingTrendIndex == null)
            {
                updateIndexTrend = CreateSectorIndex(sectorName, RefDataManager.Instance.GetAllSecurities(), priceBarSize);

                if (updateIndexTrend != null)
                {
                    SectorTrends.Add(updateIndexTrend);
                }
            }
            else
            {
                SectorTrends.Remove(existingTrendIndex);

                updateIndexTrend = UpdateSectorIndex(existingTrendIndex,
                                                     RefDataManager.Instance.GetAllSecurities().Where(x => x.Sector == sectorName).ToList());

                if (updateIndexTrend != null)
                {
                    SectorTrends.Add(updateIndexTrend);
                }
            }

            //
            // Save to database - this will overwrite an existing trend with the same identifiers
            //
            if (updateIndexTrend != null)
            {
                Database.SetTrendIndex(updateIndexTrend);
            }
        }
コード例 #3
0
        public static TrendIndex UpdateSectorIndex(TrendIndex indexToUpdate, List <Security> securities)
        {
            if (securities.Count == 0)
            {
                return(null);
            }

            var usedSecurities = securities.
                                 Where(x => x.Sector == indexToUpdate.IndexName).
                                 Where(x => x.DailyPriceBarData.Count > 0).
                                 Where(x => !x.MissingData && !x.Excluded).ToList();

            DateTime currentDate = indexToUpdate.LatestDate ??
                                   (from sec in usedSecurities select sec.GetFirstBar(indexToUpdate.TrendPriceBarSize).BarDateTime).Min();

            var priceBarSize = indexToUpdate.TrendPriceBarSize;
            var barCount     = indexToUpdate.IndexSwingpointBarCount;

            foreach (Security security in usedSecurities)
            {
                security.SetSwingPointsAndTrends(barCount, priceBarSize);
            }

            while (currentDate <= LatestDate(usedSecurities, priceBarSize))
            {
                TrendIndexDay indexDay = indexToUpdate.GetIndexDay(currentDate, true);

                var dailySecurityList = ApplyDefaultAsOfFilters(usedSecurities, currentDate);
                if (dailySecurityList.Count() > 0)
                {
                    foreach (TrendQualification trend in Enum.GetValues(typeof(TrendQualification)))
                    {
                        if (trend == TrendQualification.NotSet)
                        {
                            continue;
                        }

                        var totalTrending = dailySecurityList.Where(x => x.GetPriceBar(currentDate, priceBarSize).GetTrendType(barCount) == trend).Count();
                        indexDay.AddTrendEntry(trend, totalTrending.ToDecimal() / dailySecurityList.Count().ToDecimal());
                    }
                }

                switch (priceBarSize)
                {
                case PriceBarSize.Daily:
                    currentDate = NextTradingDay(currentDate);
                    break;

                case PriceBarSize.Weekly:
                    currentDate = NextTradingWeekStart(currentDate);
                    break;

                case PriceBarSize.Monthly:
                    currentDate = NextTradingMonthStart(currentDate);
                    break;

                case PriceBarSize.Quarterly:
                    currentDate = NextTradingQuarterStart(currentDate);
                    break;
                }
            }

            return(indexToUpdate);
        }