public PriceSeries Clip(int startIndex, int endIndex) { var result = new PriceSeries(endIndex - startIndex); for (int i = startIndex; i < endIndex; i++) { result.Add(this[i]); } return(result); }
public PriceSeries GetPriceData(string dataset) { if (_dataSets.ContainsKey(dataset)) { return(_dataSets[dataset]); } // e.g. resource format: Abt.Controls.SciChart.Example.Resources.EURUSD_Daily.csv string csvResource = $"{ResourceDirectory}.{Path.ChangeExtension(dataset, "csv")}"; var priceSeries = new PriceSeries { Symbol = dataset }; Assembly assembly = typeof(DataManager).Assembly; // Debug.WriteLine(string.Join(", ", assembly.GetManifestResourceNames())); using (Stream stream = assembly.GetManifestResourceStream(csvResource)) { Debug.Assert(stream != null, "stream != null"); using (var streamReader = new StreamReader(stream)) { string line = streamReader.ReadLine(); while (line != null) { var priceBar = new PriceBar(); // Line Format: // Date, Open, High, Low, Close, Volume // 2007.07.02 03:30, 1.35310, 1.35310, 1.35280, 1.35310, 12 string[] tokens = line.Split(','); priceBar.DateTime = DateTime.Parse(tokens[0], DateTimeFormatInfo.InvariantInfo); priceBar.Open = double.Parse(tokens[1], NumberFormatInfo.InvariantInfo); priceBar.High = double.Parse(tokens[2], NumberFormatInfo.InvariantInfo); priceBar.Low = double.Parse(tokens[3], NumberFormatInfo.InvariantInfo); priceBar.Close = double.Parse(tokens[4], NumberFormatInfo.InvariantInfo); priceBar.Volume = long.Parse(tokens[5], NumberFormatInfo.InvariantInfo); priceSeries.Add(priceBar); line = streamReader.ReadLine(); } } } _dataSets.Add(dataset, priceSeries); return(priceSeries); }
private PriceBar Next(PriceSeries priceSeries) { return(priceSeries[_currentIndex++]); }
public PriceSeries GetRandomTrades(out List <Trade> trades, out List <NewsEvent> news) { var priceSeries = new PriceSeries(); trades = new List <Trade>(); news = new List <NewsEvent>(); var startDate = new DateTime(2012, 01, 01); double randomWalk = 0.0; // Note: Change the value below to increase or decrease the point count and trade frequency const int COUNT = 1000; const uint TRADE_FREQUENCY = 14; // Generate the X,Y data with sequential dates on the X-Axis and slightly positively biased random walk on the Y-Axis for (int i = 0; i < COUNT; i++) { randomWalk += _random.NextDouble() - 0.498; priceSeries.Add(new PriceBar(startDate.AddMinutes(i * 10), randomWalk, randomWalk, randomWalk, randomWalk, 0)); } // The random walk is a truly random series, so it may contain negative values. Here we find the minimum and offset it // so it is always positive. double yOffset = -priceSeries.CloseData.Min() + _random.NextDouble(); for (int i = 0; i < COUNT; i++) { // Now update with the offset so it is never negative priceSeries[i].Close += yOffset; // Every N'th tick create a random trade if (i % TRADE_FREQUENCY == 0) { var trade = new Trade { // randomize buy or sell BuySell = _random.NextDouble() > 0.48 ? BuySell.Buy : BuySell.Sell, // Set dealprice and date DealPrice = priceSeries[i].Close, TradeDate = priceSeries[i].DateTime, // Set instrument and quantity Instrument = Instrument.CrudeOil, Quantity = _random.Next(100, 500) }; trades.Add(trade); } // Every N'th tick create a random news event if (_random.Next(0, 99) > 95) { var newsEvent = new NewsEvent { EventDate = priceSeries[i].DateTime, Headline = "OPEC meeting minutes", Body = "The Organization of the Petroleum Exporting Countries voted today to increase production of Crude oil from its member states" }; news.Add(newsEvent); } } return(priceSeries); }