public void SetStats(LoadedMarketData data) { this.open = data.GetData(MarketDataType.Open); this.close = data.GetData(MarketDataType.Close); this.high = data.GetData(MarketDataType.High); this.low = data.GetData(MarketDataType.Low); this.bodyTop = Math.Max(this.open, this.close); this.bodyBottom = Math.Min(this.open, this.close); }
public void Loader() { IMarketLoader loader = new YahooFinanceLoader(); var from = new DateTime(2008, 8, 4); var to = new DateTime(2008, 8, 5); ICollection <LoadedMarketData> list = loader.Load(new TickerSymbol("aapl"), null, from, to); IEnumerator <LoadedMarketData> itr = list.GetEnumerator(); itr.MoveNext(); LoadedMarketData data = itr.Current; Assert.AreEqual(160, (int)data.GetData(MarketDataType.Close)); itr.MoveNext(); data = itr.Current; Assert.AreEqual(153, (int)data.GetData(MarketDataType.Close)); }
/// <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); } } }