mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-24 21:48:03 +00:00
[CodeFactor] Apply fixes to commit 0606491
This commit is contained in:
@@ -82,7 +82,7 @@ public class NlmaTests
|
||||
{
|
||||
// DC gain = 1: constant input → output must equal that constant after warmup
|
||||
var nlma = new Nlma(10);
|
||||
int flen = 5 * 10 - 1; // 49
|
||||
int flen = (5 * 10) - 1; // 49
|
||||
TValue result = default;
|
||||
for (int i = 0; i < flen + 10; i++)
|
||||
{
|
||||
@@ -96,7 +96,7 @@ public class NlmaTests
|
||||
{
|
||||
// period=2, flen=9. After warmup, constant input → output = input
|
||||
var nlma = new Nlma(2);
|
||||
int flen = 5 * 2 - 1; // 9
|
||||
int flen = (5 * 2) - 1; // 9
|
||||
TValue result = default;
|
||||
for (int i = 0; i < flen + 5; i++)
|
||||
{
|
||||
@@ -111,7 +111,7 @@ public class NlmaTests
|
||||
// Igorad kernel with any period: constant input must produce constant output
|
||||
// This validates that signed-sum normalization preserves DC gain = 1
|
||||
var nlma = new Nlma(4);
|
||||
int flen = 5 * 4 - 1; // 19
|
||||
int flen = (5 * 4) - 1; // 19
|
||||
TValue result = default;
|
||||
for (int i = 0; i < flen + 5; i++)
|
||||
{
|
||||
@@ -126,7 +126,7 @@ public class NlmaTests
|
||||
// Igorad kernel with period 14 should have negative weights for lag cancellation
|
||||
// Test: feed a step function and verify responsiveness
|
||||
var nlma = new Nlma(14);
|
||||
int flen = 5 * 14 - 1; // 69
|
||||
int flen = (5 * 14) - 1; // 69
|
||||
|
||||
// Feed flen bars of 100, then flen bars of 200
|
||||
for (int i = 0; i < flen; i++)
|
||||
@@ -165,7 +165,7 @@ public class NlmaTests
|
||||
{
|
||||
// period=3, flen = 5*3-1 = 14
|
||||
var nlma = new Nlma(3);
|
||||
int flen = 5 * 3 - 1; // 14
|
||||
int flen = (5 * 3) - 1; // 14
|
||||
Assert.False(nlma.IsHot);
|
||||
|
||||
for (int i = 0; i < flen - 1; i++)
|
||||
@@ -281,12 +281,12 @@ public class NlmaTests
|
||||
public void AllModes_ProduceSameResults()
|
||||
{
|
||||
int period = 10;
|
||||
int flen = 5 * period - 1; // 49
|
||||
int flen = (5 * period) - 1; // 49
|
||||
int len = flen + 30; // ensure enough bars for full kernel
|
||||
var src = new TSeries([], []);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 100 + Math.Sin(i) * 10));
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 100 + (Math.Sin(i) * 10)));
|
||||
}
|
||||
|
||||
// Mode 1: streaming
|
||||
@@ -343,12 +343,12 @@ public class NlmaTests
|
||||
public void Batch_Span_MatchesTSeries()
|
||||
{
|
||||
int period = 7;
|
||||
int flen = 5 * period - 1; // 34
|
||||
int flen = (5 * period) - 1; // 34
|
||||
int len = flen + 20;
|
||||
var src = new TSeries([], []);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 50 + i * 0.5));
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 50 + (i * 0.5)));
|
||||
}
|
||||
|
||||
var tsBatch = Nlma.Batch(src, period);
|
||||
@@ -388,12 +388,12 @@ public class NlmaTests
|
||||
double[] output = new double[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
source[i] = 100.0 + i * 0.1;
|
||||
source[i] = 100.0 + (i * 0.1);
|
||||
}
|
||||
Nlma.Batch(source, output, 300);
|
||||
|
||||
// flen = 5*300 - 1 = 1499
|
||||
int flen = 5 * 300 - 1;
|
||||
int flen = (5 * 300) - 1;
|
||||
for (int i = flen; i < count; i++)
|
||||
{
|
||||
Assert.True(double.IsFinite(output[i]), $"Output at index {i} should be finite");
|
||||
@@ -406,7 +406,7 @@ public class NlmaTests
|
||||
public void Calculate_ReturnsIndicatorAndResults()
|
||||
{
|
||||
int period = 5;
|
||||
int flen = 5 * period - 1; // 24
|
||||
int flen = (5 * period) - 1; // 24
|
||||
int len = flen + 20;
|
||||
var src = new TSeries([], []);
|
||||
for (int i = 0; i < len; i++)
|
||||
@@ -426,7 +426,7 @@ public class NlmaTests
|
||||
public void Reset_ClearsState()
|
||||
{
|
||||
int period = 5;
|
||||
int flen = 5 * period - 1; // 24
|
||||
int flen = (5 * period) - 1; // 24
|
||||
var nlma = new Nlma(period);
|
||||
for (int i = 0; i < flen + 10; i++)
|
||||
{
|
||||
@@ -458,11 +458,11 @@ public class NlmaTests
|
||||
public void LargePeriod_Handles()
|
||||
{
|
||||
int period = 500;
|
||||
int flen = 5 * period - 1; // 2499
|
||||
int flen = (5 * period) - 1; // 2499
|
||||
var nlma = new Nlma(period);
|
||||
for (int i = 0; i < flen + 100; i++)
|
||||
{
|
||||
nlma.Update(new TValue(DateTime.MinValue.AddDays(i), 100 + i * 0.01));
|
||||
nlma.Update(new TValue(DateTime.MinValue.AddDays(i), 100 + (i * 0.01)));
|
||||
}
|
||||
Assert.True(double.IsFinite(nlma.Last.Value));
|
||||
Assert.True(nlma.IsHot);
|
||||
|
||||
@@ -13,12 +13,12 @@ public class NlmaValidationTests
|
||||
public void Batch_Matches_Streaming()
|
||||
{
|
||||
int period = 10;
|
||||
int flen = 5 * period - 1; // 49
|
||||
int flen = (5 * period) - 1; // 49
|
||||
int len = flen + 30;
|
||||
var src = new TSeries([], []);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 100 + Math.Sin(i) * 20));
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 100 + (Math.Sin(i) * 20)));
|
||||
}
|
||||
|
||||
var batchResult = Nlma.Batch(src, period);
|
||||
@@ -35,12 +35,12 @@ public class NlmaValidationTests
|
||||
public void Span_Matches_Streaming()
|
||||
{
|
||||
int period = 8;
|
||||
int flen = 5 * period - 1; // 39
|
||||
int flen = (5 * period) - 1; // 39
|
||||
int len = flen + 20;
|
||||
double[] values = new double[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
values[i] = 50 + i * 0.7;
|
||||
values[i] = 50 + (i * 0.7);
|
||||
}
|
||||
|
||||
double[] spanOutput = new double[len];
|
||||
@@ -58,12 +58,12 @@ public class NlmaValidationTests
|
||||
public void Calculate_Matches_Batch()
|
||||
{
|
||||
int period = 12;
|
||||
int flen = 5 * period - 1; // 59
|
||||
int flen = (5 * period) - 1; // 59
|
||||
int len = flen + 20;
|
||||
var src = new TSeries([], []);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 200 + i * 0.3));
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 200 + (i * 0.3)));
|
||||
}
|
||||
|
||||
var batchResult = Nlma.Batch(src, period);
|
||||
@@ -79,7 +79,7 @@ public class NlmaValidationTests
|
||||
public void ConstantInput_ProducesConstant()
|
||||
{
|
||||
int period = 15;
|
||||
int flen = 5 * period - 1; // 74
|
||||
int flen = (5 * period) - 1; // 74
|
||||
int len = flen + 20;
|
||||
var src = new TSeries([], []);
|
||||
for (int i = 0; i < len; i++)
|
||||
@@ -108,12 +108,12 @@ public class NlmaValidationTests
|
||||
public void LargePeriod_Handles()
|
||||
{
|
||||
int period = 200;
|
||||
int flen = 5 * period - 1; // 999
|
||||
int flen = (5 * period) - 1; // 999
|
||||
int len = flen + 100;
|
||||
var src = new TSeries([], []);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 100 + Math.Sin(i * 0.1) * 10));
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 100 + (Math.Sin(i * 0.1) * 10)));
|
||||
}
|
||||
|
||||
var result = Nlma.Batch(src, period);
|
||||
@@ -128,7 +128,7 @@ public class NlmaValidationTests
|
||||
[Fact]
|
||||
public void DifferentPeriods_ProduceDifferentResults()
|
||||
{
|
||||
int maxFlen = 5 * 20 - 1; // 99 for period=20
|
||||
int maxFlen = (5 * 20) - 1; // 99 for period=20
|
||||
int len = maxFlen + 30;
|
||||
var src = new TSeries([], []);
|
||||
for (int i = 0; i < len; i++)
|
||||
@@ -177,7 +177,7 @@ public class NlmaValidationTests
|
||||
// Multiple corrections should not drift
|
||||
for (int c = 0; c < 10; c++)
|
||||
{
|
||||
nlma.Update(new TValue(DateTime.MinValue.AddDays(29), 129.0 + c * 0.001), isNew: false);
|
||||
nlma.Update(new TValue(DateTime.MinValue.AddDays(29), 129.0 + (c * 0.001)), isNew: false);
|
||||
}
|
||||
|
||||
// Final correction with original value
|
||||
@@ -192,13 +192,13 @@ public class NlmaValidationTests
|
||||
// cancellation effect. Verify this by checking that NLMA on sinusoidal data
|
||||
// differs from SMA and shows phase lead (less phase lag than SMA).
|
||||
int period = 10;
|
||||
int flen = 5 * period - 1; // 49
|
||||
int flen = (5 * period) - 1; // 49
|
||||
int len = 3 * flen;
|
||||
var src = new TSeries([], []);
|
||||
// Sinusoidal signal with period matching the filter period
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 100 + 10 * Math.Sin(2 * Math.PI * i / 20)));
|
||||
src.Add(new TValue(DateTime.MinValue.AddDays(i), 100 + (10 * Math.Sin(2 * Math.PI * i / 20))));
|
||||
}
|
||||
|
||||
var nlmaResult = Nlma.Batch(src, period);
|
||||
@@ -235,7 +235,7 @@ public class NlmaValidationTests
|
||||
{
|
||||
// NLMA's negative weights can cause output to exceed input range
|
||||
int period = 14;
|
||||
int flen = 5 * period - 1; // 69
|
||||
int flen = (5 * period) - 1; // 69
|
||||
var nlma = new Nlma(period);
|
||||
|
||||
// Step function: all 0s then all 100s — enough data for full kernel
|
||||
|
||||
Reference in New Issue
Block a user