Ejemplo n.º 1
0
        private static IEnumerable <BaseData> GetEnumerator(Symbol symbol, DateTime startDateTime, DateTime endDateTime)
        {
            var data = Historical.Get(symbol.Value, startDateTime, endDateTime);

            foreach (var item in data)
            {
                yield return(new TradeBar(item.Date, symbol, item.Open, item.High, item.Low, item.Close, (long)item.Volume, TimeSpan.FromDays(1)));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Download Dividend and Split data from Yahoo
        /// </summary>
        /// <param name="symbol">Symbol of the data to download</param>
        /// <param name="startUtc">Get data after this time</param>
        /// <param name="endUtc">Get data before this time</param>
        /// <returns></returns>
        public Queue <BaseData> DownloadSplitAndDividendData(Symbol symbol, DateTime startUtc, DateTime endUtc)
        {
            var split    = Historical.GetRaw(symbol.Value, startUtc, endUtc, "split");
            var dividend = Historical.GetRaw(symbol.Value, startUtc, endUtc, "dividend");
            var parsed   = new List <BaseData>();

            foreach (var data in new[] { split, dividend })
            {
                bool isSplit = false;

                foreach (var item in data.Split('\n'))
                {
                    if (item == "Date,Stock Splits")
                    {
                        isSplit = true;
                        continue;
                    }
                    if (item == "Date,Dividends")
                    {
                        continue;
                    }
                    if (item == "")
                    {
                        break;
                    }

                    string[] values = item.Split(',');

                    if (isSplit)
                    {
                        parsed.Add(new Split
                        {
                            Time  = DateTime.ParseExact(values[0].Replace("-", String.Empty), DateFormat.EightCharacter, CultureInfo.InvariantCulture),
                            Value = ParseAmount(values[1])
                        });
                    }
                    else
                    {
                        parsed.Add(new Dividend
                        {
                            Time  = DateTime.ParseExact(values[0].Replace("-", String.Empty), DateFormat.EightCharacter, CultureInfo.InvariantCulture),
                            Value = Decimal.Parse(values[1])
                        });
                    }
                }
            }

            return(new Queue <BaseData>(parsed.OrderByDescending(x => x.Time)));
        }