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; }
public PriceSeries GetPriceData(string dataset) { if (_dataSets.ContainsKey(dataset)) { return _dataSets[dataset]; } // e.g. resource format: Abt.Controls.SciChart.Example.Resources.EURUSD_Daily.csv var csvResource = string.Format("{0}.{1}", ResourceDirectory, Path.ChangeExtension(dataset, "csv")); 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 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 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 static PriceSeries GetPriceDataByTimeFrame(List <Tick> ticks, int timeFrame, IDiscontinuousDateTimeCalendar calendar, out Tuple <DateTime, double> min, out Tuple <DateTime, double> max) { var priceSeries = new PriceSeries(); var dateTime = ticks[0].DateTime; min = null; max = null; double open = 0; double high = 0; double low = 0; double close = 0; long volume = 0; bool hasTicks = false; for (int i = 0; i < ticks.Count; i++) { if (ticks[i].DateTime < dateTime + TimeSpan.FromMinutes(timeFrame)) { if (!calendar.IsValueInGap(ticks[i].DateTime)) { if (!hasTicks) { high = ticks[i].High; low = ticks[i].Low; open = ticks[i].Open; hasTicks = true; } else { high = high < ticks[i].High ? ticks[i].High : high; low = low > ticks[i].Low ? ticks[i].Low : low; } close = ticks[i].Close; volume += ticks[i].Volume; } } else { if (hasTicks) { var priceBar = new PriceBar { DateTime = dateTime, Open = open, High = high, Low = low, Close = close, Volume = volume }; priceSeries.Add(priceBar); if (priceSeries.Count == 1) { min = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.Low); max = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.High); } else { if (priceBar.High > max.Item2) { max = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.High); } if (priceBar.Low < min.Item2) { min = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.Low); } } hasTicks = false; } else { dateTime = dateTime + TimeSpan.FromMinutes(timeFrame); } } } 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); }
public static PriceSeries GetPriceDataByRange(List <Tick> ticks, double rangeCount, IDiscontinuousDateTimeCalendar calendar, double barTimeFrame, out Tuple <DateTime, double> min, out Tuple <DateTime, double> max) { var priceSeries = new PriceSeries(); var dateTime = new DateTime(); min = null; max = null; double open = 0; double high = 0; double low = 0; double close = 0; long volume = 0; double range = 0; bool hasTicks = false; for (int i = 0; i < ticks.Count; i++) { if (Math.Abs(range) < rangeCount) { if (!calendar.IsValueInGap(ticks[i].DateTime)) { if (!hasTicks) { high = ticks[i].High; low = ticks[i].Low; open = ticks[i].Open; if (priceSeries.Count == 0) { dateTime = ticks[i].DateTime; } hasTicks = true; } else { high = high < ticks[i].High ? ticks[i].High : high; low = low > ticks[i].Low ? ticks[i].Low : low; } volume += ticks[i].Volume; range = high - low; close = ticks[i].Close > open ? low + rangeCount : high - rangeCount; } } else if (hasTicks) { if (range / rangeCount > 2) { for (int j = 0; j < range / rangeCount; j++) { var priceBar = new PriceBar { DateTime = calendar.GetValueByOffset(dateTime, priceSeries.Count * barTimeFrame), Open = ticks[i].Close > open ? open + j * rangeCount : open - j * rangeCount, High = ticks[i].Close > open ? open + j * rangeCount : open - j * rangeCount, Low = ticks[i].Close > open ? open + j * rangeCount : open - (j + 1) * rangeCount, Close = ticks[i].Close > open ? open + j * rangeCount : open - (j + 1) * rangeCount, Volume = volume }; priceSeries.Add(priceBar); if (priceSeries.Count == 1) { min = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.Low); max = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.High); } else { if (priceBar.High > max.Item2) { max = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.High); } if (priceBar.Low < min.Item2) { min = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.Low); } } } } else { var priceBar = new PriceBar { DateTime = calendar.GetValueByOffset(dateTime, priceSeries.Count * barTimeFrame), Open = open, High = high, Low = low, Close = close, Volume = volume }; priceSeries.Add(priceBar); if (priceSeries.Count == 1) { min = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.Low); max = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.High); } else { if (priceBar.High > max.Item2) { max = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.High); } if (priceBar.Low < min.Item2) { min = new Tuple <DateTime, double>(priceBar.DateTime, priceBar.Low); } } } range = 0; hasTicks = false; } } return(priceSeries); }