Skip to content

Commit

Permalink
Minor plotting test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Molinero committed Jan 3, 2024
1 parent 87d97bb commit 9f9bf3b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 1 addition & 4 deletions Algorithm/QCAlgorithm.Plotting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,7 @@ public IEnumerable<Chart> GetChartUpdates(bool clearChartData = false)
{
foreach (var chart in _charts.Values)
{
var updates = chart.GetUpdates();

yield return chart.GetUpdates();
if (clearChartData)
{
// we can clear this data out after getting updates to prevent unnecessary memory usage
Expand All @@ -553,8 +552,6 @@ public IEnumerable<Chart> GetChartUpdates(bool clearChartData = false)
series.Value.Purge();
}
}

yield return updates;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/Algorithm/AlgorithmPlottingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace QuantConnect.Tests.Algorithm
{
[TestFixture]
[TestFixture, Parallelizable(ParallelScope.Fixtures)]
public class AlgorithmPlottingTests
{
private Symbol _spy;
Expand Down Expand Up @@ -105,7 +105,7 @@ public void TestGetChartUpdatesWhileAdding()
{
for (var i = 0; i < 1000; i++)
{
_algorithm.GetChartUpdates(true);
_algorithm.GetChartUpdates(true).ToList();
Thread.Sleep(1);
}
});
Expand Down Expand Up @@ -168,7 +168,7 @@ def Update(self, input):
customIndicator.Update(input);
customIndicator.Current.Value = customIndicator.Value;
Assert.DoesNotThrow(() => _algorithm.Plot("PlotTest", customIndicator));
var charts = _algorithm.GetChartUpdates();
var charts = _algorithm.GetChartUpdates().ToList();
Assert.IsTrue(charts.Where(x => x.Name == "PlotTest").Any());
Assert.AreEqual(10, charts.First().Series["custom"].GetValues<ChartPoint>().First().y);
}
Expand All @@ -194,7 +194,7 @@ def Update(self, input):

var customIndicator = module.GetAttr("CustomIndicator").Invoke();
Assert.DoesNotThrow(() => _algorithm.Plot("PlotTest", customIndicator));
var charts = _algorithm.GetChartUpdates();
var charts = _algorithm.GetChartUpdates().ToList();
Assert.IsFalse(charts.Where(x => x.Name == "PlotTest").Any());
Assert.IsTrue(charts.Where(x => x.Name == "Strategy Equity").Any());
Assert.AreEqual(10, charts.First().Series["PlotTest"].GetValues<ChartPoint>().First().y);
Expand All @@ -213,7 +213,7 @@ public void PlotIndicatorPlotsBaseIndicator()
sma1.Update(new DateTime(2022, 11, 15), 1);
sma2.Update(new DateTime(2022, 11, 15), 2);

var charts = _algorithm.GetChartUpdates();
var charts = _algorithm.GetChartUpdates().ToList();
Assert.IsTrue(charts.Where(x => x.Name == "PlotTest").Any());

var chart = charts.First();
Expand Down

0 comments on commit 9f9bf3b

Please sign in to comment.