예제 #1
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));
            }
        }
예제 #2
0
 public Histogram(TimeSeries data, double binSize)
 {
     this.binSize = binSize;
     for (int i = 0; i < data.Count(); i++) {
         IncrementAt((int)Math.Floor(data[i] / binSize));
     }
 }
예제 #3
0
 /// <summary>Uses Scott's choice algorithm to assign bin width:
 /// http://en.wikipedia.org/wiki/Histogram#Number_of_bins_and_width</summary>
 public Histogram(TimeSeries data)
 {
     var bS = (3.5 * data.StandardDeviation) / Math.Pow(data.Count(), .33333333333333);
     if (bS <= 0)
         bS = .01;
     this.binSize = bS;
     for (int i = 0; i < data.Count(); i++) {
         IncrementAt((int)Math.Floor(data[i] / binSize));
     }
 }
예제 #4
0
 public TimeSeries DailyReturns(int i, DateTime start, DateTime end)
 {
     var r = getReader(i);
     TimeSeries ts = new TimeSeries(getTitle(i));
     double lastVal = double.NaN;
     foreach (var p in r.readData(0, 6, start, end)) {
         double y = p.Y / lastVal - 1;
         if (lastVal == double.NaN) y = 0;
         ts.Add(p.X, y);
         lastVal = p.Y;
     }
     return ts;
 }
예제 #5
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;
        }
예제 #6
0
        public TimeSeries Open(int i, DateTime start, DateTime end, int fieldIdx = 6)
        {
            TimeSeries ts = new TimeSeries(getTitle(i));
            var r = getReader(i);
            try {
                foreach (var p in r.readData(0, fieldIdx, start, end)) {
                    ts.Add(p.X, p.Y);
                }
            }
            catch{

            }
            return ts;
        }
예제 #7
0
        public TimeSeries Open(string symbol, DateTime start, DateTime end, int fieldIdx = 6)
        {
            TimeSeries ts = new TimeSeries(symbol);
            var r = getReader(symbol);
            try {
                foreach (var p in r.readData(0, fieldIdx, start, end)) {
                    ts.Add(p.X, p.Y);
                }
            } catch {

            }
            return ts;
        }
예제 #8
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();
        }
예제 #9
0
 public TimeSeries GetDiffs()
 {
     double lastVal = double.NaN;
     TimeSeries ts = new TimeSeries(this.Name);
     ///Notice that this for loop iterates forward in time
     for (int i = domain.Count() - 1; i >= 0; i--) {
         double y = range[i] / lastVal - 1;
         if (double.IsNaN(lastVal)) y = 0;
         ts.Add(domain[i], y);
         lastVal = range[i];
     }
     return ts;
 }
예제 #10
0
        public ScatterSeries CorrelateDailyReturns(TimeSeries ts2)
        {
            ScatterSeries ss = new ScatterSeries() { MarkerSize = .8, MarkerStroke = OxyColors.Blue, MarkerFill = OxyColors.Blue };
            int i = this.DailyReturns.Count() - 1;
            int j = ts2.DailyReturns.Count() - 1;
            while (i >= 0 && j >= 0) {
                double domaini = this.DailyReturns.domain[i];
                double domainj = ts2.DailyReturns.domain[j];
                if (domaini != domainj) {
                    if (domaini > domainj) {
                        i--;
                    } else { j--; }
                    continue;
                } else {
                    ss.Points.Add(new ScatterPoint(this.DailyReturns.range[i], ts2.DailyReturns.range[j]));
                    i--;
                    j--;
                }

            }
            return ss;
        }
예제 #11
0
        public ScatterSeries Correlate2(TimeSeries ts2)
        {
            ScatterSeries ss = new ScatterSeries() { MarkerSize = .8, MarkerStroke = OxyColors.Blue, MarkerFill = OxyColors.Blue };
            bool axis1Direction = this.domain[1] - this.domain[0] > 0;
            bool axis2Direction = ts2.domain[1] - ts2.domain[0] > 0;
            int i, j;
            if (axis1Direction) {
                i = this.Count() - 1;
            } else {
                i = 0;
            }
            if (axis2Direction) {
                j = ts2.Count() - 1;
            } else {
                j = 0;
            }

            while (i >= 0 && j >= 0 && i < this.Count() && j < ts2.Count()) {
                double domaini = this.domain[i];
                double domainj = ts2.domain[j];
                if (domaini != domainj) {
                    if (domaini > domainj) {
                        //Move i
                        if (axis1Direction) {
                            i--;
                        } else {
                            i++;
                        }
                    } else {
                        //Move j
                        if (axis2Direction) {
                            j--;
                        } else {
                            j++;
                        }
                    }
                    continue;
                } else {
                    ss.Points.Add(new ScatterPoint(this.range[i], ts2.range[j]));
                    //Move both
                    if (axis1Direction) {
                        i--;
                    } else {
                        i++;
                    }
                    if (axis2Direction) {
                        j--;
                    } else {
                        j++;
                    }
                }
            }
            return ss;
        }
예제 #12
0
        private LineSeries getSeries(TimeSeries ts)
        {
            if (LogarithmicX) {
                ts.LogarithmicX();
            }
            if (LogarithmicY) {
                ts.LogarithmicY();
            }

            if (this.Normalize0) {
                return ts.Normalize0();
            } else if (this.Normalize1) {
                return ts.Normalize1();
            } else {
                return ts.GetLineSeries();
            }
        }