public void Update(Bar bar) { dsDayCl.Add(bar.DateTime, daycl); dsDayPv.Add(bar.DateTime, dayPv); dsDayR1.Add(bar.DateTime, dayR1); dsDayR2.Add(bar.DateTime, dayR2); dsDayR3.Add(bar.DateTime, dayR3); dsDayS1.Add(bar.DateTime, dayS1); dsDayS2.Add(bar.DateTime, dayS2); dsDayS3.Add(bar.DateTime, dayS3); dsWeekPv.Add(bar.DateTime, weekPv); dsWeekR1.Add(bar.DateTime, weekR1); dsWeekR2.Add(bar.DateTime, weekR2); dsWeekR3.Add(bar.DateTime, weekR3); dsWeekS1.Add(bar.DateTime, weekS1); dsWeekS2.Add(bar.DateTime, weekS2); dsWeekS3.Add(bar.DateTime, weekS3); dsMonPv.Add(bar.DateTime, monPv); dsMonR1.Add(bar.DateTime, monR1); dsMonR2.Add(bar.DateTime, monR2); dsMonR3.Add(bar.DateTime, monR3); dsMonS1.Add(bar.DateTime, monS1); dsMonS2.Add(bar.DateTime, monS2); dsMonS3.Add(bar.DateTime, monS3); dsSma20Day.Add(bar.DateTime, sma20day); dsSma200Day.Add(bar.DateTime, sma200day); }
void slopeItemAddedEventHandler(object sender, DateTimeEventArgs e) { double val = (slopeAvg.dsSlope.Last - m_SlopeAvgScaleMin) / (m_SlopeAvgScaleMax - m_SlopeAvgScaleMin); dsSlopeAvg.Add(e.DateTime, val); accelAvg.Add(e.DateTime, val); }
protected void CalcStats(DateTime dt) { rs.CalcStats(); //dsAccel.Add( dtLast, b2 * 10000.0 ); dsSlope.Add(dt, rs.b1); dsRR.Add(dt, rs.RR); //dsSD.Add( dtLast, SD ); dsAvg.Add(dt, rs.meanY); }
void accelItemAddedEventHandler(object sender, DateTimeEventArgs e) { double val = accelAvg.dsSlope.Last; double tmp = (val - m_AccelAvgScaleMin) / (m_AccelAvgScaleMax - m_AccelAvgScaleMin); tmp = Math.Min(tmp, 1.25); tmp = Math.Max(tmp, -0.25); dsAccelAvg.Add(e.DateTime, tmp); }
public override DoubleSeries GetNegativeSeries() { DoubleSeries ds = new DoubleSeries(); for (int i = this.fFirstIndex; i < this.fLastIndex; ++i) { if (this[i] < 0.0) { ds.Add(this.GetDateTime(i), this[i]); } } return(ds); }
public void Add(Quote quote) { if (0 == values.Count) { dtUnique = quote.DateTime; firstTimeTick = quote.DateTime.Ticks; } else { dtUnique = (quote.DateTime > dtUnique) ? quote.DateTime : dtUnique + ms; } Add(dtUnique, quote.Bid); Add(dtUnique, quote.Ask); //Console.WriteLine( "{0} Added {1:#.00} {2:#.00} {3:#.00} {4}", dt, val, Min, Max, dsPoints.Count ); UpdateWindow(); CalcStats(quote.DateTime); if (!double.IsNaN(rs.b1) && !double.IsPositiveInfinity(rs.b1) && !double.IsNegativeInfinity(rs.b1)) { slopeAvg.Add(dtUnique, rs.meanY); double upper = rs.meanY + BBMultiplier * rs.SD; double lower = rs.meanY - BBMultiplier * rs.SD; dsBBUpper.Add(dtUnique, upper); dsBBLower.Add(dtUnique, lower); double tmp = (quote.Bid + quote.Ask) / 2; double avgquote = 0; if (tmp == rs.meanY) { avgquote = tmp; } else { if (tmp > rs.meanY) { avgquote = quote.Ask; } if (tmp < rs.meanY) { avgquote = quote.Bid; } } dsB.Add(dtUnique, (avgquote - lower) / (upper - lower)); double bw = 1000.0 * (upper - lower) / rs.meanY; dsBandwidth.Add(dtUnique, bw / m_bbwMax); } //Console.WriteLine( "{0} Added {1} {2} {3} {4} {5}", dtUnique, Xcnt, b1, b0, R, dsSlope.Name ); }
protected override void OnUpdateChart(ICollection <IDataObject> objects) { DoubleSeries doubleSeries = new DoubleSeries("Trade"); using (IEnumerator <IDataObject> enumerator = ((IEnumerable <IDataObject>)objects).GetEnumerator()) { while (((IEnumerator)enumerator).MoveNext()) { Trade trade = (Trade)enumerator.Current; doubleSeries.Add(trade.DateTime, trade.Price); } } ((TimeSeries)doubleSeries).Draw(Color.Black); }
public static double Value(TimeSeries input, int index, int length1, int length2) { if (index < length1 - 1 + input.FirstIndex || index < length2 - 1 + input.FirstIndex) { return(double.NaN); } DoubleSeries doubleSeries = new DoubleSeries(); for (int index1 = index; index1 > index - Math.Max(length1, length2); --index1) { doubleSeries.Add(input.GetDateTime(index1), input[index1, BarData.Volume]); } return(SMA.Value((TimeSeries)doubleSeries, length1 - 1, length1, BarData.Close) - SMA.Value((TimeSeries)doubleSeries, length2 - 1, length2, BarData.Close)); }
public override DoubleSeries GetPercentReturnSeries() { DoubleSeries ds = new DoubleSeries(this.Name, this.Title); if (this.fRealCount > 1) { double t0 = this[0]; for (int i = this.fFirstIndex; i < this.fLastIndex; ++i) { DateTime dt = this.GetDateTime(i); double t1 = this[i]; if (t0 != 0.0) { ds.Add(dt, (t1 / t0 - 1.0) * 100.0); } else { ds.Add(dt, 0.0); } t0 = t1; } } return(ds); }
public static double Value(TimeSeries input, int index, int length, BarData option) { if (index < 1 + input.FirstIndex) { return(double.NaN); } DoubleSeries doubleSeries = new DoubleSeries(); for (int firstIndex = input.FirstIndex; firstIndex <= index; ++firstIndex) { doubleSeries.Add(input.GetDateTime(firstIndex), input[firstIndex, option]); } EMA ema = new EMA((TimeSeries) new EMA((TimeSeries) new EMA((TimeSeries)doubleSeries, length, option), length, option), length, option); return((ema[index - input.FirstIndex] - ema[index - 1 - input.FirstIndex]) / ema[index - 1 - input.FirstIndex] * 100.0); }
public static double Value(TimeSeries input, int index, int length1, int length2) { if (index < length2 - 1 + input.FirstIndex) { return(double.NaN); } DoubleSeries doubleSeries = new DoubleSeries(); for (int index1 = 0; index1 <= index; ++index1) { doubleSeries.Add(input.GetDateTime(index1), input[index1, BarData.High] - input[index1, BarData.Low]); } EMA ema = new EMA((TimeSeries)doubleSeries, length1, BarData.Close); return((ema[index] - ema[index - length2 + 1]) / ema[index - length2 + 1] * 100.0); }
protected override void OnUpdateChart(ICollection <IDataObject> objects) { DoubleSeries doubleSeries1 = new DoubleSeries("Bid"); DoubleSeries doubleSeries2 = new DoubleSeries("Ask"); using (IEnumerator <IDataObject> enumerator = ((IEnumerable <IDataObject>)objects).GetEnumerator()) { while (((IEnumerator)enumerator).MoveNext()) { Quote quote = (Quote)enumerator.Current; doubleSeries1.Add(quote.DateTime, quote.Bid); doubleSeries2.Add(quote.DateTime, quote.Ask); } } ((TimeSeries)doubleSeries1).Draw(Color.Blue); ((TimeSeries)doubleSeries2).Draw(Color.Red); }
public DoubleSeries GetRandomWalkSeries(int count) { var doubleSeries = new DoubleSeries(count); // Generate a slightly positive biased random walk // y[i] = y[i-1] + random, // where random is in the range -0.5, +0.5 for(int i = 0; i < count; i++) { double next = _last + (_random.NextDouble() - 0.5 + _bias); _last = next; doubleSeries.Add(new XYPoint() { X = _i++, Y = next}); } return doubleSeries; }
private DoubleSeries CreateSomeScatterData(double randomness, double curviness) { var doubleSeries = new DoubleSeries(); Random r = new Random(0); const double c = 0; const double m = 0.02; // Create some data which looks like a scatter chart with points randomly spaced around a // slightly curved / linear trendline dataset // // this will be used to apply filters such as Trendline, Polynomial, Scale, Offset etc... for (int x = 0; x < 200; x++) { double y = (m * x + c + (r.NextDouble() * randomness)) * x * (1 + curviness); doubleSeries.Add(new XYPoint { X = x, Y = y }); } return(doubleSeries); }
public static double Value(TimeSeries input, int index, int length, int order) { if (index < length - 1 + input.FirstIndex) { return(double.NaN); } DoubleSeries doubleSeries = new DoubleSeries(); double num = 0.0; for (int index1 = 0; index1 <= index; ++index1) { doubleSeries.Add(input.GetDateTime(index1), input[index1, BarData.High] - input[index1, BarData.Low]); } EMA ema1 = new EMA((TimeSeries)doubleSeries, order, BarData.Close); EMA ema2 = new EMA((TimeSeries)ema1, order, BarData.Close); for (int index1 = index; index1 > index - length; --index1) { num += ema1[index1] / ema2[index1]; } return(num); }
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 GetAcousticChannel(int channelNumber) { if (channelNumber > 7) throw new InvalidOperationException("Only channels 0-7 allowed"); if (_acousticPlotData.Count != 0) { return _acousticPlotData[channelNumber]; } // e.g. resource format: Abt.Controls.SciChart.Example.Resources.EURUSD_Daily.csv var csvResource = string.Format("{0}.{1}", ResourceDirectory, "AcousticPlots.csv"); var ch0 = new DoubleSeries(100000); var ch1 = new DoubleSeries(100000); var ch2 = new DoubleSeries(100000); var ch3 = new DoubleSeries(100000); var ch4 = new DoubleSeries(100000); var ch5 = new DoubleSeries(100000); var ch6 = new DoubleSeries(100000); var ch7 = new DoubleSeries(100000); var assembly = typeof(DataManager).Assembly; using (var stream = assembly.GetManifestResourceStream(csvResource)) using (var streamReader = new StreamReader(stream)) { string line = streamReader.ReadLine(); line = streamReader.ReadLine(); while (line != null) { // 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(','); double x = double.Parse(tokens[0], NumberFormatInfo.InvariantInfo); double y0 = double.Parse(tokens[1], NumberFormatInfo.InvariantInfo); double y1 = double.Parse(tokens[2], NumberFormatInfo.InvariantInfo); double y2 = double.Parse(tokens[3], NumberFormatInfo.InvariantInfo); double y3 = double.Parse(tokens[4], NumberFormatInfo.InvariantInfo); double y4 = double.Parse(tokens[5], NumberFormatInfo.InvariantInfo); double y5 = double.Parse(tokens[6], NumberFormatInfo.InvariantInfo); double y6 = double.Parse(tokens[7], NumberFormatInfo.InvariantInfo); double y7 = double.Parse(tokens[8], NumberFormatInfo.InvariantInfo); ch0.Add(new XYPoint() { X = x, Y = y0 }); ch1.Add(new XYPoint() { X = x, Y = y1 }); ch2.Add(new XYPoint() { X = x, Y = y2 }); ch3.Add(new XYPoint() { X = x, Y = y3 }); ch4.Add(new XYPoint() { X = x, Y = y4 }); ch5.Add(new XYPoint() { X = x, Y = y5 }); ch6.Add(new XYPoint() { X = x, Y = y6 }); ch7.Add(new XYPoint() { X = x, Y = y7 }); line = streamReader.ReadLine(); } } _acousticPlotData.AddRange(new[] { ch0, ch1, ch2, ch3, ch4, ch5, ch6, ch7}); return _acousticPlotData[channelNumber]; }
public DoubleSeries GetButterflyCurve(int count=2000) { // From http://en.wikipedia.org/wiki/Butterfly_curve_%28transcendental%29 // x = sin(t) * (e^cos(t) - 2cos(4t) - sin^5(t/12)) // y = cos(t) * (e^cos(t) - 2cos(4t) - sin^5(t/12)) var temp = 0.01; var doubleSeries = new DoubleSeries(count); for (int i = 0; i < count; i++) { var t = i*temp; double multiplier = Math.Pow(Math.E, Math.Cos(t)) - 2*Math.Cos(4*t) - Math.Pow(Math.Sin(t/12), 5); double x = Math.Sin(t)*multiplier; double y = Math.Cos(t) * multiplier; doubleSeries.Add(new XYPoint {X = x, Y = y}); } 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 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 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 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 override void OnQuote(Quote quote) { //Console.WriteLine( "onQuote {0} b/a {1}/{2}", // instrument.Symbol, quote.Bid, quote.Ask ); if ((quote.DateTime.TimeOfDay > tsStop) || (quote.DateTime.TimeOfDay < tsStart)) { ExitSignal = true; } //gpstrategy.EmitSignalQuote(this, quote); dsAsk.Add(quote.DateTime, quote.Ask); dsBid.Add(quote.DateTime, quote.Bid); double t = (quote.Ask + quote.Bid) / 2.0; dsBidAskMidPoint.Add(quote.DateTime, t); if (0.0 == Default) { Default = t; } //dsBidAskRange.Add( quote.DateTime, quote.Ask - quote.Bid ); if (quote.Ask > quote.Bid) { //double d = Math.Log( Math.Abs( Math.Log( quote.Ask ) - Math.Log( quote.Bid ) ) ); //double d = Math.Log( Math.Log( quote.Ask ) - Math.Log( quote.Bid ) ); //double d = Math.Abs( Math.Log( quote.Ask ) - Math.Log( quote.Bid ) ); double d = quote.Ask - quote.Bid; //Console.WriteLine( "{0}", d ); dsBidAskSpread.Add(quote.DateTime, d); } // // calculate KAMA // if (0 == dsBidAskKama0.Count) { dsBidAskKama0.Add(quote.DateTime, dsBidAskMidPoint.Last); } else { if (0 == dsTradeER0.Count) { dsBidAskKama0.Add(quote.DateTime, dsBidAskMidPoint.Last); } else { double er = dsTradeER0.Last; double sc = Math.Pow(er * (dblKamaFastest - dblKamaSlowest) + dblKamaSlowest, 2); dsBidAskKama0.Add(quote.DateTime, dsBidAskKama0.Last + sc * (dsBidAskMidPoint.Last - dsBidAskKama0.Last)); } } if (0 == dsBidAskKama1.Count) { dsBidAskKama1.Add(quote.DateTime, dsBidAskMidPoint.Last); } else { if (0 == dsTradeER1.Count) { dsBidAskKama1.Add(quote.DateTime, dsBidAskMidPoint.Last); } else { double er = dsTradeER1.Last; double sc = Math.Pow(er * (dblKamaFastest - dblKamaSlowest) + dblKamaSlowest, 2); dsBidAskKama1.Add(quote.DateTime, dsBidAskKama1.Last + sc * (dsBidAskMidPoint.Last - dsBidAskKama1.Last)); } } //BuySignal = individual.LongSignal.EvaluateBool(this); //SellSignal = individual.ShortSignal.EvaluateBool(this); if (ExitSignal) { if (HasPosition) { switch (Position.Side) { case PositionSide.Long: OnNewLongExit(Instrument, (int)Math.Abs(Position.Qty), "Long Stop"); break; case PositionSide.Short: OnNewShortExit(Instrument, (int)Math.Abs(Position.Qty), "Short Stop"); break; } } } else { if (BuySignal ^ SellSignal) // one or the other but not both { if (HasPosition) { switch (Position.Side) { case PositionSide.Long: if (SellSignal) { OnNewLongExit(Instrument, (int)Math.Abs(Position.Qty), "Long Exit"); OnNewShortEntry(Instrument, OrderSize, "Short Reversal"); } break; case PositionSide.Short: if (BuySignal) { OnNewShortExit(Instrument, (int)Math.Abs(Position.Qty), "Short Exit"); OnNewLongEntry(Instrument, OrderSize, "Long Reversal"); } break; } } else { if (BuySignal) { OnNewLongEntry(Instrument, OrderSize, "Long Entry"); } if (SellSignal) { OnNewShortEntry(Instrument, OrderSize, "Short Entry"); } } } } }
public override void OnTrade(Trade trade) { //Console.WriteLine( "{0} {1} {2}", trade.DateTime, trade.Price, trade.Size ); //gpstrategy.EmitSignalTrade(this, trade); if (0.0 == Default) { Default = trade.Price; } dsTrade.Add(trade.DateTime, trade.Price); dsTradeVolume.Add(trade.DateTime, trade.Size); //Console.WriteLine( "rp {0} {1}", dsTrade.Count, dsReturns.Count ); //if ( ReturnsPeriod < smaTrade.Count ) { // dsReturns.Add( trade.DateTime, ( smaTrade.Last - smaTrade.Ago( ReturnsPeriod ) ) / smaTrade.Ago( ReturnsPeriod ) ); //} if (intReturnsPeriod < dsTrade.Count) { //Console.WriteLine( "adding return" ); dsReturns.Add(trade.DateTime, (trade.Price - dsTrade.Ago(intReturnsPeriod)) / dsTrade.Ago(intReturnsPeriod)); } //Console.WriteLine( "er" ); if (dsTrade.Count >= 3) { int interval = Math.Min(dsTrade.Count, intER0); double last = dsTrade.Last; double first = dsTrade.Ago(1); double sum = Math.Abs(last - first); for (int i = 2; i < interval; i++) { first = dsTrade.Ago(i); sum += Math.Abs(dsTrade.Ago(i - 1) - first); } if (0.0 == sum) { dsTradeER0.Add(trade.DateTime, 1); } else { double t = Math.Abs(last - first) / sum; dsTradeER0.Add(trade.DateTime, t); } } //Console.WriteLine( "er" ); if (dsTrade.Count >= 3) { int interval = Math.Min(dsTrade.Count, intER1); double last = dsTrade.Last; double first = dsTrade.Ago(1); double sum = Math.Abs(last - first); for (int i = 2; i < interval; i++) { first = dsTrade.Ago(i); sum += Math.Abs(dsTrade.Ago(i - 1) - first); } if (0.0 == sum) { dsTradeER1.Add(trade.DateTime, 1); } else { double t = Math.Abs(last - first) / sum; dsTradeER1.Add(trade.DateTime, t); } } if (Math.Max(cntKurtosis, cntSkew) <= dsTrade.Count) { dsKurtosis.Add(trade.DateTime, stats.Kurtosis(cntKurtosis)); dsSkew.Add(trade.DateTime, stats.Skewness(cntSkew)); } dsZero.Add(trade.DateTime, 0); }
//TODO add try/catch #region Input_Parse //RayonRs232 old parser public void ParseInputData(int length, byte[] dataInput) { if (Rs232Interface.GetInstance.IsSynced == false)//TODO { Rs232Interface.GetInstance.IsSynced = true; //Rs232Interface.GetInstance. } else { //Parser int PlotDataSampleLSB; int PlotDataSampleMSB; int PlotDataSample; int i = 0; //int limit = (dataInput.Length - (dataInput.Length%12)); for (; i < dataInput.Length - 24;) { if (dataInput[i] == 0xbb && dataInput[i + 1] == 0xcc) { XYPoint xyPoint1 = new XYPoint(); XYPoint xyPoint2 = new XYPoint(); XYPoint xyPoint3 = new XYPoint(); XYPoint xyPoint4 = new XYPoint(); XYPoint xyPoint5 = new XYPoint(); // //First Sample // try // { PlotDataSampleLSB = (short)dataInput[i + 2]; PlotDataSampleMSB = (short)dataInput[i + 3]; PlotDataSample = (PlotDataSampleMSB << 8) | PlotDataSampleLSB; xyPoint1.Y = (double)PlotDataSample; xyPoint1.X = _deltaTOneChen; _deltaTOneChen += 0.1; datasource1.Add(xyPoint1); //Second PlotDataSampleLSB = (short)dataInput[i + 4]; PlotDataSampleMSB = (short)dataInput[i + 5]; PlotDataSample = (PlotDataSampleMSB << 8) | PlotDataSampleLSB; xyPoint2.Y = (double)PlotDataSample; xyPoint2.X = _deltaTOneChen; _deltaTOneChen += 0.1; datasource1.Add(xyPoint2); //Third Sample PlotDataSampleLSB = (short)dataInput[i + 6]; PlotDataSampleMSB = (short)dataInput[i + 7]; PlotDataSample = (PlotDataSampleMSB << 8) | PlotDataSampleLSB; xyPoint3.Y = (double)PlotDataSample; xyPoint3.X = _deltaTOneChen; _deltaTOneChen += 0.1; datasource1.Add(xyPoint3); //Fourth sample PlotDataSampleLSB = (short)dataInput[i + 8]; PlotDataSampleMSB = (short)dataInput[i + 9]; PlotDataSample = (PlotDataSampleMSB << 8) | PlotDataSampleLSB; xyPoint4.Y = (double)PlotDataSample; xyPoint4.X = _deltaTOneChen; datasource1.Add(xyPoint4); _deltaTOneChen += 0.1; //Fifth sample PlotDataSampleLSB = (short)dataInput[i + 10]; PlotDataSampleMSB = (short)dataInput[i + 11]; PlotDataSample = (PlotDataSampleMSB << 8) | PlotDataSampleLSB; if (PlotDataSample != 4.0) { // int a = 5; } xyPoint5.Y = (double)PlotDataSample; xyPoint5.X = _deltaTOneChen; _deltaTOneChen += 0.1; datasource1.Add(xyPoint5); i = i + 11; } i++; } Parser2Plot(this, new Parser2SendEventArgs(datasource1)); datasource1.Clear(); } }
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 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 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 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; }
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; }