public void PassesTicksStraightThrough() { var enumerator = new EnqueueableEnumerator<Tick>(); // add some ticks var currentTime = new DateTime(2015, 10, 08); // returns true even if no data present until stop is called Assert.IsTrue(enumerator.MoveNext()); Assert.IsNull(enumerator.Current); var tick1 = new Tick(currentTime, Symbols.SPY, 199.55m, 199, 200) {Quantity = 10}; enumerator.Enqueue(tick1); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(tick1, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.IsNull(enumerator.Current); var tick2 = new Tick(currentTime, Symbols.SPY, 199.56m, 199.21m, 200.02m) {Quantity = 5}; enumerator.Enqueue(tick2); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(tick2, enumerator.Current); enumerator.Stop(); Assert.IsFalse(enumerator.MoveNext()); Assert.IsNull(enumerator.Current); }
public void PassesTicksStraightThrough() { var enumerator = new EnqueueableEnumerator<Tick>(); // add some ticks var currentTime = new DateTime(2015, 10, 08); // returns true even if no data present until stop is called Assert.IsTrue(enumerator.MoveNext()); Assert.IsNull(enumerator.Current); var tick1 = new Tick(currentTime, Symbols.SPY, 199.55m, 199, 200) {Quantity = 10}; enumerator.Enqueue(tick1); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(tick1, enumerator.Current); Assert.IsTrue(enumerator.MoveNext()); Assert.IsNull(enumerator.Current); var tick2 = new Tick(currentTime, Symbols.SPY, 199.56m, 199.21m, 200.02m) {Quantity = 5}; enumerator.Enqueue(tick2); Assert.IsTrue(enumerator.MoveNext()); Assert.AreEqual(tick2, enumerator.Current); enumerator.Stop(); Assert.IsFalse(enumerator.MoveNext()); Assert.IsNull(enumerator.Current); }
public void MoveNextBlocks() { var finished = new ManualResetEvent(false); var enumerator = new EnqueueableEnumerator <Tick>(true); // producer int count = 0; Task.Run(() => { while (!finished.WaitOne(TimeSpan.FromMilliseconds(50))) { enumerator.Enqueue(new Tick(DateTime.Now, Symbols.SPY, 100, 101)); count++; // 5 data points is plenty if (count > 5) { finished.Set(); enumerator.Stop(); } } }); // consumer int dequeuedCount = 0; bool encounteredError = false; var consumerTaskFinished = new ManualResetEvent(false); Task.Run(() => { while (enumerator.MoveNext()) { dequeuedCount++; if (enumerator.Current == null) { encounteredError = true; } } consumerTaskFinished.Set(); }); finished.WaitOne(Timeout.Infinite); consumerTaskFinished.WaitOne(Timeout.Infinite); Assert.IsFalse(enumerator.MoveNext()); Assert.IsFalse(encounteredError); Assert.AreEqual(count, dequeuedCount); enumerator.Dispose(); }
public void RecordsInternalQueueCount() { var enumerator = new EnqueueableEnumerator<Tick>(); var currentTime = new DateTime(2015, 12, 01); var tick = new Tick(currentTime, Symbols.SPY, 100, 101); enumerator.Enqueue(tick); Assert.AreEqual(1, enumerator.Count); tick = new Tick(currentTime, Symbols.SPY, 100, 101); enumerator.Enqueue(tick); Assert.AreEqual(2, enumerator.Count); enumerator.MoveNext(); Assert.AreEqual(1, enumerator.Count); enumerator.MoveNext(); Assert.AreEqual(0, enumerator.Count); }
public void RecordsInternalQueueCount() { var enumerator = new EnqueueableEnumerator<Tick>(); var currentTime = new DateTime(2015, 12, 01); var tick = new Tick(currentTime, Symbols.SPY, 100, 101); enumerator.Enqueue(tick); Assert.AreEqual(1, enumerator.Count); tick = new Tick(currentTime, Symbols.SPY, 100, 101); enumerator.Enqueue(tick); Assert.AreEqual(2, enumerator.Count); enumerator.MoveNext(); Assert.AreEqual(1, enumerator.Count); enumerator.MoveNext(); Assert.AreEqual(0, enumerator.Count); }
public void RecordsMostRecentlyEnqueuedItem() { var enumerator = new EnqueueableEnumerator<Tick>(); var currentTime = new DateTime(2015, 12, 01); var tick1 = new Tick(currentTime, Symbols.SPY, 100, 101); enumerator.Enqueue(tick1); Assert.AreEqual(null, enumerator.Current); Assert.AreEqual(tick1, enumerator.LastEnqueued); var tick2 = new Tick(currentTime, Symbols.SPY, 100, 101); enumerator.Enqueue(tick2); Assert.AreEqual(tick2, enumerator.LastEnqueued); enumerator.MoveNext(); Assert.AreEqual(tick1, enumerator.Current); enumerator.MoveNext(); Assert.AreEqual(tick2, enumerator.Current); }
public void Step1D(decimal min, decimal max, decimal step) { var param = new OptimizationStepParameter("ema-fast", min, max, step); var set = new HashSet <OptimizationParameter>() { param }; _strategy.Initialize(new Target("Profit", new Maximization(), null), new List <Constraint>(), set, new StepBaseOptimizationStrategySettings()); var counter = 0; using (var enumerator = new EnqueueableEnumerator <ParameterSet>()) { _strategy.NewParameterSet += (s, parameterSet) => { enumerator.Enqueue(parameterSet); }; _strategy.PushNewResults(OptimizationResult.Initial); using (var paramEnumerator = new OptimizationStepParameterEnumerator(param)) { while (paramEnumerator.MoveNext()) { var value = paramEnumerator.Current; counter++; Assert.IsTrue(enumerator.MoveNext()); var suggestion = enumerator.Current; Assert.IsNotNull(suggestion); Assert.IsTrue(suggestion.Value.All(s => set.Any(arg => arg.Name == s.Key))); Assert.AreEqual(1, suggestion.Value.Count); Assert.AreEqual(value, suggestion.Value["ema-fast"]); } } Assert.AreEqual(0, enumerator.Count); } Assert.Greater(counter, 0); Assert.AreEqual(Math.Floor((param.MaxValue - param.MinValue) / param.Step.Value) + 1, counter); }
public void Step3D() { var args = new HashSet <OptimizationParameter>() { new OptimizationStepParameter("ema-fast", 10, 100, 1), new OptimizationStepParameter("ema-slow", 20, 200, 4), new OptimizationStepParameter("ema-custom", 30, 300, 2) }; _strategy.Initialize(new Target("Profit", new Maximization(), null), null, args, new StepBaseOptimizationStrategySettings()); var counter = 0; using (var enumerator = new EnqueueableEnumerator <ParameterSet>()) { _strategy.NewParameterSet += (s, parameterSet) => { enumerator.Enqueue(parameterSet); }; _strategy.PushNewResults(OptimizationResult.Initial); var fastParam = args.First(arg => arg.Name == "ema-fast") as OptimizationStepParameter; var slowParam = args.First(arg => arg.Name == "ema-slow") as OptimizationStepParameter; var customParam = args.First(arg => arg.Name == "ema-custom") as OptimizationStepParameter; using (var fastEnumerator = new OptimizationStepParameterEnumerator(fastParam)) { using (var slowEnumerator = new OptimizationStepParameterEnumerator(slowParam)) { using (var customEnumerator = new OptimizationStepParameterEnumerator(customParam)) { while (fastEnumerator.MoveNext()) { var fast = fastEnumerator.Current; slowEnumerator.Reset(); while (slowEnumerator.MoveNext()) { var slow = slowEnumerator.Current; customEnumerator.Reset(); while (customEnumerator.MoveNext()) { var custom = customEnumerator.Current; counter++; Assert.IsTrue(enumerator.MoveNext()); var suggestion = enumerator.Current; Assert.IsNotNull(suggestion); Assert.IsTrue(suggestion.Value.All(s => args.Any(arg => arg.Name == s.Key))); Assert.AreEqual(3, suggestion.Value.Count()); Assert.AreEqual(fast, suggestion.Value["ema-fast"]); Assert.AreEqual(slow, suggestion.Value["ema-slow"]); Assert.AreEqual(custom, suggestion.Value["ema-custom"]); } } } } } } Assert.AreEqual(0, enumerator.Count); } Assert.Greater(counter, 0); var total = 1m; foreach (var arg in args.Cast <OptimizationStepParameter>()) { total *= (arg.MaxValue - arg.MinValue) / arg.Step.Value + 1; } Assert.AreEqual(total, counter); }
public void RecordsMostRecentlyEnqueuedItem() { var enumerator = new EnqueueableEnumerator<Tick>(); var currentTime = new DateTime(2015, 12, 01); var tick1 = new Tick(currentTime, Symbols.SPY, 100, 101); enumerator.Enqueue(tick1); Assert.AreEqual(null, enumerator.Current); Assert.AreEqual(tick1, enumerator.LastEnqueued); var tick2 = new Tick(currentTime, Symbols.SPY, 100, 101); enumerator.Enqueue(tick2); Assert.AreEqual(tick2, enumerator.LastEnqueued); enumerator.MoveNext(); Assert.AreEqual(tick1, enumerator.Current); enumerator.MoveNext(); Assert.AreEqual(tick2, enumerator.Current); }
public void MoveNextBlocks() { var finished = new ManualResetEvent(false); var enumerator = new EnqueueableEnumerator<Tick>(true); // producer int count = 0; Task.Run(() => { while (!finished.WaitOne(TimeSpan.FromMilliseconds(50))) { enumerator.Enqueue(new Tick(DateTime.Now, Symbols.SPY, 100, 101)); count++; // 5 data points is plenty if (count > 5) { finished.Set(); enumerator.Stop(); } } }); // consumer int dequeuedCount = 0; bool encounteredError = false; var consumerTaskFinished = new ManualResetEvent(false); Task.Run(() => { while (enumerator.MoveNext()) { dequeuedCount++; if (enumerator.Current == null) { encounteredError = true; } } consumerTaskFinished.Set(); }); finished.WaitOne(Timeout.Infinite); consumerTaskFinished.WaitOne(Timeout.Infinite); Assert.IsFalse(enumerator.MoveNext()); Assert.IsFalse(encounteredError); Assert.AreEqual(count, dequeuedCount); }