Beispiel #1
0
        public TimeSeries Open2(string symbl, DataType type, DateTime start, DateTime end)
        {
            var a = new Quote(symbl);
            XDocument doc = null;
            if (Properties.Settings.Default.PollWebAPI) {
                doc = a.Fetch(start.Date, end);
                if (doc == null) {
                    throw new Exception();
                }
            }

            TimeSeries ts = new TimeSeries(symbl);
            if (type == DataType.AdjClose) {
                if (!Properties.Settings.Default.PollWebAPI) {
                    return Open(symbl, start, end, 6);
                }
                foreach (var quote in doc.Descendants("quote")) {
                    ts.Add(DateTimeAxis.ToDouble(DateTime.Parse(quote.Element("Date").Value)),
                        double.Parse(quote.Element("Adj_Close").Value));
                }
            }

            if (type == DataType.Volume) {
                if (!Properties.Settings.Default.PollWebAPI) {
                    return Open(symbl, start, end, 5);
                }
                foreach (var quote in doc.Descendants("quote")) {
                    ts.Add(DateTimeAxis.ToDouble(DateTime.Parse(quote.Element("Date").Value)),
                        double.Parse(quote.Element("Volume").Value));
                }
            }

            if (type == DataType.Close) {
                if (!Properties.Settings.Default.PollWebAPI) {
                    return Open(symbl, start, end, 4);
                }
                foreach (var quote in doc.Descendants("quote")) {
                    ts.Add(DateTimeAxis.ToDouble(DateTime.Parse(quote.Element("Date").Value)),
                        double.Parse(quote.Element("Close").Value));
                }
            }

            if (type == DataType.Open) {
                if (!Properties.Settings.Default.PollWebAPI) {
                    return Open(symbl, start, end, 1);
                }
                foreach (var quote in doc.Descendants("quote")) {
                    ts.Add(DateTimeAxis.ToDouble(DateTime.Parse(quote.Element("Date").Value)),
                        double.Parse(quote.Element("Open").Value));
                }
            }

            if (type == DataType.High) {
                if (!Properties.Settings.Default.PollWebAPI) {
                    return Open(symbl, start, end, 2);
                }
                foreach (var quote in doc.Descendants("quote")) {
                    ts.Add(DateTimeAxis.ToDouble(DateTime.Parse(quote.Element("Date").Value)),
                        double.Parse(quote.Element("High").Value));
                }
            }

            if (type == DataType.Low) {
                foreach (var quote in doc.Descendants("quote")) {
                    ts.Add(DateTimeAxis.ToDouble(DateTime.Parse(quote.Element("Date").Value)),
                        double.Parse(quote.Element("Low").Value));
                }
            }
            return ts;
        }
Beispiel #2
0
        public void GetOpenCloseHighLow(string symbl, DateTime start, DateTime end, out TimeSeries open, out TimeSeries close, out TimeSeries high, out TimeSeries low)
        {
            var a = new Quote(symbl);
            XDocument doc = null;
            if (Properties.Settings.Default.PollWebAPI) {
                doc = a.Fetch(start.Date, end);
                if (doc == null) {
                    throw new Exception();
                }
            }

            open = new TimeSeries(symbl);
            close = new TimeSeries(symbl);
            high = new TimeSeries(symbl);
            low = new TimeSeries(symbl);

            if (!Properties.Settings.Default.PollWebAPI) {
                open = Open(symbl, start, end, 1);
                high = Open(symbl, start, end, 2);
                low = Open(symbl, start, end, 3);
                close = Open(symbl, start, end, 4);
                return;
            }

            foreach (var quote in doc.Descendants("quote")) {
                open.Add(DateTimeAxis.ToDouble(DateTime.Parse(quote.Element("Date").Value)),
                    double.Parse(quote.Element("Open").Value));
                close.Add(DateTimeAxis.ToDouble(DateTime.Parse(quote.Element("Date").Value)),
                    double.Parse(quote.Element("Close").Value));
                high.Add(DateTimeAxis.ToDouble(DateTime.Parse(quote.Element("Date").Value)),
                    double.Parse(quote.Element("High").Value));
                low.Add(DateTimeAxis.ToDouble(DateTime.Parse(quote.Element("Date").Value)),
                    double.Parse(quote.Element("Low").Value));
            }
        }
Beispiel #3
0
        public TimeSeries Open(string symbl, DataType type, DateTime start, DateTime end)
        {
            this.start = start;
            this.end = end;
            symbl = symbl.ToUpper();
            var a = new Quote(symbl);
            //var doc = a.Fetch(DateTime.Parse("2010-03-5").Date, DateTime.Parse("2011-03-5"));

            TimeSeries ts = new TimeSeries(symbl);
            if (type == DataType.AdjClose) {
                return Open(symbolIndex[symbl], start, end, 6);
            }

            if (type == DataType.Volume) {
                return Open(symbolIndex[symbl], start, end, 5);
            }

            if (type == DataType.Close) {
                return Open(symbolIndex[symbl], start, end, 4);
            }
            //if (type == DataType.DailyReturns) {
            //    return DailyReturns(symbolIndex[symbl], start, end);
            //}
            throw new Exception();
        }