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: SciChart.Examples.ExternalDependencies.Resources.Data.EURUSD_Daily.csv var csvResource = string.Format("{0}.{1}", ResourceDirectory, Path.ChangeExtension(dataset, "csv.gz")); var priceSeries = new PriceSeries(); priceSeries.Symbol = dataset; var assembly = typeof(DataManager).Assembly; // Debug.WriteLine(string.Join(", ", assembly.GetManifestResourceNames())); using (var stream = assembly.GetManifestResourceStream(csvResource)) using (var gz = new GZipStream(stream, CompressionMode.Decompress)) using (var streamReader = new StreamReader(gz)) { 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 var 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); }
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 TradeFrequency = 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 % TradeFrequency == 0) { var trade = new Trade(); // randomize buy or sell trade.BuySell = _random.NextDouble() > 0.48 ? BuySell.Buy : BuySell.Sell; // Set dealprice and date trade.DealPrice = priceSeries[i].Close; trade.TradeDate = priceSeries[i].DateTime; // Set instrument and quantity trade.Instrument = Instrument.CrudeOil; trade.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(); newsEvent.EventDate = priceSeries[i].DateTime; newsEvent.Headline = "OPEC meeting minutes"; newsEvent.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); }