예제 #1
0
        /// <summary>
        /// Gets a copy of this data from a date, to a date.
        /// </summary>
        /// <param name="start">Date to start from</param>
        /// <param name="end">Date to end at</param>
        /// <returns>New object with the data from the requested dates</returns>
        public TickerData SubSet(DateTime start, DateTime end)
        {
            TickerData copyData = new TickerData(TickerAndExchange);

            int copyStartIndex = -1;
            int copyEndIndex   = -1;

            for (int i = 0; i < Dates.Count; i++)
            {
                if (copyStartIndex == -1 && Dates[i] >= start)
                {
                    copyStartIndex = i;
                }
                if (copyEndIndex == -1 && Dates[i] >= end)
                {
                    copyEndIndex = i;
                }

                if (copyStartIndex > -1 && copyEndIndex > -1)
                {
                    break;
                }
            }

            if (copyStartIndex != -1)
            {
                if (copyEndIndex == -1 && end > Dates.Last())
                {
                    copyEndIndex = Dates.Count - 1;
                }

                int amountToCopy = (copyEndIndex - copyStartIndex) + 1;
                copyData.Dates.AddRange(Dates.GetRange(copyStartIndex, amountToCopy));
                copyData.Open.AddRange(Open.GetRange(copyStartIndex, amountToCopy));
                copyData.Close.AddRange(Close.GetRange(copyStartIndex, amountToCopy));
                copyData.High.AddRange(High.GetRange(copyStartIndex, amountToCopy));
                copyData.Low.AddRange(Low.GetRange(copyStartIndex, amountToCopy));
                copyData.Volume.AddRange(Volume.GetRange(copyStartIndex, amountToCopy));

                // Extras
                copyData.Typical.AddRange(Typical.GetRange(copyStartIndex, amountToCopy));
                copyData.Median.AddRange(Median.GetRange(copyStartIndex, amountToCopy));
                copyData.HigherTimeframeTrend.AddRange(HigherTimeframeTrend.GetRange(copyStartIndex, amountToCopy));

                for (int i = 0; i < HigherTimeframeValueStrings.Length; i++)
                {
                    string key = HigherTimeframeValueStrings[i];
                    copyData.HigherTimeframeValues[key].AddRange(HigherTimeframeValues[key].GetRange(copyStartIndex, amountToCopy));
                }

                copyData.Start   = copyData.Dates[0];
                copyData.End     = copyData.Dates[copyData.Dates.Count - 1];
                copyData.NumBars = copyData.Dates.Count;
                copyData.SaveDates();
            }

            return(copyData);
        }
예제 #2
0
 private TypicalListData ToTypicalListData(Typical t)
 {
     return(new TypicalListData()
     {
         TypicalID = t.TypicalID,
         Name = t.Name,
         SeriesID = t.SeriesTypicals.Where(st => st.IsPrimary).Select(st => st.SeriesID).FirstOrDefault(),
         ImageFileData = t.FeaturedImageForSize("m16to9"),
         FeaturedSeries = t.FeaturedSeries
     });
 }
예제 #3
0
        public virtual int _GetUniqueIdentifier()
        {
            var hashCode = 399326290;

            hashCode = hashCode * -1521134295 + (Id?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (Probability?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (RecordScore?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (InitialRecordScore?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (PartitionFieldValue?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (Timestamp?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (Typical?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (Actual?.GetHashCode() ?? 0);
            return(hashCode);
        }
예제 #4
0
        /// <summary>
        /// Appends the other data to the data already in this class. It doesn't overwrite data
        /// for existing dates, so it can only prepend data to the start or append to the end.
        /// </summary>
        /// <param name="otherData">Data to append</param>
        public void AppendData(TickerData otherData)
        {
            // Prepend
            if (otherData.Start < Start)
            {
                // Find the index in the other data where this data starts.
                int copyEndIndex;
                for (copyEndIndex = 0; copyEndIndex < otherData.Dates.Count; copyEndIndex++)
                {
                    if (otherData.Dates[copyEndIndex] >= Start)
                    {
                        break;
                    }
                }

                // Insert all the new data at the front of the existing data.
                Dates.InsertRange(0, otherData.Dates.GetRange(0, copyEndIndex));
                Open.InsertRange(0, otherData.Open.GetRange(0, copyEndIndex));
                Close.InsertRange(0, otherData.Close.GetRange(0, copyEndIndex));
                High.InsertRange(0, otherData.High.GetRange(0, copyEndIndex));
                Low.InsertRange(0, otherData.Low.GetRange(0, copyEndIndex));
                Volume.InsertRange(0, otherData.Volume.GetRange(0, copyEndIndex));

                // Extras
                Typical.InsertRange(0, otherData.Typical.GetRange(0, copyEndIndex));
                Median.InsertRange(0, otherData.Median.GetRange(0, copyEndIndex));
                HigherTimeframeTrend.InsertRange(0, otherData.HigherTimeframeTrend.GetRange(0, copyEndIndex));

                for (int i = 0; i < HigherTimeframeValueStrings.Length; i++)
                {
                    string key = HigherTimeframeValueStrings[i];
                    HigherTimeframeValues[key].InsertRange(0, otherData.HigherTimeframeValues[key].GetRange(0, copyEndIndex));
                }
            }

            // Append
            if (otherData.End > End)
            {
                // Find the index where the other data passes the end of the existing data.
                int copyStartIndex;
                for (copyStartIndex = 0; copyStartIndex < otherData.Dates.Count; copyStartIndex++)
                {
                    if (otherData.Dates[copyStartIndex] > End)
                    {
                        break;
                    }
                }

                // Append the new data to the end of the existing data.
                Dates.AddRange(otherData.Dates.GetRange(copyStartIndex, otherData.Dates.Count - copyStartIndex));
                Open.AddRange(otherData.Open.GetRange(copyStartIndex, otherData.Open.Count - copyStartIndex));
                Close.AddRange(otherData.Close.GetRange(copyStartIndex, otherData.Close.Count - copyStartIndex));
                High.AddRange(otherData.High.GetRange(copyStartIndex, otherData.High.Count - copyStartIndex));
                Low.AddRange(otherData.Low.GetRange(copyStartIndex, otherData.Low.Count - copyStartIndex));
                Volume.AddRange(otherData.Volume.GetRange(copyStartIndex, otherData.Volume.Count - copyStartIndex));

                // Extras
                Typical.AddRange(otherData.Typical.GetRange(copyStartIndex, otherData.Typical.Count - copyStartIndex));
                Median.AddRange(otherData.Median.GetRange(copyStartIndex, otherData.Median.Count - copyStartIndex));
                HigherTimeframeTrend.AddRange(otherData.HigherTimeframeTrend.GetRange(copyStartIndex, otherData.HigherTimeframeTrend.Count - copyStartIndex));

                for (int i = 0; i < HigherTimeframeValueStrings.Length; i++)
                {
                    string key = HigherTimeframeValueStrings[i];
                    HigherTimeframeValues[key].AddRange(otherData.HigherTimeframeValues[key].GetRange(copyStartIndex, otherData.HigherTimeframeValues[key].Count - copyStartIndex));
                }
            }

            Start   = Dates[0];
            End     = Dates[Dates.Count - 1];
            NumBars = Dates.Count;
            SaveDates();
        }
예제 #5
0
        public TypicalInformation GetTypicalInfo(int?id = null, string typicalName = null)
        {
            TypicalInformation tInfo = new TypicalInformation();

            Typical theData = null;

            if (id.HasValue)
            {
                theData = database.Typicals.FirstOrDefault(s => s.TypicalID == id);
            }
            else if ((typicalName ?? "").Any())
            {
                theData = database.Typicals.FirstOrDefault(s => s.Name == typicalName);
            }

            if (theData != null)
            {
                tInfo.TypicalID = theData.TypicalID;
                tInfo.Name      = theData.Name;
                var serTypical = theData.SeriesTypicals.FirstOrDefault(st => st.IsPrimary);
                if (serTypical != null)
                {
                    tInfo.Category = serTypical.Series.Category.Name;
                    tInfo.Series   = serTypical.Series.Name;
                }
                tInfo.FeaturedImageFileData = theData.FeaturedImageForSize("l16to9");
                tInfo.Images  = theData.ImageListForSize("m16to9", 3).Select(i => (ImageComboItem)i).ToList();
                tInfo.Options = new Dictionary <string, IEnumerable <string> >();
                tInfo.Details = new Dictionary <string, IEnumerable <string> >();

                foreach (var attr in theData.TypicalOptionAttributes.Select(soa => soa.TAttribute).Distinct())
                {
                    if (attr.DetailItem)
                    {
                        tInfo.Details.Add(attr.Name, new List <string>(
                                              theData.TypicalOptionAttributes
                                              .Where(soa => soa.AttributeID == attr.AttributeID)
                                              .Select(so => so.TAttributeOption.Name)
                                              ));
                    }
                    else
                    {
                        tInfo.Options.Add(attr.Name, new List <string>(
                                              theData.TypicalOptionAttributes
                                              .Where(soa => soa.AttributeID == attr.AttributeID)
                                              .Select(so => so.TAttributeOption.Name)
                                              ));
                    }
                }

                foreach (var attr in theData.TypicalIntAttributes.Select(soa => soa.TAttribute).Distinct())
                {
                    if (attr.DetailItem)
                    {
                        tInfo.Details.Add(attr.Name, new List <string>(
                                              theData.TypicalIntAttributes
                                              .Where(soa => soa.AttributeID == attr.AttributeID)
                                              .Select(so => so.Value.ToString())
                                              ));
                    }
                    else
                    {
                        tInfo.Options.Add(attr.Name, new List <string>(
                                              theData.TypicalIntAttributes
                                              .Where(soa => soa.AttributeID == attr.AttributeID)
                                              .Select(so => so.Value.ToString())
                                              ));
                    }
                }

                foreach (var attr in theData.TypicalTextAttributes.Select(soa => soa.TAttribute).Distinct())
                {
                    if (attr.DetailItem)
                    {
                        tInfo.Details.Add(attr.Name, new List <string>(
                                              theData.TypicalTextAttributes
                                              .Where(soa => soa.AttributeID == attr.AttributeID)
                                              .Select(so => so.Value)
                                              ));
                    }
                    else
                    {
                        tInfo.Options.Add(attr.Name, new List <string>(
                                              theData.TypicalTextAttributes
                                              .Where(soa => soa.AttributeID == attr.AttributeID)
                                              .Select(so => so.Value)
                                              ));
                    }
                }
            }

            return(tInfo);
        }