コード例 #1
0
        internal int GetEndIndex(int endDate, KLineDataIndexResult result)
        {
            //最后一个index是结束日的后一天对应的index-1
            int endIndex;

            if (result.IndexDic.Keys.Contains(endDate))
            {
                endIndex = result.NextDateIndex(endDate) - 1;
                if (endIndex < 0)
                {
                    endIndex = Length() - 1;
                }
            }
            else
            {
                int realEndDateNext = FindDate(result, endDate, true);
                if (realEndDateNext < 0)
                {
                    endIndex = Length() - 1;
                }
                else
                {
                    endIndex = result.IndexDic[realEndDateNext] - 1;
                }
            }

            return(endIndex);
        }
コード例 #2
0
        public IKLineData Load(int date, int beforeDayCount, int afterDayCount)
        {
            if (!File.Exists(path))
            {
                return(null);
            }
            KLineDataIndexResult result = LoadIndex();
            int index = FindIndex(result, date, true);

            if (index < 0)
            {
                return(null);
            }
            int startIndex = index - beforeDayCount;

            if (startIndex < 0)
            {
                startIndex = 0;
            }

            int endIndex = index + afterDayCount;

            if (endIndex >= result.DateList.Count)
            {
                endIndex = result.DateList.Count - 1;
            }

            return(LoadByIndex(startIndex, endIndex));
        }
コード例 #3
0
        public int GetLastTradingDay()
        {
            KLineDataIndexResult indexResult = LoadIndex();

            if (indexResult == null)
            {
                return(-1);
            }
            return(indexResult.LastDate);
        }
コード例 #4
0
        public IKLineData Load(int startDate, int endDate)
        {
            if (!File.Exists(path))
            {
                return(null);
            }
            KLineDataIndexResult result = LoadIndex();

            return(Load(startDate, endDate, result));
        }
コード例 #5
0
        public List <int> GetAllTradingDay()
        {
            if (!File.Exists(path))
            {
                return(null);
            }
            KLineDataIndexResult result = LoadIndex();

            return(result.DateList);
        }
コード例 #6
0
        internal IKLineData Load(int startDate, int endDate, KLineDataIndexResult result)
        {
            int startIndex = GetStartIndex(startDate, result);
            int endIndex   = GetEndIndex(endDate, result);

            if (startIndex < 0 || endIndex < 0 || startIndex > endIndex)
            {
                return(null);
            }
            return(LoadByIndex(startIndex, endIndex));
        }
コード例 #7
0
        internal int GetStartIndex(int startDate, KLineDataIndexResult result)
        {
            int startIndex;

            if (result.IndexDic.Keys.Contains(startDate))
            {
                startIndex = result.IndexDic[startDate];
            }
            else
            {
                int realStartDate = FindDate(result, startDate, true);
                startIndex = result.GetDateDataIndex(realStartDate);
            }

            return(startIndex);
        }
コード例 #8
0
        public KLineDataIndexResult GetIndexResult()
        {
            String indexPath = path + ".index";

            if (!File.Exists(indexPath))
            {
                return(null);
            }
            KLineDataIndexResult result = new KLineDataIndexResult();

            String[] lines = File.ReadAllLines(indexPath);
            for (int i = 0; i < lines.Length; i++)
            {
                String   line = lines[i];
                String[] arr  = line.Split(',');
                result.AddIndex(int.Parse(arr[0]), int.Parse(arr[1]));
            }
            return(result);
        }
コード例 #9
0
        internal KLineDataIndexResult LoadIndex()
        {
            KLineDataIndexResult result = LoadIndexInternal();

            if (result == null)
            {
                DoIndex();
                return(LoadIndexInternal());
            }
            else
            {
                int lastDate = (int)GetLastTime();
                if (result.LastDate != lastDate)
                {
                    DoIndex();
                    return(LoadIndexInternal());
                }
                else
                {
                    return(result);
                }
            }
        }
コード例 #10
0
        private int FindIndex(KLineDataIndexResult result, int date, bool forward)
        {
            List <int> dateList = result.DateList;

            if (forward)
            {
                int lastDate = dateList[0];
                if (lastDate > date)
                {
                    return(0);
                }
                for (int i = 1; i < dateList.Count; i++)
                {
                    if (dateList[i] > date && dateList[i - 1] < date)
                    {
                        return(result.IndexDic[dateList[i]]);
                    }
                }
            }
            else
            {
                int lastDate = dateList[dateList.Count - 1];
                if (lastDate < date)
                {
                    return(0);
                }
                for (int i = dateList.Count - 2; i >= 0; i--)
                {
                    if (dateList[i] < date && dateList[i + 1] > date)
                    {
                        return(result.IndexDic[dateList[i]]);
                    }
                }
            }
            return(-1);
        }