Beispiel #1
0
        public QuoteCollection(QuoteCollection original, RecordType longer)
        {
            if (QuoteType > longer)
            {
                throw new Exception();
            }

            Name      = original.Name;
            QuoteType = longer;
            //DateTimeFormat = DefaultDateTimeFormats[QuoteType];

            DataCollection = FromShortTerms(original, longer);

            getCeilingFloor();

            //YData = original.YData;
            //Threshold = original.Threshold;
            LastModify       = DateTime.Now;
            ShortTermOutline = TrendMarker.OutlineFromQuotes(this, 1);
            CurrentOutline   = TrendMarker.OutlineFromQuotes(this, TrendMarker.DefaultThreshold);

            if (CurrentOutline == null)
            {
                CurrentOutline = ShortTermOutline;
            }

            OutlineValues = getDefaultValues();
            Dates         = getDates();
        }
Beispiel #2
0
        public QuoteCollection this[RecordType longer]
        {
            get
            {
                if (longer < QuoteType)
                {
                    throw new Exception();
                }
                else if (longer == QuoteType)
                {
                    return(this);
                }

                QuoteCollection result = null;

                foreach (QuoteCollection longQuotes in longTerms)
                {
                    if (longQuotes.QuoteType == longer)
                    {
                        result = longQuotes;
                    }
                }

                if (result == null)
                {
                    result = new QuoteCollection(this, longer);
                    longTerms.Add(result);
                }
                else if (result.LastModify < LastModify)
                {
                    longTerms.Clear();
                    result = new QuoteCollection(this, longer);
                    longTerms.Add(result);
                }

                return(result);
            }
        }
Beispiel #3
0
        public static SortedDictionary <DateTimeOffset, Double> OutlineOf(QuoteCollection quotes, int threshold)
        {
            TrendMarker marker = new TrendMarker(quotes.DataCollection, threshold);

            return(marker.OutlineDictionary);
        }
Beispiel #4
0
        //public static Dictionary<DateTimeOffset, Major> MajorsOf(List<Quote> dataCollection, int threshold)
        //{
        //    TrendMarker marker = new TrendMarker(dataCollection, threshold);

        //    return marker.MajorQuotes;
        //}

        public static Outline OutlineFromQuotes(QuoteCollection quotes, int threshold)
        {
            TrendMarker marker = new TrendMarker(quotes.DataCollection, threshold);

            return(marker.TheOutline);
        }
Beispiel #5
0
        public static List <Quote> FromShortTerms(QuoteCollection shorters, RecordType longerType)
        {
            if (longerType <= shorters.QuoteType)
            {
                throw new Exception();
            }
            else if (longerType <= RecordType.DayRecord)
            {
                throw new NotImplementedException();
            }
            else if (shorters.QuoteType == RecordType.WeekRecord)
            {
                throw new NotImplementedException();
            }

            periodDelegate differenceComparer = null;

            switch (longerType)
            {
            case RecordType.WeekRecord:
                differenceComparer = new periodDelegate(weekValueOf);
                break;

            case RecordType.MonthRecord:
                differenceComparer = new periodDelegate(monthValueOf);
                break;

            case RecordType.QuarterRecord:
                differenceComparer = new periodDelegate(quarterValueOf);
                break;

            case RecordType.YearRecord:
                differenceComparer = new periodDelegate(yearValueOf);
                break;

            default:
                throw new NotImplementedException();
            }

            List <Quote> result = new List <Quote>();

            var groupQuery =
                from item in shorters.DataCollection
                let period = differenceComparer(item)
                             group item by period into clusters
                             orderby clusters.Key
                             select clusters;

            foreach (var cluster in groupQuery)
            {
                double         open = cluster.First().Open, high = double.MinValue, low = double.MaxValue, close = cluster.Last().Close, volume = 0;
                DateTimeOffset lastTime = cluster.Last().Date;

                foreach (Quote item in cluster)
                {
                    if (item.High > high)
                    {
                        high = item.High;
                    }

                    if (item.Low < low)
                    {
                        low = item.Low;
                    }

                    volume += item.Volume;
                }
                Quote newRecord = new Quote(lastTime, open, high, low, close, volume);
                result.Add(newRecord);
            }

            return(result);
        }