Example #1
0
 public DataRangePartition GetPartition(int index = int.MaxValue)
 {
     if (index < _partitions.Count)
     {
         return(_partitions[index]);
     }
     else
     {
         var last = _partitions.LastOrDefault();
         _partitions.Add(DataRangePartition.Create(last));
         return(_partitions.LastOrDefault());
     }
 }
Example #2
0
        public void Partition()
        {
            int                start = 0;
            List <int>         slide;
            List <int>         maxmin;
            DataRangePartition partition = GetPartition();

            while (start < _dataPoints.Count)
            {
                slide  = GetNextSlideWindow(start, SlideWindow);
                maxmin = FindMaxAndMin(slide.First(), slide.Last());
                //step 1: find direction
                if (_dataPoints[slide.LastOrDefault()].Close >= _dataPoints[slide.FirstOrDefault()].Close)
                {
                    partition.Direction = TrendDirection.Up;
                    while (start != maxmin.Last())
                    {
                        for (int i = slide.First(); i <= maxmin.Last(); i++)
                        {
                            partition.AddData(_dataPoints[i]);
                        }
                        start  = maxmin.Last();
                        slide  = GetNextSlideWindow(start, SlideWindow);
                        maxmin = FindMaxAndMin(slide.First(), slide.Last());
                    }

                    if (slide.Count == 1)
                    {
                        partition.AddData(_dataPoints[start]);
                    }

                    start = maxmin.Last() + 1;
                    if (start < _dataPoints.Count)
                    {
                        partition = GetPartition();
                    }
                }
                else
                {
                    partition.Direction = TrendDirection.Down;
                    while (start != maxmin.First())
                    {
                        for (int i = slide.First(); i <= maxmin.First(); i++)
                        {
                            partition.AddData(_dataPoints[i]);
                        }
                        start  = maxmin.First();
                        slide  = GetNextSlideWindow(start, SlideWindow);
                        maxmin = FindMaxAndMin(slide.First(), slide.Last());
                    }

                    if (slide.Count == 1)
                    {
                        partition.AddData(_dataPoints[start]);
                    }

                    start = maxmin.First() + 1;
                    if (start < _dataPoints.Count)
                    {
                        partition = GetPartition();
                    }
                }
            }
        }