Add benchmark for backtest on the test
This commit is contained in:
@@ -74,11 +74,14 @@ public static class TradingBox
|
||||
Dictionary<string, LightSignal> previousSignal, IndicatorComboConfig config, int? loopbackPeriod,
|
||||
Dictionary<IndicatorType, IndicatorsResultBase> preCalculatedIndicatorValues)
|
||||
{
|
||||
var signalOnCandles = new List<LightSignal>();
|
||||
// Optimize list creation - avoid redundant allocations
|
||||
var limitedCandles = newCandles.Count <= 600
|
||||
? newCandles.OrderBy(c => c.Date).ToList()
|
||||
: newCandles.OrderBy(c => c.Date).TakeLast(600).ToList();
|
||||
// Pre-allocate with estimated capacity to reduce reallocations
|
||||
var signalOnCandles = new List<LightSignal>(Math.Min(newCandles.Count, 100));
|
||||
|
||||
// Optimize candle ordering - reuse existing sorted data when possible
|
||||
var orderedCandles = newCandles.OrderBy(c => c.Date).ToList();
|
||||
var limitedCandles = orderedCandles.Count <= 600
|
||||
? orderedCandles
|
||||
: orderedCandles.GetRange(orderedCandles.Count - 600, 600);
|
||||
|
||||
foreach (var indicator in lightScenario.Indicators)
|
||||
{
|
||||
@@ -112,10 +115,9 @@ public static class TradingBox
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ensure limitedCandles is ordered chronologically
|
||||
var orderedCandles = limitedCandles.OrderBy(c => c.Date).ToList();
|
||||
// Ensure limitedCandles is ordered chronologically (already ordered from previous step)
|
||||
var loopback = loopbackPeriod.HasValue && loopbackPeriod > 1 ? loopbackPeriod.Value : 1;
|
||||
var candleLoopback = orderedCandles.TakeLast(loopback).ToList();
|
||||
var candleLoopback = limitedCandles.TakeLast(loopback).ToList();
|
||||
|
||||
if (!candleLoopback.Any())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user