public DoubleSeries GetDampedSinewave(int pad, double amplitude, double phase, double dampingFactor, int pointCount, int freq = 10) { var doubleSeries = new DoubleSeries(); for (int i = 0; i < pad; i++) { double time = 10 * i / (double)pointCount; doubleSeries.Add(new XYPoint() { X = time }); } for (int i = pad, j = 0; i < pointCount; i++, j++) { var xyPoint = new XYPoint(); double time = 10 * i / (double)pointCount; double wn = 2 * Math.PI / (pointCount / (double)freq); xyPoint.X = time; xyPoint.Y = amplitude * Math.Sin(j * wn + phase); doubleSeries.Add(xyPoint); amplitude *= (1.0 - dampingFactor); } return(doubleSeries); }
public DoubleSeries GetClusteredPoints(double xCentre, double yCentre, double deviation, int count) { var doubleSeries = new DoubleSeries(); for (int i = 0; i < count; i++) { double x = GetGaussianRandomNumber(xCentre, deviation); double y = GetGaussianRandomNumber(yCentre, deviation); doubleSeries.Add(new XYPoint() { X = x, Y = y }); } return(doubleSeries); }
public DoubleSeries GetStraightLine(double gradient, double yIntercept, int pointCount) { var doubleSeries = new DoubleSeries(pointCount); for (int i = 0; i <= pointCount; i++) { double x = i + 1; double y = gradient * x + yIntercept; doubleSeries.Add(new XYPoint() { X = x, Y = y }); } return(doubleSeries); }
public DoubleSeries GetRandomDoubleSeries(int pointCount) { var doubleSeries = new DoubleSeries(); double amplitude = _random.NextDouble() + 0.5; double freq = Math.PI * (_random.NextDouble() + 0.5) * 10; double offset = _random.NextDouble() - 0.5; for (int i = 0; i < pointCount; i++) { doubleSeries.Add(new XYPoint() { X = i, Y = offset + amplitude * Math.Sin(freq * i) }); } return(doubleSeries); }
public DoubleSeries GetLissajousCurve(double alpha, double beta, double delta, int count = 200) { // From http://en.wikipedia.org/wiki/Lissajous_curve // x = Asin(at + d), y = Bsin(bt) var doubleSeries = new DoubleSeries(count); for (int i = 0; i < count; i++) { double x = Math.Sin(alpha * i * 0.1 + delta); double y = Math.Sin(beta * i * 0.1); doubleSeries.Add(new XYPoint() { X = x, Y = y }); } return(doubleSeries); }
public DoubleSeries GetExponentialCurve(double power, int pointCount) { var doubleSeries = new DoubleSeries(pointCount); double x = 0.00001; const double fudgeFactor = 1.4; for (int i = 0; i < pointCount; i++) { x *= fudgeFactor; double y = Math.Pow((double)i + 1, power); doubleSeries.Add(new XYPoint() { X = x, Y = y }); } return(doubleSeries); }
/* * 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 DoubleSeries GenerateSpiral(double xCentre, double yCentre, double maxRadius, int count) { var doubleSeries = new DoubleSeries(); double radius = 0; double x, y; double deltaRadius = maxRadius / count; for (int i = 0; i < count; i++) { double sinX = Math.Sin(2 * Math.PI * i * 0.05); double cosX = Math.Cos(2 * Math.PI * i * 0.05); x = xCentre + radius * sinX; y = yCentre + radius * cosX; doubleSeries.Add(new XYPoint() { X = x, Y = y }); radius += deltaRadius; } return(doubleSeries); }
public DoubleSeries GenerateEEG(int count, ref double startPhase, double phaseStep) { var doubleSeries = new DoubleSeries(); var rand = new Random((int)DateTime.Now.Ticks); for (int i = 0; i < count; i++) { var xyPoint = new XYPoint(); var time = i / (double)count; xyPoint.X = time; //double mod = 0.2 * Math.Sin(startPhase); xyPoint.Y = //mod * Math.Sin(startPhase / 4.9) + 0.05 * (rand.NextDouble() - 0.5) + 1.0; doubleSeries.Add(xyPoint); startPhase += phaseStep; } return(doubleSeries); }
public DoubleSeries GetSquirlyWave() { var doubleSeries = new DoubleSeries(); var rand = new Random((int)DateTime.Now.Ticks); const int COUNT = 1000; for (int i = 0; i < COUNT; i++) { var xyPoint = new XYPoint(); var time = i / (double)COUNT; xyPoint.X = time; xyPoint.Y = time * Math.Sin(2 * Math.PI * i / (double)COUNT) + 0.2 * Math.Sin(2 * Math.PI * i / (COUNT / 7.9)) + 0.05 * (rand.NextDouble() - 0.5) + 1.0; doubleSeries.Add(xyPoint); } return(doubleSeries); }
public DoubleSeries GetFourierSeriesZoomed(double amplitude, double phaseShift, double xStart, double xEnd, int count = 5000) { var data = GetFourierSeries(amplitude, phaseShift, count); int index0 = 0; int index1 = 0; for (int i = 0; i < count; i++) { if (data.XData[i] > xStart && index0 == 0) { index0 = i; } if (data.XData[i] > xEnd && index1 == 0) { index1 = i; break; } } var result = new DoubleSeries(); var xData = data.XData.Skip(index0).Take(index1 - index0).ToArray(); var yData = data.YData.Skip(index0).Take(index1 - index0).ToArray(); for (int i = 0; i < xData.Length; i++) { result.Add(new XYPoint() { X = xData[i], Y = yData[i] }); } return(result); }
public DoubleSeries GetFourierSeries(double amplitude, double phaseShift, int count = 5000) { var doubleSeries = new DoubleSeries(); for (int i = 0; i < count; i++) { var xyPoint = new XYPoint(); double time = 10 * i / (double)count; double wn = 2 * Math.PI / (count / 10); xyPoint.X = time; xyPoint.Y = Math.PI * amplitude * (Math.Sin(i * wn + phaseShift) + 0.33 * Math.Sin(i * 3 * wn + phaseShift) + 0.20 * Math.Sin(i * 5 * wn + phaseShift) + 0.14 * Math.Sin(i * 7 * wn + phaseShift) + 0.11 * Math.Sin(i * 9 * wn + phaseShift) + 0.09 * Math.Sin(i * 11 * wn + phaseShift)); doubleSeries.Add(xyPoint); } return(doubleSeries); }