Example #1
0
 public static String ToXDesc(ChartXUnit xUnit, int startDate, int endDate)
 {
     if (xUnit == ChartXUnit.CXU_Year)
     {
         return(String.Format("{0}", Utils.Year(startDate)));
     }
     else
     {
         return(String.Format("{0}-{1}", startDate.ToString().Substring(2), endDate.ToString().Substring(2)));
     }
 }
Example #2
0
        public static int ToDayCount(ChartXUnit xUnit)
        {
            switch (xUnit)
            {
            case ChartXUnit.CXU_Day:
                return(1);

            case ChartXUnit.CXU_Week:
                return(5);

            case ChartXUnit.CXU_Month:
                return(22);

            case ChartXUnit.CXU_Year:
                return(245);

            default:
                throw new ArgumentException("Unknow xUnit!");
            }
        }
Example #3
0
        public static String ToUnitName(ChartXUnit xUnit)
        {
            switch (xUnit)
            {
            case ChartXUnit.CXU_Day:
                return("Day");

            case ChartXUnit.CXU_Week:
                return("Week");

            case ChartXUnit.CXU_Month:
                return("Month");

            case ChartXUnit.CXU_Year:
                return("Year");

            default:
                throw new ArgumentException("Unknown ChartXUnit!");
            }
        }
        public void selItemsHistoryDataToChart(Chart chart, List <SelectItem> selItems, List <DateRange> dateRangeList, RunMode runMode, out ChartXUnit xUnit)
        {
            List <HistoryData>    dataList = new List <HistoryData>();
            List <DateSelectItem> items    = RegressResult.ToDaySelectItemList(selItems, dateRangeList);

            xUnit = SUtils.DetermineXUnit(items.Count);
            if (items.Count == 0)
            {
                return;
            }
            if (xUnit == ChartXUnit.CXU_Year)
            {
                items.Reverse();
                int startDate        = items[0].date_;
                int endDate          = items[items.Count - 1].date_;
                int startYear        = Utils.Year(startDate);
                int endYear          = Utils.Year(endDate);
                int iSearchStartHint = 0;
                for (int iYear = startYear; iYear <= endYear; iYear++)
                {
                    int iStartIndex = -1;
                    int nDaySpan    = 0;
                    for (int i = iSearchStartHint; i < items.Count; i++)
                    {
                        if (iStartIndex == -1 && Utils.Year(items[i].date_) == iYear)
                        {
                            iStartIndex = i;
                        }
                        if (iStartIndex != -1)
                        {
                            if (Utils.Year(items[i].date_) == iYear)
                            {
                                nDaySpan++;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    iSearchStartHint = iStartIndex + nDaySpan;
                    HistoryData data = StrategyAsset.GetHistoryData(items, iStartIndex, nDaySpan, runMode);
                    dataList.Add(data);
                }
            }
            else
            {
                int nDaySpan    = SUtils.ToDayCount(xUnit);
                int iStartIndex = 0;
                do
                {
                    if (iStartIndex + nDaySpan - 1 > items.Count)
                    {
                        break;
                    }
                    HistoryData data = StrategyAsset.GetHistoryData(items, iStartIndex, nDaySpan, runMode);
                    dataList.Add(data);
                    iStartIndex += nDaySpan;
                } while (iStartIndex < items.Count);
                dataList.Reverse();
            }

            List <String> xDescList = new List <string>();

            foreach (var item in dataList)
            {
                xDescList.Add(SUtils.ToXDesc(xUnit, item.startDate_, item.endDate_));
            }
            SUtils.FillHistoryDataToChart(chart, dataList, xDescList);
            re_.reHistory_ = StrategyAsset.GetHistoryData(items, 0, items.Count, re_.runMode_);
        }