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);
        }
예제 #2
0
        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 RandomPricesDataSource(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);
        }
        public RandomPricesDataSource(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 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);
         }
     }
 }
        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;
        }
 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;
 }
예제 #9
0
        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;
        }
예제 #10
0
        private void OnNewPrice(PriceBar price)
        {
            // Ensure only one update processed at a time from multi-threaded timer
            lock (this)
            {
                // Update the last price, or append?
                var ds0 = (IOhlcDataSeries<DateTime, double>)_seriesViewModels[0].DataSeries;

                if (_lastPrice != null && _lastPrice.DateTime == price.DateTime)
                {
                    ds0.Update(price.DateTime, price.Open, price.High, price.Low, price.Close);
                }
                else
                {
                    ds0.Append(price.DateTime, price.Open, price.High, price.Low, price.Close);

                    // If the latest appending point is inside the viewport (i.e. not off the edge of the screen)
                    // then scroll the viewport 1 bar, to keep the latest bar at the same place
                    if (XVisibleRange.Max > ds0.Count)
                    {
                        var existingRange = _xVisibleRange;
                        var newRange = new IndexRange(existingRange.Min + 1, existingRange.Max + 1);
                        XVisibleRange = newRange;
                    }
                }

                _lastPrice = price;
            }
        }
        public PriceBar GetNextData()
        {
            PriceBar nextRandomPriceBar = GetNextRandomPriceBar();

            return(nextRandomPriceBar);
        }