public RandomPriceBarsDataSource( int candleIntervalMinutes, bool simulateDateGap, double timerInterval, int updatesPerPrice, int randomSeed, double startingPrice, DateTime startDate) { _candleIntervalMinutes = candleIntervalMinutes; _simulateDateGap = simulateDateGap; _updatesPerPrice = updatesPerPrice; _timer = new Timer(timerInterval) { Enabled = false, AutoReset = true, }; _timer.Elapsed += TimerElapsed; _initialPriceBar = new PriceBarInfo { Close = startingPrice, DateTime = startDate }; _lastPriceBar = new PriceBar( _initialPriceBar.DateTime, _initialPriceBar.Close, _initialPriceBar.Close, _initialPriceBar.Close, _initialPriceBar.Close, 0L); _random = new Random(randomSeed); }
private PriceBar GetUpdatedData() { double num = _lastPriceBar.Close + ((_random.NextDouble() - 0.48) * (_lastPriceBar.Close / 100.0)); double high = (num > _lastPriceBar.High) ? num : _lastPriceBar.High; double low = (num < _lastPriceBar.Low) ? num : _lastPriceBar.Low; long volumeInc = (long)((_random.NextDouble() * 30000 + 20000) * 0.05); _lastPriceBar = new PriceBar(_lastPriceBar.DateTime, _lastPriceBar.Open, high, low, num, _lastPriceBar.Volume + volumeInc); return(_lastPriceBar); }
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 GetNextRandomPriceBar() { double close = _lastPriceBar.Close; double num = (_random.NextDouble() - 0.9) * _initialPriceBar.Close / 30.0; double num2 = _random.NextDouble(); double num3 = _initialPriceBar.Close + _initialPriceBar.Close / 2.0 * Math.Sin(7.27220521664304E-06 * _currentTime) + _initialPriceBar.Close / 16.0 * Math.Cos(7.27220521664304E-05 * _currentTime) + _initialPriceBar.Close / 32.0 * Math.Sin(7.27220521664304E-05 * (10.0 + num2) * _currentTime) + _initialPriceBar.Close / 64.0 * Math.Cos(7.27220521664304E-05 * (20.0 + num2) * _currentTime) + num; double num4 = Math.Max(close, num3); double num5 = _random.NextDouble() * _initialPriceBar.Close / 100.0; double high = num4 + num5; double num6 = Math.Min(close, num3); double num7 = _random.NextDouble() * _initialPriceBar.Close / 100.0; double low = num6 - num7; long volume = (long)(_random.NextDouble() * 30000 + 20000); DateTime openTime = _simulateDateGap ? EmulateDateGap(_lastPriceBar.DateTime) : _lastPriceBar.DateTime; DateTime closeTime = openTime.AddMinutes(_candleIntervalMinutes); PriceBar candle = new PriceBar(closeTime, close, high, low, num3, volume); _lastPriceBar = new PriceBar(candle.DateTime, candle.Open, candle.High, candle.Low, candle.Close, volume); _currentTime += _candleIntervalMinutes * 60; return(candle); }
private void OnTimerElapsed() { if (_currentUpdateCount < _updatesPerPrice) { _currentUpdateCount++; PriceBar updatedData = GetUpdatedData(); if (UpdateData != null) { UpdateData(updatedData); } } else { _currentUpdateCount = 0; PriceBar nextData = GetNextData(); if (NewData != null) { NewData(nextData); } } }
public PriceBar GetNextData() { PriceBar nextRandomPriceBar = GetNextRandomPriceBar(); return(nextRandomPriceBar); }