mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 20:48:04 +00:00
[CodeFactor] Apply fixes to commit 0606491
This commit is contained in:
@@ -136,7 +136,6 @@ public class BlmaTests
|
||||
|
||||
blma.Pub += (object? sender, in TValueEventArgs args) => timestamps.Add(args.Value.AsDateTime);
|
||||
|
||||
|
||||
blma.Prime(input);
|
||||
|
||||
Assert.Equal(input.Length, timestamps.Count);
|
||||
@@ -162,7 +161,6 @@ public class BlmaTests
|
||||
|
||||
blma.Pub += (object? sender, in TValueEventArgs args) => timestamps.Add(args.Value.AsDateTime);
|
||||
|
||||
|
||||
blma.Prime(input);
|
||||
|
||||
Assert.Equal(input.Length, timestamps.Count);
|
||||
|
||||
@@ -101,7 +101,7 @@ public class CrmaValidationTests
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
values[i] = 2.0 * i + 5.0;
|
||||
values[i] = (2.0 * i) + 5.0;
|
||||
}
|
||||
|
||||
global::QuanTAlib.Crma.Batch(values, output, period);
|
||||
@@ -126,7 +126,7 @@ public class CrmaValidationTests
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
values[i] = 0.5 * i * i + i + 3.0;
|
||||
values[i] = (0.5 * i * i) + i + 3.0;
|
||||
}
|
||||
|
||||
global::QuanTAlib.Crma.Batch(values, output, period);
|
||||
@@ -152,7 +152,7 @@ public class CrmaValidationTests
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
values[i] = 0.001 * i * i * i + 0.01 * i * i + i + 5.0;
|
||||
values[i] = (0.001 * i * i * i) + (0.01 * i * i) + i + 5.0;
|
||||
}
|
||||
|
||||
global::QuanTAlib.Crma.Batch(values, output, period);
|
||||
|
||||
@@ -386,7 +386,7 @@ public class FwmaTests
|
||||
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);
|
||||
}
|
||||
|
||||
Fwma.Batch(source.AsSpan(), output.AsSpan(), 20);
|
||||
|
||||
@@ -383,7 +383,7 @@ public class HammaTests
|
||||
double weightSum = 0;
|
||||
for (int i = 0; i < period; i++)
|
||||
{
|
||||
weights[i] = 0.54 - 0.46 * Math.Cos(twoPiOverPm1 * i);
|
||||
weights[i] = 0.54 - (0.46 * Math.Cos(twoPiOverPm1 * i));
|
||||
weightSum += weights[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ public sealed class HammaValidationTests : IDisposable
|
||||
double weightSum = 0;
|
||||
for (int i = 0; i < period; i++)
|
||||
{
|
||||
weights[i] = 0.54 - 0.46 * Math.Cos(twoPiOverPm1 * i);
|
||||
weights[i] = 0.54 - (0.46 * Math.Cos(twoPiOverPm1 * i));
|
||||
weightSum += weights[i];
|
||||
}
|
||||
|
||||
@@ -187,11 +187,11 @@ public sealed class HammaValidationTests : IDisposable
|
||||
int period = 5;
|
||||
double twoPiOverPm1 = 2.0 * Math.PI / (period - 1);
|
||||
|
||||
double w0 = 0.54 - 0.46 * Math.Cos(0); // 0.08
|
||||
double w1 = 0.54 - 0.46 * Math.Cos(twoPiOverPm1 * 1); // ≈0.54
|
||||
double w2 = 0.54 - 0.46 * Math.Cos(twoPiOverPm1 * 2); // 1.0
|
||||
double w3 = 0.54 - 0.46 * Math.Cos(twoPiOverPm1 * 3); // ≈0.54
|
||||
double w4 = 0.54 - 0.46 * Math.Cos(twoPiOverPm1 * 4); // 0.08
|
||||
double w0 = 0.54 - (0.46 * Math.Cos(0)); // 0.08
|
||||
double w1 = 0.54 - (0.46 * Math.Cos(twoPiOverPm1 * 1)); // ≈0.54
|
||||
double w2 = 0.54 - (0.46 * Math.Cos(twoPiOverPm1 * 2)); // 1.0
|
||||
double w3 = 0.54 - (0.46 * Math.Cos(twoPiOverPm1 * 3)); // ≈0.54
|
||||
double w4 = 0.54 - (0.46 * Math.Cos(twoPiOverPm1 * 4)); // 0.08
|
||||
|
||||
Assert.Equal(0.08, w0, 1e-10);
|
||||
Assert.Equal(0.08, w4, 1e-10);
|
||||
|
||||
@@ -79,13 +79,13 @@ public class HendTests
|
||||
double lastResult = double.NaN;
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
double val = 10.0 + 3.0 * i;
|
||||
double val = 10.0 + (3.0 * i);
|
||||
var result = hend.Update(new TValue(DateTime.UtcNow.AddSeconds(i), val));
|
||||
lastResult = result.Value;
|
||||
}
|
||||
// Centered filter: output at bar N = polynomial value at bar N - half
|
||||
int centerIdx = total - 1 - half;
|
||||
double expected = 10.0 + 3.0 * centerIdx;
|
||||
double expected = 10.0 + (3.0 * centerIdx);
|
||||
Assert.Equal(expected, lastResult, 1e-6);
|
||||
}
|
||||
|
||||
@@ -99,12 +99,12 @@ public class HendTests
|
||||
double lastResult = double.NaN;
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
double val = 5.0 + 2.0 * i + 0.5 * i * i;
|
||||
double val = 5.0 + (2.0 * i) + (0.5 * i * i);
|
||||
var result = hend.Update(new TValue(DateTime.UtcNow.AddSeconds(i), val));
|
||||
lastResult = result.Value;
|
||||
}
|
||||
int centerIdx = total - 1 - half;
|
||||
double expected = 5.0 + 2.0 * centerIdx + 0.5 * centerIdx * centerIdx;
|
||||
double expected = 5.0 + (2.0 * centerIdx) + (0.5 * centerIdx * centerIdx);
|
||||
Assert.Equal(expected, lastResult, 1e-4);
|
||||
}
|
||||
|
||||
@@ -118,12 +118,12 @@ public class HendTests
|
||||
double lastResult = double.NaN;
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
double val = 1.0 + 0.5 * i + 0.1 * i * i + 0.01 * i * i * i;
|
||||
double val = 1.0 + (0.5 * i) + (0.1 * i * i) + (0.01 * i * i * i);
|
||||
var result = hend.Update(new TValue(DateTime.UtcNow.AddSeconds(i), val));
|
||||
lastResult = result.Value;
|
||||
}
|
||||
int centerIdx = total - 1 - half;
|
||||
double expected = 1.0 + 0.5 * centerIdx + 0.1 * centerIdx * centerIdx + 0.01 * centerIdx * centerIdx * centerIdx;
|
||||
double expected = 1.0 + (0.5 * centerIdx) + (0.1 * centerIdx * centerIdx) + (0.01 * centerIdx * centerIdx * centerIdx);
|
||||
Assert.Equal(expected, lastResult, 1e-2);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,12 +88,12 @@ public class HendValidationTests(ITestOutputHelper output)
|
||||
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
double val = a + b * i;
|
||||
double val = a + (b * i);
|
||||
hend.Update(new TValue(DateTime.UtcNow.AddSeconds(i), val));
|
||||
}
|
||||
|
||||
int centerIdx = total - 1 - half;
|
||||
double expected = a + b * centerIdx;
|
||||
double expected = a + (b * centerIdx);
|
||||
_output.WriteLine($"Linear: expected={expected}, actual={hend.Last.Value}");
|
||||
Assert.Equal(expected, hend.Last.Value, 1e-6);
|
||||
}
|
||||
@@ -108,12 +108,12 @@ public class HendValidationTests(ITestOutputHelper output)
|
||||
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
double val = a + b * i + c * i * i;
|
||||
double val = a + (b * i) + (c * i * i);
|
||||
hend.Update(new TValue(DateTime.UtcNow.AddSeconds(i), val));
|
||||
}
|
||||
|
||||
int centerIdx = total - 1 - half;
|
||||
double expected = a + b * centerIdx + c * centerIdx * centerIdx;
|
||||
double expected = a + (b * centerIdx) + (c * centerIdx * centerIdx);
|
||||
_output.WriteLine($"Quadratic: expected={expected}, actual={hend.Last.Value}");
|
||||
Assert.Equal(expected, hend.Last.Value, 0.1);
|
||||
}
|
||||
@@ -128,12 +128,12 @@ public class HendValidationTests(ITestOutputHelper output)
|
||||
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
double val = a + b * i + c * i * i + d * i * i * i;
|
||||
double val = a + (b * i) + (c * i * i) + (d * i * i * i);
|
||||
hend.Update(new TValue(DateTime.UtcNow.AddSeconds(i), val));
|
||||
}
|
||||
|
||||
int centerIdx = total - 1 - half;
|
||||
double expected = a + b * centerIdx + c * centerIdx * centerIdx + d * centerIdx * centerIdx * centerIdx;
|
||||
double expected = a + (b * centerIdx) + (c * centerIdx * centerIdx) + (d * centerIdx * centerIdx * centerIdx);
|
||||
_output.WriteLine($"Cubic: expected={expected}, actual={hend.Last.Value}");
|
||||
Assert.Equal(expected, hend.Last.Value, 1.0);
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ public class IlrsTests
|
||||
// Feed increasing prices
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
ilrs.Update(new TValue(DateTime.UtcNow, 100.0 + i * 10));
|
||||
ilrs.Update(new TValue(DateTime.UtcNow, 100.0 + (i * 10)));
|
||||
}
|
||||
|
||||
// Integral should be well above starting value
|
||||
@@ -373,7 +373,7 @@ public class IlrsTests
|
||||
// Feed decreasing prices
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
ilrs.Update(new TValue(DateTime.UtcNow, 200.0 - i * 10));
|
||||
ilrs.Update(new TValue(DateTime.UtcNow, 200.0 - (i * 10)));
|
||||
}
|
||||
|
||||
// Integral should be below starting value
|
||||
|
||||
@@ -70,12 +70,12 @@ public class LsmaTests
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
double y = 2 * i + 1;
|
||||
double y = (2 * i) + 1;
|
||||
var result = lsma.Update(new TValue(DateTime.UtcNow, y));
|
||||
|
||||
if (i >= period)
|
||||
{
|
||||
double expected = 2 * (i + offset) + 1;
|
||||
double expected = (2 * (i + offset)) + 1;
|
||||
Assert.Equal(expected, result.Value, 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -101,7 +101,7 @@ public class QrmaValidationTests
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
values[i] = 2.0 * i + 5.0;
|
||||
values[i] = (2.0 * i) + 5.0;
|
||||
}
|
||||
|
||||
global::QuanTAlib.Qrma.Batch(values, output, period);
|
||||
@@ -125,7 +125,7 @@ public class QrmaValidationTests
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
values[i] = 0.5 * i * i + i + 3.0;
|
||||
values[i] = (0.5 * i * i) + i + 3.0;
|
||||
}
|
||||
|
||||
global::QuanTAlib.Qrma.Batch(values, output, period);
|
||||
|
||||
@@ -66,7 +66,7 @@ public sealed class RainValidationTests : IDisposable
|
||||
double[] expected = new double[BarCount];
|
||||
for (int i = 0; i < BarCount; i++)
|
||||
{
|
||||
expected[i] = (5.0 * layer0[i] + 4.0 * layer1[i] + 3.0 * layer2[i] + 2.0 * layer3[i]
|
||||
expected[i] = ((5.0 * layer0[i]) + (4.0 * layer1[i]) + (3.0 * layer2[i]) + (2.0 * layer3[i])
|
||||
+ layer4[i] + layer5[i] + layer6[i] + layer7[i] + layer8[i] + layer9[i]) / 20.0;
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ public class RwmaTests
|
||||
var result = rwma.Update(bar2);
|
||||
|
||||
// RWMA = (10*20 + 20*2) / (20+2) = (200+40)/22 = 10.909...
|
||||
double expected = (10.0 * 20.0 + 20.0 * 2.0) / (20.0 + 2.0);
|
||||
double expected = ((10.0 * 20.0) + (20.0 * 2.0)) / (20.0 + 2.0);
|
||||
Assert.Equal(expected, result.Value, 10);
|
||||
|
||||
// Should be closer to 10 (the high-range bar) than 20
|
||||
@@ -684,7 +684,7 @@ public class RwmaTests
|
||||
var result = rwma.Update(quietBar);
|
||||
|
||||
// RWMA = (50*40 + 100*2) / (40+2) = (2000+200)/42 = 52.38...
|
||||
double expected = (50.0 * 40.0 + 100.0 * 2.0) / 42.0;
|
||||
double expected = ((50.0 * 40.0) + (100.0 * 2.0)) / 42.0;
|
||||
Assert.Equal(expected, result.Value, 10);
|
||||
|
||||
// Should be much closer to 50 than 100
|
||||
|
||||
@@ -128,11 +128,11 @@ public class RwmaValidationTests
|
||||
Assert.Equal(10.0, results[0], 6);
|
||||
|
||||
// Bar 1: RWMA = (10*10 + 20*6) / (10+6) = (100+120)/16 = 13.75
|
||||
double expectedBar1 = (10.0 * 10.0 + 20.0 * 6.0) / 16.0;
|
||||
double expectedBar1 = ((10.0 * 10.0) + (20.0 * 6.0)) / 16.0;
|
||||
Assert.Equal(expectedBar1, results[1], 6);
|
||||
|
||||
// Bar 2: RWMA = (10*10 + 20*6 + 30*10) / (10+6+10) = (100+120+300)/26 = 20.0
|
||||
double expectedBar2 = (10.0 * 10.0 + 20.0 * 6.0 + 30.0 * 10.0) / 26.0;
|
||||
double expectedBar2 = ((10.0 * 10.0) + (20.0 * 6.0) + (30.0 * 10.0)) / 26.0;
|
||||
Assert.Equal(expectedBar2, results[2], 6);
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ public class RwmaValidationTests
|
||||
var result = rwma.Update(new TBar(DateTime.UtcNow.AddMinutes(1), 100, 101, 99, 100, 100)); // range=2
|
||||
|
||||
// RWMA = (10*50 + 100*2) / (50+2) = (500+200)/52 = 13.46...
|
||||
double expected = (10.0 * 50.0 + 100.0 * 2.0) / 52.0;
|
||||
double expected = ((10.0 * 50.0) + (100.0 * 2.0)) / 52.0;
|
||||
Assert.Equal(expected, result.Value, 6);
|
||||
|
||||
// RWMA should be much closer to 10 than to 100
|
||||
|
||||
@@ -394,12 +394,12 @@ public class SgmaTests
|
||||
double[] prices = new double[20];
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
prices[i] = 100 + i * 5;
|
||||
prices[i] = 100 + (i * 5);
|
||||
}
|
||||
|
||||
for (int i = 10; i < 20; i++)
|
||||
{
|
||||
prices[i] = 145 - (i - 10) * 5;
|
||||
prices[i] = 145 - ((i - 10) * 5);
|
||||
}
|
||||
|
||||
var sgma2 = new Sgma(5, 2);
|
||||
|
||||
@@ -101,7 +101,7 @@ public class SgmaValidationTests
|
||||
double[] prices = new double[20];
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
prices[i] = 100.0 + i * 10.0; // Linear: 100, 110, 120, ..., 290
|
||||
prices[i] = 100.0 + (i * 10.0); // Linear: 100, 110, 120, ..., 290
|
||||
}
|
||||
|
||||
var sgma0 = new Sgma(period, 0);
|
||||
|
||||
@@ -230,7 +230,7 @@ public sealed class SinemaValidationTests : IDisposable
|
||||
double w3 = Math.Sin(Math.PI * 4 / 5);
|
||||
double w4 = Math.Sin(Math.PI * 5 / 5);
|
||||
|
||||
double expectedSum = 100 * w0 + 102 * w1 + 104 * w2 + 103 * w3 + 105 * w4;
|
||||
double expectedSum = (100 * w0) + (102 * w1) + (104 * w2) + (103 * w3) + (105 * w4);
|
||||
double weightSum = w0 + w1 + w2 + w3 + w4;
|
||||
double expected = expectedSum / weightSum;
|
||||
|
||||
@@ -273,7 +273,7 @@ public sealed class SinemaValidationTests : IDisposable
|
||||
// w0 = sin(π*1/2) = 1, w1 = sin(π*2/2) = 0
|
||||
// Result = (100*1 + 110*0) / 1 = 100
|
||||
double r2 = sinema.Update(new TValue(DateTime.UtcNow, 110)).Value;
|
||||
double expected2 = (100 * Math.Sin(Math.PI * 1 / 2) + 110 * Math.Sin(Math.PI * 2 / 2))
|
||||
double expected2 = ((100 * Math.Sin(Math.PI * 1 / 2)) + (110 * Math.Sin(Math.PI * 2 / 2)))
|
||||
/ (Math.Sin(Math.PI * 1 / 2) + Math.Sin(Math.PI * 2 / 2));
|
||||
Assert.Equal(expected2, r2, 1e-10);
|
||||
|
||||
|
||||
@@ -85,12 +85,12 @@ public class Sp15Tests
|
||||
const int n = 30;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
double val = intercept + slope * i;
|
||||
double val = intercept + (slope * i);
|
||||
sp15.Update(new TValue(DateTime.UtcNow.AddMinutes(i).Ticks, val));
|
||||
}
|
||||
// Centered at lag 7: output at bar n-1 matches polynomial at bar (n-1)-7
|
||||
int centerIdx = n - 1 - 7;
|
||||
double expected = intercept + slope * centerIdx;
|
||||
double expected = intercept + (slope * centerIdx);
|
||||
Assert.Equal(expected, sp15.Last.Value, 1e-6);
|
||||
}
|
||||
|
||||
@@ -101,11 +101,11 @@ public class Sp15Tests
|
||||
const int n = 40;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
double val = 0.1 * i * i + 2.0 * i + 5.0;
|
||||
double val = (0.1 * i * i) + (2.0 * i) + 5.0;
|
||||
sp15.Update(new TValue(DateTime.UtcNow.AddMinutes(i).Ticks, val));
|
||||
}
|
||||
int k = n - 1 - 7;
|
||||
double expected = 0.1 * k * k + 2.0 * k + 5.0;
|
||||
double expected = (0.1 * k * k) + (2.0 * k) + 5.0;
|
||||
Assert.Equal(expected, sp15.Last.Value, 1e-4);
|
||||
}
|
||||
|
||||
@@ -116,11 +116,11 @@ public class Sp15Tests
|
||||
const int n = 40;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
double val = 0.001 * i * i * i + 0.1 * i * i + 2.0 * i + 5.0;
|
||||
double val = (0.001 * i * i * i) + (0.1 * i * i) + (2.0 * i) + 5.0;
|
||||
sp15.Update(new TValue(DateTime.UtcNow.AddMinutes(i).Ticks, val));
|
||||
}
|
||||
int k = n - 1 - 7;
|
||||
double expected = 0.001 * k * k * k + 0.1 * k * k + 2.0 * k + 5.0;
|
||||
double expected = (0.001 * k * k * k) + (0.1 * k * k) + (2.0 * k) + 5.0;
|
||||
Assert.Equal(expected, sp15.Last.Value, 1e-2);
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public class Sp15Tests
|
||||
// Multiple corrections
|
||||
for (int c = 0; c < 5; c++)
|
||||
{
|
||||
sp15.Update(new TValue(DateTime.UtcNow.Ticks, 500.0 + c * 10), isNew: false);
|
||||
sp15.Update(new TValue(DateTime.UtcNow.Ticks, 500.0 + (c * 10)), isNew: false);
|
||||
}
|
||||
// Restore
|
||||
sp15.Update(series[19], isNew: false);
|
||||
@@ -527,7 +527,7 @@ public class Sp15Tests
|
||||
// All 100 contributes: 100 * sum(weights) = 100
|
||||
// Extra 100 at center contributes: 100 * (74/320) = 23.125
|
||||
// Total = 100 + 23.125 = 123.125
|
||||
double expected = 100.0 + 100.0 * 74.0 / 320.0;
|
||||
double expected = 100.0 + (100.0 * 74.0 / 320.0);
|
||||
Assert.Equal(expected, sp15.Last.Value, 1e-10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,12 +68,12 @@ public class Sp15ValidationTests
|
||||
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
double val = a + b * i;
|
||||
double val = a + (b * i);
|
||||
sp15.Update(new TValue(DateTime.UtcNow.AddSeconds(i), val));
|
||||
}
|
||||
|
||||
int centerIdx = total - 1 - 7;
|
||||
double expected = a + b * centerIdx;
|
||||
double expected = a + (b * centerIdx);
|
||||
Assert.Equal(expected, sp15.Last.Value, 1e-6);
|
||||
}
|
||||
|
||||
@@ -86,12 +86,12 @@ public class Sp15ValidationTests
|
||||
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
double val = a + b * i + c * i * i;
|
||||
double val = a + (b * i) + (c * i * i);
|
||||
sp15.Update(new TValue(DateTime.UtcNow.AddSeconds(i), val));
|
||||
}
|
||||
|
||||
int centerIdx = total - 1 - 7;
|
||||
double expected = a + b * centerIdx + c * centerIdx * centerIdx;
|
||||
double expected = a + (b * centerIdx) + (c * centerIdx * centerIdx);
|
||||
Assert.Equal(expected, sp15.Last.Value, 1e-4);
|
||||
}
|
||||
|
||||
@@ -104,12 +104,12 @@ public class Sp15ValidationTests
|
||||
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
double val = a + b * i + c * i * i + d * i * i * i;
|
||||
double val = a + (b * i) + (c * i * i) + (d * i * i * i);
|
||||
sp15.Update(new TValue(DateTime.UtcNow.AddSeconds(i), val));
|
||||
}
|
||||
|
||||
int centerIdx = total - 1 - 7;
|
||||
double expected = a + b * centerIdx + c * centerIdx * centerIdx + d * centerIdx * centerIdx * centerIdx;
|
||||
double expected = a + (b * centerIdx) + (c * centerIdx * centerIdx) + (d * centerIdx * centerIdx * centerIdx);
|
||||
Assert.Equal(expected, sp15.Last.Value, 1.0);
|
||||
}
|
||||
|
||||
@@ -172,8 +172,8 @@ public class Sp15ValidationTests
|
||||
double[] reverse = new double[15];
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
forward[i] = 10.0 + 2.0 * i;
|
||||
reverse[i] = 10.0 + 2.0 * (14 - i);
|
||||
forward[i] = 10.0 + (2.0 * i);
|
||||
reverse[i] = 10.0 + (2.0 * (14 - i));
|
||||
}
|
||||
|
||||
TValue fwdResult = default;
|
||||
@@ -186,7 +186,7 @@ public class Sp15ValidationTests
|
||||
|
||||
// For linear input centered at i=7: forward center = 10+14=24, reverse center = 10+14=24
|
||||
// Both should give the same result for symmetric weights applied to symmetric-about-center linear data
|
||||
double expected = 2.0 * (10.0 + 2.0 * 7.0);
|
||||
double expected = 2.0 * (10.0 + (2.0 * 7.0));
|
||||
Assert.Equal(expected, fwdResult.Value + revResult.Value, 1e-6);
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ public class Sp15ValidationTests
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
// Pure period-4 sinusoid centered at 100
|
||||
double val = 100.0 + 10.0 * Math.Sin(2.0 * Math.PI * i / 4.0);
|
||||
double val = 100.0 + (10.0 * Math.Sin(2.0 * Math.PI * i / 4.0));
|
||||
sp15.Update(new TValue(DateTime.UtcNow.AddSeconds(i), val));
|
||||
}
|
||||
// After warmup, the output should be ~100 (sinusoid suppressed)
|
||||
@@ -214,7 +214,7 @@ public class Sp15ValidationTests
|
||||
const int n = 60;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
double val = 100.0 + 10.0 * Math.Sin(2.0 * Math.PI * i / 5.0);
|
||||
double val = 100.0 + (10.0 * Math.Sin(2.0 * Math.PI * i / 5.0));
|
||||
sp15.Update(new TValue(DateTime.UtcNow.AddSeconds(i), val));
|
||||
}
|
||||
Assert.Equal(100.0, sp15.Last.Value, 0.5);
|
||||
|
||||
@@ -243,7 +243,6 @@ public class SwmaTests
|
||||
swma.Update(new TValue(DateTime.UtcNow.AddSeconds(i), 100.0));
|
||||
}
|
||||
|
||||
|
||||
swma.Update(new TValue(DateTime.UtcNow.AddSeconds(5), double.NaN));
|
||||
// After NaN, last-valid substitution should produce finite result
|
||||
Assert.True(double.IsFinite(swma.Last.Value));
|
||||
|
||||
@@ -29,7 +29,7 @@ public class TrimaValidationTests
|
||||
var qResult = trima.Update(_testData.Data);
|
||||
|
||||
// Calculate Skender Composite TRIMA: SMA(SMA(x, p1), p2)
|
||||
int p1 = period / 2 + 1;
|
||||
int p1 = (period / 2) + 1;
|
||||
int p2 = (period + 1) / 2;
|
||||
|
||||
var sma1Results = _testData.SkenderQuotes.GetSma(p1).ToList();
|
||||
|
||||
@@ -102,12 +102,12 @@ public class TsfTests
|
||||
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
double y = 2.0 * i + 5.0;
|
||||
double y = (2.0 * i) + 5.0;
|
||||
var result = tsf.Update(new TValue(DateTime.UtcNow, y));
|
||||
|
||||
if (i >= period)
|
||||
{
|
||||
double expected = 2.0 * (i + 1) + 5.0;
|
||||
double expected = (2.0 * (i + 1)) + 5.0;
|
||||
Assert.Equal(expected, result.Value, 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user