public void TestCSVLoader() { var loader = new CSVFinal(); loader.DateFormat = "yyyy.MM.dd hh:mm:ss"; var tickerAAPL = new TickerSymbol("AAPL", "NY"); var desc = new MarketDataDescription(tickerAAPL, MarketDataType.Close, true, true); MarketMLDataSet marketData = new MarketMLDataSet(loader, 5, 1); marketData.AddDescription(desc); marketData.SequenceGrandularity = Util.Time.TimeUnit.Hours; var begin = new DateTime(2006, 1, 1); var end = new DateTime(2007, 7, 31); loader.GetFile((AssemblyDirectory + "\\smallCSV.csv")); marketData.Load(begin, end); marketData.Generate(); // first test the points IEnumerator <TemporalPoint> itr = marketData.Points.GetEnumerator(); itr.MoveNext(); TemporalPoint point = itr.Current; Assert.AreEqual(0, point.Sequence); Assert.AreEqual(1, point.Data.Length); Assert.AreEqual(1.12884, point[0]); Assert.AreEqual(5, marketData.Points.Count); }
public void TestCSVLoader() { var loader = new CSVFinal(); loader.DateFormat = "yyyy.MM.dd hh:mm:ss"; var tickerAAPL = new TickerSymbol("AAPL", "NY"); var desc = new MarketDataDescription(tickerAAPL, MarketDataType.Close, true, true); MarketMLDataSet marketData = new MarketMLDataSet(loader, 5, 1); marketData.AddDescription(desc); marketData.SequenceGrandularity = Util.Time.TimeUnit.Hours; var begin = new DateTime(2006, 1, 1); var end = new DateTime(2007, 7, 31); loader.GetFile((AssemblyDirectory + "\\smallCSV.csv")); marketData.Load(begin, end); marketData.Generate(); // first test the points IEnumerator<TemporalPoint> itr = marketData.Points.GetEnumerator(); itr.MoveNext(); TemporalPoint point = itr.Current; Assert.AreEqual(0, point.Sequence); Assert.AreEqual(1, point.Data.Length); Assert.AreEqual(1.12884, point[0]); Assert.AreEqual(5, marketData.Points.Count); }
public bool Equals(TickerSymbol other) { if (other.Symbol.Equals(this.Symbol)) { if ((other.Exchange == null) && (other.Exchange == null)) { return true; } goto Label_001B; } return false; Label_0017: return false; Label_001B: if (other.Exchange == null) { goto Label_0017; } do { if (this.Exchange == null) { goto Label_0017; } if (3 != 0) { return other.Exchange.Equals(this.Exchange); } } while (0 != 0); goto Label_001B; }
/// <summary> /// Construct a MarketDataDescription item. /// </summary> /// <param name="ticker">The ticker symbol to use.</param> /// <param name="dataType">The data type needed.</param> /// <param name="type">The normalization type.</param> /// <param name="activationFunction"> The activation function to apply to this data, can be null.</param> /// <param name="input">Is this field used for input?</param> /// <param name="predict">Is this field used for prediction?</param> public MarketDataDescription(TickerSymbol ticker, MarketDataType dataType, Type type, IActivationFunction activationFunction, bool input, bool predict) : base(activationFunction, type, input, predict) { _ticker = ticker; _dataType = dataType; }
/// <summary> /// Construct a MarketDataDescription item. /// </summary> /// <param name="ticker">The ticker symbol to use.</param> /// <param name="dataType">The data type needed.</param> /// <param name="type">The normalization type.</param> /// <param name="activationFunction"> The activation function to apply to this data, can be null.</param> /// <param name="input">Is this field used for input?</param> /// <param name="predict">Is this field used for prediction?</param> public MarketDataDescription(TickerSymbol ticker, MarketDataType dataType, Type type, IActivationFunction activationFunction, bool input, bool predict) : base(activationFunction, type, input, predict) { _ticker = ticker; _dataType = dataType; }
/// <summary> /// Load one ticker symbol. /// </summary> /// <param name="ticker">The ticker symbol to load.</param> /// <param name="from">Load data from this date.</param> /// <param name="to">Load data to this date.</param> private void LoadSymbol(TickerSymbol ticker, DateTime from, DateTime to) { ICollection <LoadedMarketData> data = Loader.Load(ticker, null, from, to); foreach (LoadedMarketData item in data) { TemporalPoint point = CreatePoint(item.When); LoadPointFromMarketData(ticker, point, item); } }
/// <summary> /// Load one point of market data. /// </summary> /// <param name="ticker">The ticker symbol to load.</param> /// <param name="point">The point to load at.</param> /// <param name="item">The item being loaded.</param> private void LoadPointFromMarketData(TickerSymbol ticker, TemporalPoint point, LoadedMarketData item) { foreach (TemporalDataDescription desc in Descriptions) { var mdesc = (MarketDataDescription)desc; if (mdesc.Ticker.Equals(ticker)) { point.Data[mdesc.Index] = item.Data[mdesc.DataType]; } } }
/// <summary> /// Determine if two ticker symbols equal each other. /// </summary> /// <param name="other">The other ticker symbol.</param> /// <returns>True if the two symbols equal.</returns> public bool Equals(TickerSymbol other) { // if the symbols do not even match then they are not equal if (!other.Symbol.Equals(this.Symbol)) { return false; } // if the symbols match then we need to compare the exchanges if (other.Exchange == null && other.Exchange == null) { return true; } if (other.Exchange == null || this.Exchange == null) { return false; } return other.Exchange.Equals(this.Exchange); }
/// <summary> /// Load one ticker symbol. /// </summary> /// <param name="ticker">The ticker symbol to load.</param> /// <param name="from">Load data from this date.</param> /// <param name="to">Load data to this date.</param> private void LoadSymbol(TickerSymbol ticker, DateTime from, DateTime to) { IList <MarketDataType> types = new List <MarketDataType>(); foreach (MarketDataDescription desc in Descriptions) { if (desc.Ticker.Equals(ticker)) { types.Add(desc.DataType); } } ICollection <LoadedMarketData> data = Loader.Load(ticker, types, from, to); foreach (LoadedMarketData item in data) { TemporalPoint point = CreatePoint(item.When); LoadPointFromMarketData(ticker, point, item); } }
/// <summary> /// Determine if two ticker symbols equal each other. /// </summary> /// <param name="other">The other ticker symbol.</param> /// <returns>True if the two symbols equal.</returns> public bool Equals(TickerSymbol other) { // if the symbols do not even match then they are not equal if (!other.Symbol.Equals(this.Symbol)) { return(false); } // if the symbols match then we need to compare the exchanges if (other.Exchange == null && other.Exchange == null) { return(true); } if (other.Exchange == null || this.Exchange == null) { return(false); } return(other.Exchange.Equals(this.Exchange)); }
/// <summary> /// Load one ticker symbol. /// </summary> /// <param name="ticker">The ticker symbol to load.</param> /// <param name="from">Load data from this date.</param> /// <param name="to">Load data to this date.</param> private void LoadSymbol(TickerSymbol ticker, DateTime from, DateTime to) { IList < MarketDataType > types = new List<MarketDataType>(); foreach (MarketDataDescription desc in Descriptions) { if (desc.Ticker.Equals(ticker)) { types.Add(desc.DataType); } } ICollection<LoadedMarketData> data = Loader.Load(ticker, types, from, to); foreach (LoadedMarketData item in data) { TemporalPoint point = CreatePoint(item.When); LoadPointFromMarketData(ticker, point, item); } }
/// <summary> /// Load one point of market data. /// </summary> /// <param name="ticker">The ticker symbol to load.</param> /// <param name="point">The point to load at.</param> /// <param name="item">The item being loaded.</param> private void LoadPointFromMarketData(TickerSymbol ticker, TemporalPoint point, LoadedMarketData item) { foreach (TemporalDataDescription desc in Descriptions) { var mdesc = (MarketDataDescription) desc; if (mdesc.Ticker.Equals(ticker)) { point.Data[mdesc.Index] = item.Data[mdesc.DataType]; } } }
public void MarketData() { IMarketLoader loader = new YahooFinanceLoader(); var tickerAAPL = new TickerSymbol("AAPL", null); var tickerMSFT = new TickerSymbol("MSFT", null); var marketData = new MarketMLDataSet(loader, 5, 1); marketData.AddDescription(new MarketDataDescription(tickerAAPL, MarketDataType.Close, true, true)); marketData.AddDescription(new MarketDataDescription(tickerMSFT, MarketDataType.Close, true, false)); marketData.AddDescription(new MarketDataDescription(tickerAAPL, MarketDataType.Volume, true, false)); marketData.AddDescription(new MarketDataDescription(tickerMSFT, MarketDataType.Volume, true, false)); var begin = new DateTime(2008, 7, 1); var end = new DateTime(2008, 7, 31); marketData.Load(begin, end); marketData.Generate(); Assert.AreEqual(22, marketData.Points.Count); // first test the points IEnumerator <TemporalPoint> itr = marketData.Points.GetEnumerator(); itr.MoveNext(); TemporalPoint point = itr.Current; Assert.AreEqual(0, point.Sequence); Assert.AreEqual(4, point.Data.Length); Assert.AreEqual(174.68, point[0]); Assert.AreEqual(26.87, point[1]); Assert.AreEqual(39, (int)(point[2] / 1000000)); Assert.AreEqual(100, (int)(point[3] / 1000000)); itr.MoveNext(); point = itr.Current; Assert.AreEqual(1, point.Sequence); Assert.AreEqual(4, point.Data.Length); Assert.AreEqual(168.18, point[0]); Assert.AreEqual(25.88, point[1]); Assert.AreEqual(29, (int)(point[2] / 1000000)); Assert.AreEqual(84, (int)(point[3] / 1000000)); itr.MoveNext(); point = itr.Current; Assert.AreEqual(2, point.Sequence); Assert.AreEqual(4, point.Data.Length); Assert.AreEqual(170.12, point[0]); Assert.AreEqual(25.98, point[1]); Assert.AreEqual(18, (int)(point[2] / 1000000)); Assert.AreEqual(37, (int)(point[3] / 1000000)); // now check the actual data Assert.AreEqual(16, marketData.Data.Count); Assert.AreEqual(20, marketData.InputNeuronCount); Assert.AreEqual(1, marketData.OutputNeuronCount); IEnumerator <IMLDataPair> itr2 = marketData.Data.GetEnumerator(); itr2.MoveNext(); IMLDataPair pair = itr2.Current; Assert.AreEqual(20, pair.Input.Count); Assert.AreEqual(1, pair.Ideal.Count); Assert.AreEqual(-0.037, Math.Round(pair.Input[0] * 1000.0) / 1000.0); Assert.AreEqual(-0.037, Math.Round(pair.Input[1] * 1000.0) / 1000.0); Assert.AreEqual(-0.246, Math.Round(pair.Input[2] * 1000.0) / 1000.0); Assert.AreEqual(-0.156, Math.Round(pair.Input[3] * 1000.0) / 1000.0); Assert.AreEqual(0.012, Math.Round(pair.Input[4] * 1000.0) / 1000.0); Assert.AreEqual(0.0040, Math.Round(pair.Input[5] * 1000.0) / 1000.0); Assert.AreEqual(-0.375, Math.Round(pair.Input[6] * 1000.0) / 1000.0); Assert.AreEqual(-0.562, Math.Round(pair.Input[7] * 1000.0) / 1000.0); Assert.AreEqual(0.03, Math.Round(pair.Input[8] * 1000.0) / 1000.0); Assert.AreEqual(0.0020, Math.Round(pair.Input[9] * 1000.0) / 1000.0); Assert.AreEqual(0.57, Math.Round(pair.Input[10] * 100.0) / 100.0); Assert.AreEqual(0.929, Math.Round(pair.Input[11] * 1000.0) / 1000.0); Assert.AreEqual(0.025, Math.Round(pair.Input[12] * 1000.0) / 1000.0); Assert.AreEqual(-0.0070, Math.Round(pair.Input[13] * 1000.0) / 1000.0); // for some reason, Yahoo likes to vary the volume numbers slightly, sometimes! Assert.AreEqual(0.1, Math.Round(pair.Input[14] * 10.0) / 10.0); Assert.AreEqual(-0.084, Math.Round(pair.Input[15] * 1000.0) / 1000.0); Assert.AreEqual(-0.03, Math.Round(pair.Input[16] * 1000.0) / 1000.0); Assert.AreEqual(-0.024, Math.Round(pair.Input[17] * 1000.0) / 1000.0); Assert.AreEqual(0.008, Math.Round(pair.Input[18] * 1000.0) / 1000.0); Assert.AreEqual(-0.172, Math.Round(pair.Input[19] * 1000.0) / 1000.0); itr2.MoveNext(); pair = itr2.Current; Assert.AreEqual(20, pair.Input.Count); Assert.AreEqual(1, pair.Ideal.Count); Assert.AreEqual(0.012, Math.Round(pair.Input[0] * 1000.0) / 1000.0); Assert.AreEqual(0.0040, Math.Round(pair.Input[1] * 1000.0) / 1000.0); Assert.AreEqual(-0.375, Math.Round(pair.Input[2] * 1000.0) / 1000.0); Assert.AreEqual(-0.562, Math.Round(pair.Input[3] * 1000.0) / 1000.0); Assert.AreEqual(0.03, Math.Round(pair.Input[4] * 1000.0) / 1000.0); Assert.AreEqual(0.0020, Math.Round(pair.Input[5] * 1000.0) / 1000.0); Assert.AreEqual(0.6, Math.Round(pair.Input[6] * 10.0) / 10.0); Assert.AreEqual(0.929, Math.Round(pair.Input[7] * 1000.0) / 1000.0); Assert.AreEqual(0.025, Math.Round(pair.Input[8] * 1000.0) / 1000.0); Assert.AreEqual(-0.0070, Math.Round(pair.Input[9] * 1000.0) / 1000.0); Assert.AreEqual(0.1, Math.Round(pair.Input[10] * 10.0) / 10.0); Assert.AreEqual(-0.084, Math.Round(pair.Input[11] * 1000.0) / 1000.0); Assert.AreEqual(-0.03, Math.Round(pair.Input[12] * 1000.0) / 1000.0); Assert.AreEqual(-0.024, Math.Round(pair.Input[13] * 1000.0) / 1000.0); Assert.AreEqual(0.0080, Math.Round(pair.Input[14] * 1000.0) / 1000.0); Assert.AreEqual(-0.172, Math.Round(pair.Input[15] * 1000.0) / 1000.0); Assert.AreEqual(0.014, Math.Round(pair.Input[16] * 1000.0) / 1000.0); Assert.AreEqual(0.0090, Math.Round(pair.Input[17] * 1000.0) / 1000.0); Assert.AreEqual(-0.1, Math.Round(pair.Input[18] * 10.0) / 10.0); Assert.AreEqual(0.066, Math.Round(pair.Input[19] * 1000.0) / 1000.0); }
/// <summary> /// Load the market data. /// </summary> /// <returns>True if the data was loaded.</returns> private bool LoadMarketData() { try { IMarketLoader loader = new YahooFinanceLoader(); TickerSymbol ticker = new TickerSymbol(this.Company.Text); IList<MarketDataType> needed = new List<MarketDataType>(); needed.Add(MarketDataType.AdjustedClose); needed.Add(MarketDataType.Close); needed.Add(MarketDataType.Open); needed.Add(MarketDataType.High); needed.Add(MarketDataType.Low); DateTime from = this.starting -TimeSpan.FromDays(365); DateTime to = this.starting + TimeSpan.FromDays(365*2); this.marketData = (List<LoadedMarketData>)loader.Load(ticker, needed, from, to); this.marketData.Sort(); this.numberOfDays = (int)((ActualWidth - FIRST_DAY_OFFSET) / DAY_WIDTH); this.numberOfDays = Math.Min(numberOfDays, this.marketData.Count); return true; } catch (Exception e) { MessageBox.Show("Ticker symbol likely invalid.\n"+e.Message, "Error Loading Data"); return false; } }
/// <summary> /// Construct a MarketDataDescription item. /// </summary> /// <param name="ticker">The ticker symbol to use.</param> /// <param name="dataType">The data type needed.</param> /// <param name="input">Is this field used for input?</param> /// <param name="predict">Is this field used for prediction?</param> public MarketDataDescription(TickerSymbol ticker, MarketDataType dataType, bool input, bool predict) : this(ticker, dataType, Type.PercentChange, null, input, predict) { }
private void xb45ce8e0e2f1da44(TickerSymbol x96e4701dec47675e, DateTime x7f8a886f51b477eb, DateTime x3ed4f4f0195b98d7) { foreach (LoadedMarketData data in this.Loader.Load(x96e4701dec47675e, null, x7f8a886f51b477eb, x3ed4f4f0195b98d7)) { TemporalPoint point = this.CreatePoint(data.When); this.xd619c0bf81b12658(x96e4701dec47675e, point, data); } }
public ICollection<LoadedMarketData> Load(TickerSymbol ticker, IList<MarketDataType> dataNeeded, DateTime from, DateTime to) { ICollection<LoadedMarketData> is2 = new List<LoadedMarketData>(); HttpWebResponse response = (HttpWebResponse) WebRequest.Create(x38c212309d8d5dd3(ticker, from, to)).GetResponse(); using (Stream stream = response.GetResponseStream()) { DateTime time; double num; double num2; double num3; double num4; double num5; double num6; LoadedMarketData data; ReadCSV dcsv = new ReadCSV(stream, true, CSVFormat.DecimalPoint); goto Label_005B; Label_003F: data.SetData(MarketDataType.Open, num2); Label_0049: data.SetData(MarketDataType.Volume, num6); is2.Add(data); Label_005B: if (dcsv.Next()) { goto Label_01AF; } dcsv.Close(); stream.Close(); if ((((uint) num) - ((uint) num5)) <= uint.MaxValue) { goto Label_0125; } if ((((uint) num) & 0) == 0) { goto Label_00B0; } Label_00A4: data.SetData(MarketDataType.Low, num5); goto Label_003F; Label_00B0: data.SetData(MarketDataType.AdjustedClose, num); do { data.SetData(MarketDataType.Open, num2); if ((((uint) num) - ((uint) num6)) > uint.MaxValue) { goto Label_0049; } data.SetData(MarketDataType.Close, num3); data.SetData(MarketDataType.High, num4); } while ((((uint) num5) - ((uint) num3)) > uint.MaxValue); if (((uint) num2) >= 0) { goto Label_00A4; } goto Label_003F; Label_0125: if (((uint) num2) >= 0) { return is2; } goto Label_005B; Label_013C: num6 = dcsv.GetDouble("volume"); data = new LoadedMarketData(time, ticker); if ((((uint) num2) | 2) == 0) { goto Label_017C; } goto Label_00B0; Label_016E: num2 = dcsv.GetDouble("open"); Label_017C: num3 = dcsv.GetDouble("close"); num4 = dcsv.GetDouble("high"); num5 = dcsv.GetDouble("low"); goto Label_013C; Label_01AF: time = dcsv.GetDate("date"); num = dcsv.GetDouble("adj close"); if ((((uint) num3) + ((uint) num6)) <= uint.MaxValue) { goto Label_016E; } goto Label_00B0; } }
/// <derived/> public ICollection<LoadedMarketData> Load(TickerSymbol ticker, IList<MarketDataType> dataNeeded, DateTime from, DateTime to) { try { string fileCSV = ""; foreach (TickerSymbol tickerSymbol in fileList.Keys) { if (tickerSymbol.Symbol.ToLower().Equals(ticker.Symbol.ToLower())) { if (fileList.TryGetValue(tickerSymbol, out fileCSV)) { return File.Exists(fileCSV) ? (ReadAndCallLoader(tickerSymbol, dataNeeded, from, to, fileCSV)) : null; //If file does not exist } return null; //Problem reading list } } return null; //if ticker is not defined } catch (FileNotFoundException fnfe) { Console.WriteLine("Problem with loading data for instruments", fnfe); return null; } }
/// <summary> /// Construct a MarketDataDescription item. /// </summary> /// <param name="ticker">The ticker symbol to use.</param> /// <param name="dataType">The data type needed.</param> /// <param name="input">Is this field used for input?</param> /// <param name="predict">Is this field used for prediction?</param> public MarketDataDescription(TickerSymbol ticker, MarketDataType dataType, bool input, bool predict) : this(ticker, dataType, Type.PercentChange, null, input, predict) { }
public ICollection<LoadedMarketData> ReadAndCallLoader(TickerSymbol symbol, IList<MarketDataType> neededTypes, DateTime from, DateTime to, string File) { try { ReadCSV dcsv; DateTime time; double num; double num2; double num3; double num4; double num5; LoadedMarketData data; ICollection<LoadedMarketData> is3; ICollection<LoadedMarketData> is2 = new List<LoadedMarketData>(); goto Label_0109; Label_000B: is3 = is2; if ((((uint) num5) + ((uint) num4)) >= 0) { return is3; } if ((((uint) num3) & 0) == 0) { goto Label_0088; } Label_003D: is2.Add(data); Label_0045: if (dcsv.Next()) { goto Label_00EF; } Label_0050: dcsv.Close(); if (0 == 0) { goto Label_000B; } goto Label_0088; Label_005E: data.SetData(MarketDataType.High, num3); data.SetData(MarketDataType.Low, num4); data.SetData(MarketDataType.Close, num2); data.SetData(MarketDataType.Volume, num5); goto Label_003D; Label_0088: num2 = dcsv.GetDouble("High"); num3 = dcsv.GetDouble("Low"); num4 = dcsv.GetDouble("Close"); num5 = dcsv.GetDouble("Volume"); new LoadedMarketData(time, symbol).SetData(MarketDataType.Open, num); if (((uint) num3) >= 0) { goto Label_005E; } goto Label_003D; Label_00EF: time = dcsv.GetDate("Time"); num = dcsv.GetDouble("Open"); goto Label_0088; Label_0109: dcsv = new ReadCSV(File, true, this.x9c5d9c5f2c877175); if (((uint) num3) > uint.MaxValue) { goto Label_000B; } dcsv.DateFormat = this.x21d82b8f3e4c4642.Normalize(); if (((uint) num3) > uint.MaxValue) { goto Label_0050; } goto Label_0045; } catch (Exception exception) { Console.WriteLine("Something went wrong reading the csv"); Console.WriteLine("Something went wrong reading the csv:" + exception.Message); } Console.WriteLine("Something went wrong reading the csv"); return null; }
private static Uri x38c212309d8d5dd3(TickerSymbol x96e4701dec47675e, DateTime x7f8a886f51b477eb, DateTime x3ed4f4f0195b98d7) { byte[] buffer; MemoryStream os = new MemoryStream(); FormUtility utility = new FormUtility(os, null); utility.Add("s", x96e4701dec47675e.Symbol.ToUpper()); if (0 == 0) { utility.Add("a", (x7f8a886f51b477eb.Month - 1)); utility.Add("b", x7f8a886f51b477eb.Day); if (4 == 0) { goto Label_0018; } utility.Add("c", x7f8a886f51b477eb.Year); utility.Add("d", (x3ed4f4f0195b98d7.Month - 1)); utility.Add("e", x3ed4f4f0195b98d7.Day); utility.Add("f", x3ed4f4f0195b98d7.Year); utility.Add("g", "d"); goto Label_0061; } Label_000B: if (0x7fffffff == 0) { goto Label_0061; } os.Close(); Label_0018: buffer = os.GetBuffer(); return new Uri("http://ichart.finance.yahoo.com/table.csv?" + StringUtil.FromBytes(buffer)); Label_0061: utility.Add("ignore", ".csv"); goto Label_000B; }
public MarketDataDescription(TickerSymbol ticker, MarketDataType dataType, TemporalDataDescription.Type type, IActivationFunction activationFunction, bool input, bool predict) : base(activationFunction, type, input, predict) { this._x96e4701dec47675e = ticker; this._xd2f3d36b96df4542 = dataType; }
public MarketDataDescription(TickerSymbol ticker, MarketDataType dataType, TemporalDataDescription.Type type, bool input, bool predict) : this(ticker, dataType, type, null, input, predict) { }
private void xd619c0bf81b12658(TickerSymbol x96e4701dec47675e, TemporalPoint x2f7096dac971d6ec, LoadedMarketData xccb63ca5f63dc470) { foreach (TemporalDataDescription description in this.Descriptions) { MarketDataDescription description2 = (MarketDataDescription) description; if (description2.Ticker.Equals(x96e4701dec47675e)) { x2f7096dac971d6ec.Data[description2.Index] = xccb63ca5f63dc470.Data[description2.DataType]; } } }
/// <summary> /// Reads and parses CSV data from file /// </summary> /// <param name="ticker">Ticker associated with CSV file</param> /// <param name="neededTypes">Columns to parse (headers)</param> /// <param name="from">DateTime from</param> /// <param name="to">DateTime to</param> /// <param name="File">Filepath to CSV</param> /// <returns>Marketdata</returns> public ICollection<LoadedMarketData> ReadAndCallLoader(TickerSymbol ticker, IList<MarketDataType> neededTypes, DateTime from, DateTime to, string File) { try { LoadedFile = File; Console.WriteLine("Loading instrument: " + ticker.Symbol + " from: " + File); //We got a file, lets load it. ICollection<LoadedMarketData> result = new List<LoadedMarketData>(); ReadCSV csv = new ReadCSV(File, true, LoadedFormat); if (DateTimeDualColumn) { csv.DateFormat = DateFormat; csv.TimeFormat = TimeFormat; } else { csv.DateFormat = DateFormat; } //"Date","Time","Open","High","Low","Close","Volume" while (csv.Next()) { string datetime = ""; if (DateTimeDualColumn) { datetime = csv.GetDate("Date").ToShortDateString() + " " + csv.GetTime("Time").ToShortTimeString(); } else { datetime = csv.GetDate("Date").ToShortDateString(); } DateTime date = DateTime.Parse(datetime); if (date > from && date < to) { // CSV columns double open = csv.GetDouble("Open"); double high = csv.GetDouble("High"); double low = csv.GetDouble("Low"); double close = csv.GetDouble("Close"); double volume = csv.GetDouble("Volume"); LoadedMarketData data = new LoadedMarketData(date, ticker); foreach (MarketDataType marketDataType in neededTypes) { switch (marketDataType.ToString()) { case "Open": data.SetData(MarketDataType.Open, open); break; case "High": data.SetData(MarketDataType.High, high); break; case "Low": data.SetData(MarketDataType.Low, low); break; case "Close": data.SetData(MarketDataType.Close, close); break; case "Volume": data.SetData(MarketDataType.Volume, volume); break; case "RangeHighLow": data.SetData(MarketDataType.RangeHighLow, Math.Round(Math.Abs(high - low), 6)); break; case "RangeOpenClose": data.SetData(MarketDataType.RangeOpenClose, Math.Round(Math.Abs(close - open), 6)); break; case "RangeOpenCloseNonAbsolute": data.SetData(MarketDataType.RangeOpenCloseNonAbsolute, Math.Round(close - open, 6)); break; case "Weighted": data.SetData(MarketDataType.Weighted, Math.Round((high + low + 2 * close) / 4, 6)); break; } } result.Add(data); } } csv.Close(); return result; } catch (Exception ex) { Console.WriteLine("Something went wrong reading the csv: " + ex.Message); } return null; }
public void MarketData() { IMarketLoader loader = new YahooFinanceLoader(); var tickerAAPL = new TickerSymbol("AAPL", null); var tickerMSFT = new TickerSymbol("MSFT", null); var marketData = new MarketMLDataSet(loader, 5, 1); marketData.AddDescription(new MarketDataDescription(tickerAAPL, MarketDataType.Close, true, true)); marketData.AddDescription(new MarketDataDescription(tickerMSFT, MarketDataType.Close, true, false)); marketData.AddDescription(new MarketDataDescription(tickerAAPL, MarketDataType.Volume, true, false)); marketData.AddDescription(new MarketDataDescription(tickerMSFT, MarketDataType.Volume, true, false)); var begin = new DateTime(2008, 7, 1); var end = new DateTime(2008, 7, 31); marketData.Load(begin, end); marketData.Generate(); Assert.AreEqual(22, marketData.Points.Count); // first test the points IEnumerator<TemporalPoint> itr = marketData.Points.GetEnumerator(); itr.MoveNext(); TemporalPoint point = itr.Current; Assert.AreEqual(0, point.Sequence); Assert.AreEqual(4, point.Data.Length); Assert.AreEqual(174.68, point[0]); Assert.AreEqual(26.87, point[1]); Assert.AreEqual(39, (int) (point[2]/1000000)); Assert.AreEqual(100, (int) (point[3]/1000000)); itr.MoveNext(); point = itr.Current; Assert.AreEqual(1, point.Sequence); Assert.AreEqual(4, point.Data.Length); Assert.AreEqual(168.18, point[0]); Assert.AreEqual(25.88, point[1]); Assert.AreEqual(29, (int) (point[2]/1000000)); Assert.AreEqual(84, (int) (point[3]/1000000)); itr.MoveNext(); point = itr.Current; Assert.AreEqual(2, point.Sequence); Assert.AreEqual(4, point.Data.Length); Assert.AreEqual(170.12, point[0]); Assert.AreEqual(25.98, point[1]); Assert.AreEqual(18, (int) (point[2]/1000000)); Assert.AreEqual(37, (int) (point[3]/1000000)); // now check the actual data Assert.AreEqual(16, marketData.Data.Count); Assert.AreEqual(20, marketData.InputNeuronCount); Assert.AreEqual(1, marketData.OutputNeuronCount); IEnumerator<IMLDataPair> itr2 = marketData.Data.GetEnumerator(); itr2.MoveNext(); IMLDataPair pair = itr2.Current; Assert.AreEqual(20, pair.Input.Count); Assert.AreEqual(1, pair.Ideal.Count); Assert.AreEqual(-0.037, Math.Round(pair.Input[0]*1000.0)/1000.0); Assert.AreEqual(-0.037, Math.Round(pair.Input[1]*1000.0)/1000.0); Assert.AreEqual(-0.246, Math.Round(pair.Input[2]*1000.0)/1000.0); Assert.AreEqual(-0.156, Math.Round(pair.Input[3]*1000.0)/1000.0); Assert.AreEqual(0.012, Math.Round(pair.Input[4]*1000.0)/1000.0); Assert.AreEqual(0.0040, Math.Round(pair.Input[5]*1000.0)/1000.0); Assert.AreEqual(-0.375, Math.Round(pair.Input[6]*1000.0)/1000.0); Assert.AreEqual(-0.562, Math.Round(pair.Input[7]*1000.0)/1000.0); Assert.AreEqual(0.03, Math.Round(pair.Input[8]*1000.0)/1000.0); Assert.AreEqual(0.0020, Math.Round(pair.Input[9]*1000.0)/1000.0); Assert.AreEqual(0.57, Math.Round(pair.Input[10]*100.0)/100.0); Assert.AreEqual(0.929, Math.Round(pair.Input[11]*1000.0)/1000.0); Assert.AreEqual(0.025, Math.Round(pair.Input[12]*1000.0)/1000.0); Assert.AreEqual(-0.0070, Math.Round(pair.Input[13]*1000.0)/1000.0); // for some reason, Yahoo likes to vary the volume numbers slightly, sometimes! Assert.AreEqual(0.1, Math.Round(pair.Input[14]*10.0)/10.0); Assert.AreEqual(-0.084, Math.Round(pair.Input[15]*1000.0)/1000.0); Assert.AreEqual(-0.03, Math.Round(pair.Input[16]*1000.0)/1000.0); Assert.AreEqual(-0.024, Math.Round(pair.Input[17]*1000.0)/1000.0); Assert.AreEqual(0.008, Math.Round(pair.Input[18]*1000.0)/1000.0); Assert.AreEqual(-0.172, Math.Round(pair.Input[19]*1000.0)/1000.0); itr2.MoveNext(); pair = itr2.Current; Assert.AreEqual(20, pair.Input.Count); Assert.AreEqual(1, pair.Ideal.Count); Assert.AreEqual(0.012, Math.Round(pair.Input[0]*1000.0)/1000.0); Assert.AreEqual(0.0040, Math.Round(pair.Input[1]*1000.0)/1000.0); Assert.AreEqual(-0.375, Math.Round(pair.Input[2]*1000.0)/1000.0); Assert.AreEqual(-0.562, Math.Round(pair.Input[3]*1000.0)/1000.0); Assert.AreEqual(0.03, Math.Round(pair.Input[4]*1000.0)/1000.0); Assert.AreEqual(0.0020, Math.Round(pair.Input[5]*1000.0)/1000.0); Assert.AreEqual(0.6, Math.Round(pair.Input[6]*10.0)/10.0); Assert.AreEqual(0.929, Math.Round(pair.Input[7]*1000.0)/1000.0); Assert.AreEqual(0.025, Math.Round(pair.Input[8]*1000.0)/1000.0); Assert.AreEqual(-0.0070, Math.Round(pair.Input[9]*1000.0)/1000.0); Assert.AreEqual(0.1, Math.Round(pair.Input[10]*10.0)/10.0); Assert.AreEqual(-0.084, Math.Round(pair.Input[11]*1000.0)/1000.0); Assert.AreEqual(-0.03, Math.Round(pair.Input[12]*1000.0)/1000.0); Assert.AreEqual(-0.024, Math.Round(pair.Input[13]*1000.0)/1000.0); Assert.AreEqual(0.0080, Math.Round(pair.Input[14]*1000.0)/1000.0); Assert.AreEqual(-0.172, Math.Round(pair.Input[15]*1000.0)/1000.0); Assert.AreEqual(0.014, Math.Round(pair.Input[16]*1000.0)/1000.0); Assert.AreEqual(0.0090, Math.Round(pair.Input[17]*1000.0)/1000.0); Assert.AreEqual(-0.1, Math.Round(pair.Input[18]*10.0)/10.0); Assert.AreEqual(0.066, Math.Round(pair.Input[19]*1000.0)/1000.0); }
/// <summary> /// Load one ticker symbol. /// </summary> /// <param name="ticker">The ticker symbol to load.</param> /// <param name="from">Load data from this date.</param> /// <param name="to">Load data to this date.</param> private void LoadSymbol(TickerSymbol ticker, DateTime from, DateTime to) { ICollection<LoadedMarketData> data = Loader.Load(ticker, null, from, to); foreach (LoadedMarketData item in data) { TemporalPoint point = CreatePoint(item.When); LoadPointFromMarketData(ticker, point, item); } }
public ICollection<LoadedMarketData> Load(TickerSymbol ticker, IList<MarketDataType> dataNeeded, DateTime from, DateTime to) { CSVFormLoader loader; ICollection<LoadedMarketData> is2 = new List<LoadedMarketData>(); if (0 == 0) { loader = new CSVFormLoader(); if ((0 == 0) && !File.Exists(loader.Chosenfile)) { return null; } } this.x9c5d9c5f2c877175 = loader.format; foreach (MarketDataType type in loader.TypesLoaded) { this.TypesLoaded.Add(type); } this.x21d82b8f3e4c4642 = loader.DateTimeFormatTextBox.Text; return this.ReadAndCallLoader(ticker, dataNeeded, from, to, loader.Chosenfile); }
/// <summary> /// Called to load training data for a company. This is how the training data is actually created. /// To prepare input data for recognition use the CreateData method. The training set will be /// added to. This allows the network to learn from multiple companies if this method is called /// multiple times. /// </summary> /// <param name="symbol">The ticker symbol.</param> /// <param name="training">The training set to add to.</param> /// <param name="from">Beginning date</param> /// <param name="to">Ending date</param> public void LoadCompany(String symbol, BasicMLDataSet training, DateTime from, DateTime to) { IMarketLoader loader = new YahooFinanceLoader(); TickerSymbol ticker = new TickerSymbol(symbol); IList<MarketDataType> dataNeeded = new List<MarketDataType>(); dataNeeded.Add(MarketDataType.AdjustedClose); dataNeeded.Add(MarketDataType.Close); dataNeeded.Add(MarketDataType.Open); dataNeeded.Add(MarketDataType.High); dataNeeded.Add(MarketDataType.Low); List<LoadedMarketData> results = (List<LoadedMarketData>)loader.Load(ticker, dataNeeded, from, to); results.Sort(); for (int index = PredictWindow; index < results.Count - EvalWindow; index++) { LoadedMarketData data = results[index]; // determine bull or bear position, or neither bool bullish = false; bool bearish = false; for (int search = 1; search <= EvalWindow; search++) { LoadedMarketData data2 = results[index + search]; double priceBase = data.GetData(MarketDataType.AdjustedClose); double priceCompare = data2.GetData(MarketDataType.AdjustedClose); double diff = priceCompare - priceBase; double percent = diff / priceBase; if (percent > BullPercent) { bullish = true; } else if (percent < BearPercent) { bearish = true; } } IMLDataPair pair = null; if (bullish) { pair = CreateData(results, index, true); } else if (bearish) { pair = CreateData(results, index, false); } if (pair != null) { training.Add(pair); } } }