[CodeFactor] Apply fixes to commit 0606491

This commit is contained in:
codefactor-io
2026-03-12 19:37:50 +00:00
parent 060649192f
commit 8f79257155
384 changed files with 1197 additions and 1215 deletions
+1 -1
View File
@@ -608,7 +608,7 @@ public class AberrTests
var series = new TSeries();
for (int i = 0; i < 10; i++)
{
series.Add(DateTime.UtcNow, 100 + i * 10); // 100, 110, 120, ...
series.Add(DateTime.UtcNow, 100 + (i * 10)); // 100, 110, 120, ...
}
// Multiplier 1.0
+18 -18
View File
@@ -179,8 +179,8 @@ public class AccBandsTests
// SMA(3) of adjLow: (54 + 58.80952 + 63.63636) / 3 ≈ 58.81529
// SMA(3) of Close: (100+105+110)/3 = 105
double expectedUpper = (154.0 + 115.0 * (1.0 + 4.0 * 20.0 / 210.0) + 120.0 * (1.0 + 4.0 * 20.0 / 220.0)) / 3.0;
double expectedLower = (54.0 + 95.0 * (1.0 - 4.0 * 20.0 / 210.0) + 100.0 * (1.0 - 4.0 * 20.0 / 220.0)) / 3.0;
double expectedUpper = (154.0 + (115.0 * (1.0 + (4.0 * 20.0 / 210.0))) + (120.0 * (1.0 + (4.0 * 20.0 / 220.0)))) / 3.0;
double expectedLower = (54.0 + (95.0 * (1.0 - (4.0 * 20.0 / 210.0))) + (100.0 * (1.0 - (4.0 * 20.0 / 220.0)))) / 3.0;
Assert.Equal(105.0, accBands.Last.Value, 1e-10);
Assert.Equal(expectedUpper, accBands.Upper.Value, 1e-10);
@@ -399,8 +399,8 @@ public class AccBandsTests
// adjLow = 100*(1-4*0.090909) = 100*0.636364 ≈ 63.63636
accBands.Update(new TBar(DateTime.UtcNow, 110, 120, 100, 110, 1000));
Assert.Equal(110.0, accBands.Last.Value, 1e-10);
Assert.Equal(120.0 * (1.0 + 4.0 * 20.0 / 220.0), accBands.Upper.Value, 1e-10);
Assert.Equal(100.0 * (1.0 - 4.0 * 20.0 / 220.0), accBands.Lower.Value, 1e-10);
Assert.Equal(120.0 * (1.0 + (4.0 * 20.0 / 220.0)), accBands.Upper.Value, 1e-10);
Assert.Equal(100.0 * (1.0 - (4.0 * 20.0 / 220.0)), accBands.Lower.Value, 1e-10);
}
// ============== Span API Tests ==============
@@ -496,12 +496,12 @@ public class AccBandsTests
// Bar 2: H=120, L=100 => w=20/220, adjH=120*(1+4*20/220), adjL=100*(1-4*20/220)
// SMA(3) of Close: (100+105+110)/3 = 105
double adjH0 = 110.0 * (1.0 + 4.0 * 20.0 / 200.0);
double adjH1 = 115.0 * (1.0 + 4.0 * 20.0 / 210.0);
double adjH2 = 120.0 * (1.0 + 4.0 * 20.0 / 220.0);
double adjL0 = 90.0 * (1.0 - 4.0 * 20.0 / 200.0);
double adjL1 = 95.0 * (1.0 - 4.0 * 20.0 / 210.0);
double adjL2 = 100.0 * (1.0 - 4.0 * 20.0 / 220.0);
double adjH0 = 110.0 * (1.0 + (4.0 * 20.0 / 200.0));
double adjH1 = 115.0 * (1.0 + (4.0 * 20.0 / 210.0));
double adjH2 = 120.0 * (1.0 + (4.0 * 20.0 / 220.0));
double adjL0 = 90.0 * (1.0 - (4.0 * 20.0 / 200.0));
double adjL1 = 95.0 * (1.0 - (4.0 * 20.0 / 210.0));
double adjL2 = 100.0 * (1.0 - (4.0 * 20.0 / 220.0));
Assert.Equal(105.0, middle[2], 1e-10);
Assert.Equal((adjH0 + adjH1 + adjH2) / 3.0, upper[2], 1e-10);
@@ -657,12 +657,12 @@ public class AccBandsTests
// Bar 2: H=120,L=100,C=110 -> w=20/220, adjH=120*(1+80/220), adjL=100*(1-80/220)
// Bar 3: H=125,L=105,C=115 -> w=20/230, adjH=125*(1+80/230), adjL=105*(1-80/230)
// Bar 4: H=130,L=110,C=120 -> w=20/240, adjH=130*(1+80/240), adjL=110*(1-80/240)
double adjH2 = 120.0 * (1.0 + 4.0 * 20.0 / 220.0);
double adjL2 = 100.0 * (1.0 - 4.0 * 20.0 / 220.0);
double adjH3 = 125.0 * (1.0 + 4.0 * 20.0 / 230.0);
double adjL3 = 105.0 * (1.0 - 4.0 * 20.0 / 230.0);
double adjH4 = 130.0 * (1.0 + 4.0 * 20.0 / 240.0);
double adjL4 = 110.0 * (1.0 - 4.0 * 20.0 / 240.0);
double adjH2 = 120.0 * (1.0 + (4.0 * 20.0 / 220.0));
double adjL2 = 100.0 * (1.0 - (4.0 * 20.0 / 220.0));
double adjH3 = 125.0 * (1.0 + (4.0 * 20.0 / 230.0));
double adjL3 = 105.0 * (1.0 - (4.0 * 20.0 / 230.0));
double adjH4 = 130.0 * (1.0 + (4.0 * 20.0 / 240.0));
double adjL4 = 110.0 * (1.0 - (4.0 * 20.0 / 240.0));
Assert.Equal(115.0, accBands.Last.Value, 1e-10);
Assert.Equal((adjH2 + adjH3 + adjH4) / 3.0, accBands.Upper.Value, 1e-10);
@@ -672,8 +672,8 @@ public class AccBandsTests
accBands.Update(new TBar(DateTime.UtcNow, 125, 135, 115, 125, 1000));
// New window: bars [3,4,5]
// Bar 5: H=135,L=115,C=125 -> w=20/250, adjH=135*(1+80/250), adjL=115*(1-80/250)
double adjH5 = 135.0 * (1.0 + 4.0 * 20.0 / 250.0);
double adjL5 = 115.0 * (1.0 - 4.0 * 20.0 / 250.0);
double adjH5 = 135.0 * (1.0 + (4.0 * 20.0 / 250.0));
double adjL5 = 115.0 * (1.0 - (4.0 * 20.0 / 250.0));
Assert.Equal(120.0, accBands.Last.Value, 1e-10);
Assert.Equal((adjH3 + adjH4 + adjH5) / 3.0, accBands.Upper.Value, 1e-10);
@@ -63,12 +63,12 @@ public sealed class AccBandsValidationTests : IDisposable
var accBands = new AccBands(3, 4.0);
var (middle, upper, lower) = accBands.Update(series);
double adjH0 = 12.0 * (1.0 + 4.0 * 4.0 / 20.0);
double adjH1 = 14.0 * (1.0 + 4.0 * 4.0 / 24.0);
double adjH2 = 16.0 * (1.0 + 4.0 * 4.0 / 28.0);
double adjL0 = 8.0 * (1.0 - 4.0 * 4.0 / 20.0);
double adjL1 = 10.0 * (1.0 - 4.0 * 4.0 / 24.0);
double adjL2 = 12.0 * (1.0 - 4.0 * 4.0 / 28.0);
double adjH0 = 12.0 * (1.0 + (4.0 * 4.0 / 20.0));
double adjH1 = 14.0 * (1.0 + (4.0 * 4.0 / 24.0));
double adjH2 = 16.0 * (1.0 + (4.0 * 4.0 / 28.0));
double adjL0 = 8.0 * (1.0 - (4.0 * 4.0 / 20.0));
double adjL1 = 10.0 * (1.0 - (4.0 * 4.0 / 24.0));
double adjL2 = 12.0 * (1.0 - (4.0 * 4.0 / 28.0));
Assert.Equal(12.0, middle.Last.Value, 1e-10);
Assert.Equal((adjH0 + adjH1 + adjH2) / 3.0, upper.Last.Value, 1e-10);
@@ -106,8 +106,8 @@ public sealed class AccBandsValidationTests : IDisposable
double l = c - 5;
double denom = h + l;
double w = (h - l) / denom;
sumAdjH += h * (1.0 + 4.0 * w);
sumAdjL += l * (1.0 - 4.0 * w);
sumAdjH += h * (1.0 + (4.0 * w));
sumAdjL += l * (1.0 - (4.0 * w));
}
Assert.Equal(sumAdjH / 5.0, upper.Last.Value, 1e-10);
Assert.Equal(sumAdjL / 5.0, lower.Last.Value, 1e-10);
@@ -39,7 +39,6 @@ public sealed class ApchannelValidationTests : IDisposable
/// we validate against mathematical correctness by comparing the span and streaming results
/// with manually calculated EMA values for high and low prices.
/// </summary>
[Fact]
public void Validate_AllModes_ProduceSameResult()
{
+1 -1
View File
@@ -168,7 +168,7 @@ public class ApzTests
// Generate 9 corrections with isNew=false (different values)
for (int i = 0; i < 9; i++)
{
var correctionBar = new TBar(tenthBar.Time, tenthBar.Open + i, tenthBar.High + i * 2, tenthBar.Low - i, tenthBar.Close + i, tenthBar.Volume);
var correctionBar = new TBar(tenthBar.Time, tenthBar.Open + i, tenthBar.High + (i * 2), tenthBar.Low - i, tenthBar.Close + i, tenthBar.Volume);
apz.Update(correctionBar, isNew: false);
}
@@ -383,7 +383,7 @@ public sealed class ApzValidationTests : IDisposable
}
else
{
ema = alpha * bar.Close + (1 - alpha) * ema;
ema = (alpha * bar.Close) + ((1 - alpha) * ema);
}
emaResults.Add(ema);
@@ -332,8 +332,8 @@ public sealed class AtrBandsValidationTests : IDisposable
double expectedMid = smaResult[i].Sma!.Value;
double expectedAtr = atrResult[i].Atr!.Value;
double expectedUp = expectedMid + multiplier * expectedAtr;
double expectedLo = expectedMid - multiplier * expectedAtr;
double expectedUp = expectedMid + (multiplier * expectedAtr);
double expectedLo = expectedMid - (multiplier * expectedAtr);
Assert.True(
Math.Abs(qMid[i].Value - expectedMid) <= ValidationHelper.SkenderTolerance,
+1 -1
View File
@@ -411,7 +411,7 @@ public class BbandsTests
DateTime startTime = DateTime.UtcNow;
for (int i = 0; i < data.Length; i++)
{
streamBbands.Update(new TValue(startTime + i * TimeSpan.FromSeconds(1), data[i]), isNew: true);
streamBbands.Update(new TValue(startTime + (i * TimeSpan.FromSeconds(1)), data[i]), isNew: true);
}
Assert.Equal(streamBbands.Middle.Value, primedBbands.Middle.Value, precision: 10);
@@ -22,7 +22,7 @@ public class JbandsIndicatorTests
public void MinHistoryDepths_MatchesWarmupFormula()
{
var ind = new JbandsIndicator { Period = 14 };
int expected = (int)Math.Ceiling(20.0 + 80.0 * Math.Pow(14, 0.36));
int expected = (int)Math.Ceiling(20.0 + (80.0 * Math.Pow(14, 0.36)));
Assert.Equal(expected, ind.MinHistoryDepths);
}
@@ -155,7 +155,7 @@ public class JbandsIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double price = 100 + Math.Sin(i * 0.3) * 10;
double price = 100 + (Math.Sin(i * 0.3) * 10);
indZero.HistoricalData.AddBar(now.AddMinutes(i), price - 1, price + 2, price - 2, price);
indPos.HistoricalData.AddBar(now.AddMinutes(i), price - 1, price + 2, price - 2, price);
indZero.ProcessUpdate(new UpdateArgs(i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar));
@@ -185,7 +185,7 @@ public class JbandsIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double price = 100 + Math.Sin(i * 0.3) * 10;
double price = 100 + (Math.Sin(i * 0.3) * 10);
indPos.HistoricalData.AddBar(now.AddMinutes(i), price - 1, price + 2, price - 2, price);
indNeg.HistoricalData.AddBar(now.AddMinutes(i), price - 1, price + 2, price - 2, price);
indPos.ProcessUpdate(new UpdateArgs(i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar));
+1 -1
View File
@@ -617,7 +617,7 @@ public class JbandsTests
for (int i = 0; i < 100; i++)
{
var val = new TValue(DateTime.UtcNow.AddMinutes(i), 100 + i * 0.5);
var val = new TValue(DateTime.UtcNow.AddMinutes(i), 100 + (i * 0.5));
src.Add(val.Time, val.Value);
j.Update(val, isNew: true);
}
+1 -1
View File
@@ -158,7 +158,7 @@ public class MaenvTests
// Actual: first bar w=9, second bar: newest w=9, oldest w=6; sum=110*9+100*6=990+600=1590; norm=15
// WMA = 1590/15 = 106
m.Update(new TValue(DateTime.UtcNow, 110));
double expected2 = (110 * 9 + 100 * 6) / 15.0;
double expected2 = ((110 * 9) + (100 * 6)) / 15.0;
Assert.Equal(expected2, m.Last.Value, 1e-10);
}
@@ -120,11 +120,11 @@ public sealed class MaenvValidationTests : IDisposable
Assert.Equal(100.0, ind.Last.Value, 1e-10);
ind.Update(series[1]);
double expected2 = (110.0 * 9 + 100.0 * 6) / 15.0;
double expected2 = ((110.0 * 9) + (100.0 * 6)) / 15.0;
Assert.Equal(expected2, ind.Last.Value, 1e-10);
ind.Update(series[2]);
double expected3 = (120.0 * 9 + 110.0 * 6 + 100.0 * 3) / 18.0;
double expected3 = ((120.0 * 9) + (110.0 * 6) + (100.0 * 3)) / 18.0;
Assert.Equal(expected3, ind.Last.Value, 1e-10);
_output.WriteLine("Maenv WMA manual calculation validated");
@@ -129,7 +129,7 @@ public class RegchannelIndicatorTests
// Add some volatility to ensure non-zero stddev
for (int i = 0; i < 20; i++)
{
double price = 100 + Math.Sin(i * 0.5) * 10;
double price = 100 + (Math.Sin(i * 0.5) * 10);
ind.HistoricalData.AddBar(now.AddMinutes(i), price, price + 5, price - 5, price, 1000);
ind.ProcessUpdate(new UpdateArgs(i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar));
}
@@ -173,7 +173,7 @@ public class RegchannelIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
double price = 100 + i * 0.5;
double price = 100 + (i * 0.5);
ind1.HistoricalData.AddBar(now.AddMinutes(i), price, price + 5, price - 5, price);
ind2.HistoricalData.AddBar(now.AddMinutes(i), price, price + 5, price - 5, price);
ind1.ProcessUpdate(new UpdateArgs(i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar));
@@ -266,14 +266,14 @@ public class RegchannelIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double price = 100 + i * 2; // Strong uptrend
double price = 100 + (i * 2); // Strong uptrend
ind.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price);
ind.ProcessUpdate(new UpdateArgs(i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar));
}
// After warmup, middle should be close to the current regression line value
double middle = ind.LinesSeries[0].GetValue(0);
double lastPrice = 100 + 29 * 2; // 158
double lastPrice = 100 + (29 * 2); // 158
// Middle should be close to last price (within reasonable range for regression)
Assert.True(Math.Abs(middle - lastPrice) < 10, $"Middle ({middle}) should be close to last price ({lastPrice})");
@@ -90,7 +90,7 @@ public class RegchannelTests
// Feed perfect linear data: y = 100 + 2*i (slope = 2)
for (int i = 0; i < 20; i++)
{
ind.Update(new TValue(now.AddMinutes(i), 100 + 2 * i));
ind.Update(new TValue(now.AddMinutes(i), 100 + (2 * i)));
}
// Slope should be 2
@@ -107,13 +107,13 @@ public class RegchannelTests
// Low volatility: close to linear
for (int i = 0; i < 20; i++)
{
ind1.Update(new TValue(now.AddMinutes(i), 100 + i + 0.1 * Math.Sin(i)));
ind1.Update(new TValue(now.AddMinutes(i), 100 + i + (0.1 * Math.Sin(i))));
}
// High volatility: large deviations from linear
for (int i = 0; i < 20; i++)
{
ind2.Update(new TValue(now.AddMinutes(i), 100 + i + 5 * Math.Sin(i)));
ind2.Update(new TValue(now.AddMinutes(i), 100 + i + (5 * Math.Sin(i))));
}
double width1 = ind1.Upper.Value - ind1.Lower.Value;
@@ -130,7 +130,7 @@ public class RegchannelTests
for (int i = 0; i < 20; i++)
{
ind.Update(new TValue(now.AddMinutes(i), 100 + i + Math.Sin(i) * 3));
ind.Update(new TValue(now.AddMinutes(i), 100 + i + (Math.Sin(i) * 3)));
}
double upperDist = ind.Upper.Value - ind.Last.Value;
@@ -148,7 +148,7 @@ public class RegchannelTests
for (int i = 0; i < 20; i++)
{
double val = 100 + i + Math.Sin(i) * 3;
double val = 100 + i + (Math.Sin(i) * 3);
ind1.Update(new TValue(now.AddMinutes(i), val));
ind2.Update(new TValue(now.AddMinutes(i), val));
}
@@ -465,7 +465,7 @@ public class RegchannelTests
for (int i = 0; i < 10000; i++)
{
double val = 100 + Math.Sin(i * 0.01) * 10 + i * 0.001;
double val = 100 + (Math.Sin(i * 0.01) * 10) + (i * 0.001);
ind.Update(new TValue(now.AddMinutes(i), val));
}
@@ -81,7 +81,7 @@ public sealed class RegchannelValidationTests : IDisposable
// Perfect linear trend: 100, 110, 120, 130, 140
for (int i = 0; i < 5; i++)
{
series.Add(new TValue(t0.AddMinutes(i), 100 + i * 10));
series.Add(new TValue(t0.AddMinutes(i), 100 + (i * 10)));
}
var ind = new Regchannel(5, 2.0);
@@ -424,7 +424,7 @@ public sealed class RegchannelValidationTests : IDisposable
var t0 = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
uptrend.Add(new TValue(t0.AddMinutes(i), 100 + i * 2 + (i % 3))); // Noisy uptrend
uptrend.Add(new TValue(t0.AddMinutes(i), 100 + (i * 2) + (i % 3))); // Noisy uptrend
}
var indUp = new Regchannel(10, 2.0);
@@ -438,7 +438,7 @@ public sealed class RegchannelValidationTests : IDisposable
var downtrend = new TSeries();
for (int i = 0; i < 20; i++)
{
downtrend.Add(new TValue(t0.AddMinutes(i), 200 - i * 2 + (i % 3))); // Noisy downtrend
downtrend.Add(new TValue(t0.AddMinutes(i), 200 - (i * 2) + (i % 3))); // Noisy downtrend
}
var indDown = new Regchannel(10, 2.0);
@@ -129,7 +129,7 @@ public class SdchannelIndicatorTests
// Add some volatility to ensure non-zero stddev
for (int i = 0; i < 20; i++)
{
double price = 100 + Math.Sin(i * 0.5) * 10;
double price = 100 + (Math.Sin(i * 0.5) * 10);
ind.HistoricalData.AddBar(now.AddMinutes(i), price, price + 5, price - 5, price, 1000);
ind.ProcessUpdate(new UpdateArgs(i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar));
}
@@ -173,7 +173,7 @@ public class SdchannelIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
double price = 100 + i * 0.5;
double price = 100 + (i * 0.5);
ind1.HistoricalData.AddBar(now.AddMinutes(i), price, price + 5, price - 5, price);
ind2.HistoricalData.AddBar(now.AddMinutes(i), price, price + 5, price - 5, price);
ind1.ProcessUpdate(new UpdateArgs(i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar));
@@ -266,14 +266,14 @@ public class SdchannelIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double price = 100 + i * 2; // Strong uptrend
double price = 100 + (i * 2); // Strong uptrend
ind.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price);
ind.ProcessUpdate(new UpdateArgs(i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar));
}
// After warmup, middle should be close to the current regression line value
double middle = ind.LinesSeries[0].GetValue(0);
double lastPrice = 100 + 29 * 2; // 158
double lastPrice = 100 + (29 * 2); // 158
// Middle should be close to last price (within reasonable range for regression)
Assert.True(Math.Abs(middle - lastPrice) < 10, $"Middle ({middle}) should be close to last price ({lastPrice})");
@@ -192,7 +192,7 @@ public class SdchannelTests
// Perfect linear trend: 100, 102, 104, 106, 108
for (int i = 0; i < 5; i++)
{
s.Update(new TValue(DateTime.UtcNow, 100 + i * 2));
s.Update(new TValue(DateTime.UtcNow, 100 + (i * 2)));
}
// All points lie exactly on regression line
@@ -90,7 +90,7 @@ public sealed class SdchannelValidationTests : IDisposable
// Perfect linear trend: 100, 110, 120, 130, 140
for (int i = 0; i < 5; i++)
{
series.Add(new TValue(t0.AddMinutes(i), 100 + i * 10));
series.Add(new TValue(t0.AddMinutes(i), 100 + (i * 10)));
}
var ind = new Sdchannel(5, 2.0);
@@ -433,7 +433,7 @@ public sealed class SdchannelValidationTests : IDisposable
var t0 = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
uptrend.Add(new TValue(t0.AddMinutes(i), 100 + i * 2 + (i % 3))); // Noisy uptrend
uptrend.Add(new TValue(t0.AddMinutes(i), 100 + (i * 2) + (i % 3))); // Noisy uptrend
}
var indUp = new Sdchannel(10, 2.0);
@@ -447,7 +447,7 @@ public sealed class SdchannelValidationTests : IDisposable
var downtrend = new TSeries();
for (int i = 0; i < 20; i++)
{
downtrend.Add(new TValue(t0.AddMinutes(i), 200 - i * 2 + (i % 3))); // Noisy downtrend
downtrend.Add(new TValue(t0.AddMinutes(i), 200 - (i * 2) + (i % 3))); // Noisy downtrend
}
var indDown = new Sdchannel(10, 2.0);
@@ -396,7 +396,7 @@ public sealed class StarchannelValidationTests : IDisposable
// Create predictable data: 100, 102, 104, 106, 108
for (int i = 0; i < 5; i++)
{
double close = 100 + i * 2;
double close = 100 + (i * 2);
series.Add(new TBar(t0.AddMinutes(i), close, close + 5, close - 5, close, 100));
}
+1 -1
View File
@@ -403,7 +403,7 @@ public class StbandsTests
var series = new TSeries();
for (int i = 0; i < 20; i++)
{
series.Add(DateTime.UtcNow.AddMinutes(i), 100 + i * 0.5);
series.Add(DateTime.UtcNow.AddMinutes(i), 100 + (i * 0.5));
}
TSeries result = stbands.Update(series);
@@ -132,7 +132,7 @@ public class TtmLrcIndicatorTests
// Add some volatility to ensure non-zero stddev
for (int i = 0; i < 20; i++)
{
double price = 100 + Math.Sin(i * 0.5) * 10;
double price = 100 + (Math.Sin(i * 0.5) * 10);
ind.HistoricalData.AddBar(now.AddMinutes(i), price, price + 5, price - 5, price, 1000);
ind.ProcessUpdate(new UpdateArgs(i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar));
}
@@ -214,7 +214,7 @@ public class TtmLrcIndicatorTests
// Perfect linear data: y = 100 + 2*i
for (int i = 0; i < 20; i++)
{
double price = 100 + i * 2;
double price = 100 + (i * 2);
ind.HistoricalData.AddBar(now.AddMinutes(i), price, price, price, price);
ind.ProcessUpdate(new UpdateArgs(i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar));
}
@@ -264,14 +264,14 @@ public class TtmLrcIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double price = 100 + i * 2; // Strong uptrend
double price = 100 + (i * 2); // Strong uptrend
ind.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price);
ind.ProcessUpdate(new UpdateArgs(i == 0 ? UpdateReason.HistoricalBar : UpdateReason.NewBar));
}
// After warmup, midline should be close to the current regression line value
double midline = ind.LinesSeries[0].GetValue(0);
double lastPrice = 100 + 29 * 2; // 158
double lastPrice = 100 + (29 * 2); // 158
// Midline should be close to last price (within reasonable range for regression)
Assert.True(Math.Abs(midline - lastPrice) < 10, $"Midline ({midline}) should be close to last price ({lastPrice})");
+11 -11
View File
@@ -166,7 +166,7 @@ public class TtmLrcTests
// Perfect linear data: y = 100 + 2*x
for (int i = 0; i < 15; i++)
{
indicator.Update(new TValue(now.AddMinutes(i), 100 + 2.0 * i), isNew: true);
indicator.Update(new TValue(now.AddMinutes(i), 100 + (2.0 * i)), isNew: true);
}
Assert.True(indicator.IsHot);
@@ -189,7 +189,7 @@ public class TtmLrcTests
for (int i = 0; i < 15; i++)
{
indicator.Update(new TValue(now.AddMinutes(i), 100 + 5.0 * i), isNew: true);
indicator.Update(new TValue(now.AddMinutes(i), 100 + (5.0 * i)), isNew: true);
}
Assert.True(indicator.Slope > 0, $"Slope should be positive for uptrend, got {indicator.Slope}");
@@ -203,7 +203,7 @@ public class TtmLrcTests
for (int i = 0; i < 15; i++)
{
indicator.Update(new TValue(now.AddMinutes(i), 100 - 3.0 * i), isNew: true);
indicator.Update(new TValue(now.AddMinutes(i), 100 - (3.0 * i)), isNew: true);
}
Assert.True(indicator.Slope < 0, $"Slope should be negative for downtrend, got {indicator.Slope}");
@@ -236,7 +236,7 @@ public class TtmLrcTests
for (int i = 0; i < 15; i++)
{
indicator.Update(new TValue(now.AddMinutes(i), 100 + 2.0 * i), isNew: true);
indicator.Update(new TValue(now.AddMinutes(i), 100 + (2.0 * i)), isNew: true);
}
Assert.True(Math.Abs(indicator.RSquared - 1.0) < 1e-9, $"R² should be 1.0 for perfect linear fit, got {indicator.RSquared}");
@@ -313,7 +313,7 @@ public class TtmLrcTests
for (int i = 0; i < 8; i++)
{
indicator.Update(new TValue(now.AddMinutes(i), 100 + i * 2), isNew: true);
indicator.Update(new TValue(now.AddMinutes(i), 100 + (i * 2)), isNew: true);
}
double baseMid = indicator.Midline.Value;
@@ -321,11 +321,11 @@ public class TtmLrcTests
// Multiple corrections
for (int j = 0; j < 5; j++)
{
indicator.Update(new TValue(now.AddMinutes(7), 150 + j * 10), isNew: false);
indicator.Update(new TValue(now.AddMinutes(7), 150 + (j * 10)), isNew: false);
}
// Revert to original
indicator.Update(new TValue(now.AddMinutes(7), 100 + 7 * 2), isNew: false);
indicator.Update(new TValue(now.AddMinutes(7), 100 + (7 * 2)), isNew: false);
Assert.Equal(baseMid, indicator.Midline.Value, 10);
}
@@ -492,7 +492,7 @@ public class TtmLrcTests
for (int i = 0; i < 10; i++)
{
indicator.Update(new TValue(now.AddMinutes(i), 100 + i * 2), isNew: true);
indicator.Update(new TValue(now.AddMinutes(i), 100 + (i * 2)), isNew: true);
}
Assert.True(indicator.IsHot);
@@ -546,7 +546,7 @@ public class TtmLrcTests
for (int i = 0; i < 15; i++)
{
times.Add(now.AddMinutes(i).Ticks);
values.Add(100 + i * 2);
values.Add(100 + (i * 2));
}
var source = new TSeries(times, values);
@@ -565,7 +565,7 @@ public class TtmLrcTests
for (int i = 0; i < 8; i++)
{
source.Add(new TValue(now.AddMinutes(i), 100 + i * 3), isNew: true);
source.Add(new TValue(now.AddMinutes(i), 100 + (i * 3)), isNew: true);
}
Assert.True(indicator.IsHot);
@@ -720,7 +720,7 @@ public class TtmLrcTests
for (int i = 0; i < 8; i++)
{
indicator.Update(new TValue(now.AddMinutes(i), 100 + i * 2), isNew: true);
indicator.Update(new TValue(now.AddMinutes(i), 100 + (i * 2)), isNew: true);
}
Assert.NotNull(lastPubValue);
@@ -74,8 +74,8 @@ public sealed class TtmLrcValidationTests : IDisposable
Assert.Equal(115.0 - expectedStdDev, ind.Lower1.Value, 1e-10);
// Verify ±2σ bands
Assert.Equal(115.0 + 2.0 * expectedStdDev, ind.Upper2.Value, 1e-10);
Assert.Equal(115.0 - 2.0 * expectedStdDev, ind.Lower2.Value, 1e-10);
Assert.Equal(115.0 + (2.0 * expectedStdDev), ind.Upper2.Value, 1e-10);
Assert.Equal(115.0 - (2.0 * expectedStdDev), ind.Lower2.Value, 1e-10);
_output.WriteLine("TtmLrc manual calculation validated");
}
@@ -89,7 +89,7 @@ public sealed class TtmLrcValidationTests : IDisposable
// Perfect linear trend: 100, 110, 120, 130, 140
for (int i = 0; i < 5; i++)
{
series.Add(new TValue(t0.AddMinutes(i), 100 + i * 10));
series.Add(new TValue(t0.AddMinutes(i), 100 + (i * 10)));
}
var ind = new TtmLrc(5);
@@ -362,7 +362,7 @@ public sealed class TtmLrcValidationTests : IDisposable
// Feed perfect linear data
for (int i = 0; i < 10; i++)
{
ind.Update(new TValue(t0.AddMinutes(i), 100 + i * 5));
ind.Update(new TValue(t0.AddMinutes(i), 100 + (i * 5)));
}
Assert.Equal(1.0, ind.RSquared, 1e-9);
@@ -481,7 +481,7 @@ public sealed class TtmLrcValidationTests : IDisposable
var t0 = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
uptrend.Add(new TValue(t0.AddMinutes(i), 100 + i * 2 + (i % 3))); // Noisy uptrend
uptrend.Add(new TValue(t0.AddMinutes(i), 100 + (i * 2) + (i % 3))); // Noisy uptrend
}
var indUp = new TtmLrc(10);
@@ -495,7 +495,7 @@ public sealed class TtmLrcValidationTests : IDisposable
var downtrend = new TSeries();
for (int i = 0; i < 20; i++)
{
downtrend.Add(new TValue(t0.AddMinutes(i), 200 - i * 2 + (i % 3))); // Noisy downtrend
downtrend.Add(new TValue(t0.AddMinutes(i), 200 - (i * 2) + (i % 3))); // Noisy downtrend
}
var indDown = new TtmLrc(10);
@@ -409,7 +409,7 @@ public sealed class UbandsValidationTests : IDisposable
_output.WriteLine($"Source variance: {sourceVar:F4}");
_output.WriteLine($"Middle (USF) variance: {middleVar:F4}");
_output.WriteLine($"Noise reduction: {(1 - middleVar / sourceVar) * 100:F1}%");
_output.WriteLine($"Noise reduction: {(1 - (middleVar / sourceVar)) * 100:F1}%");
Assert.True(middleVar < sourceVar, "Smoothed signal should have lower variance");
}
@@ -358,7 +358,7 @@ public class UchannelQuantowerTests
double width2 = indicator2.LinesSeries[4].GetValue(0);
// Width2 should be approximately 2x Width1
Assert.True(Math.Abs(width2 - 2 * width1) < 0.0001,
Assert.True(Math.Abs(width2 - (2 * width1)) < 0.0001,
$"Width2 ({width2}) should be ~2x Width1 ({width1})");
}
@@ -377,7 +377,7 @@ public class UchannelQuantowerTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double close = 100 + (i % 5) * 2;
double close = 100 + ((i % 5) * 2);
indicator1.HistoricalData.AddBar(now.AddMinutes(i), close, close + 3, close - 3, close, 1000);
indicator1.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
indicator2.HistoricalData.AddBar(now.AddMinutes(i), close, close + 3, close - 3, close, 1000);
@@ -148,7 +148,7 @@ public class VwapbandsIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 5; i++)
{
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 105 + i, 95 + i, 102 + i, 1000 + i * 100);
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 105 + i, 95 + i, 102 + i, 1000 + (i * 100));
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -120,7 +120,7 @@ public class VwapbandsTests
// Make multiple corrections
for (int i = 0; i < 10; i++)
{
var correctionBar = new TBar(DateTime.UtcNow, 150 + i, 160 + i, 140 + i, 155 + i, 2000 + i * 100);
var correctionBar = new TBar(DateTime.UtcNow, 150 + i, 160 + i, 140 + i, 155 + i, 2000 + (i * 100));
vwapbands.Update(correctionBar, isNew: false);
}
@@ -359,7 +359,7 @@ public class VwapbandsTests
vwapbands.Update(bar2);
// VWAP = (100*1000 + 110*2000) / (1000+2000) = 320000/3000 = 106.666...
double expectedVwap = (100.0 * 1000 + 110.0 * 2000) / (1000 + 2000);
double expectedVwap = ((100.0 * 1000) + (110.0 * 2000)) / (1000 + 2000);
Assert.Equal(expectedVwap, vwapbands.Vwap.Value, precision: 10);
}
@@ -600,7 +600,7 @@ public class VwapbandsTests
// VWAP should be closer to 100 due to higher volume
// VWAP = (100*10000 + 200*100) / (10000+100) = 1020000/10100 ≈ 100.99
double expectedVwap = (100.0 * 10000 + 200.0 * 100) / (10000 + 100);
double expectedVwap = ((100.0 * 10000) + (200.0 * 100)) / (10000 + 100);
Assert.Equal(expectedVwap, vwapbands.Vwap.Value, precision: 10);
Assert.True(vwapbands.Vwap.Value < 110, "VWAP should be heavily weighted toward 100");
}
@@ -273,7 +273,7 @@ public sealed class VwapbandsValidationTests : IDisposable
// VWAP should be closer to 100 (high volume price)
// VWAP = (100 × 10000 + 200 × 100) / (10000 + 100) = 1020000 / 10100 ≈ 100.99
double expectedVwap = (100.0 * 10000 + 200.0 * 100) / (10000 + 100);
double expectedVwap = ((100.0 * 10000) + (200.0 * 100)) / (10000 + 100);
Assert.Equal(expectedVwap, vwapbands.Vwap.Value, precision: 10);
Assert.True(vwapbands.Vwap.Value < 110, "VWAP should be heavily weighted toward 100");
@@ -434,7 +434,7 @@ public sealed class VwapbandsValidationTests : IDisposable
// Multiple zero-volume bars with different prices
for (int i = 0; i < 5; i++)
{
var zeroVolBar = new TBar(DateTime.UtcNow.AddMinutes(i + 1), 200 + i * 10, 200 + i * 10, 200 + i * 10, 200 + i * 10, 0);
var zeroVolBar = new TBar(DateTime.UtcNow.AddMinutes(i + 1), 200 + (i * 10), 200 + (i * 10), 200 + (i * 10), 200 + (i * 10), 0);
vwapbands.Update(zeroVolBar);
}
@@ -242,7 +242,7 @@ public class VwapsdIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 5; i++)
{
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 105 + i, 95 + i, 102 + i, 1000 + i * 100);
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 105 + i, 95 + i, 102 + i, 1000 + (i * 100));
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -344,7 +344,7 @@ public class VwapsdIndicatorTests
double width2 = indicator2.LinesSeries[3].GetValue(0);
// Width2 should be approximately 2x Width1
Assert.True(Math.Abs(width2 - 2 * width1) < 0.0001,
Assert.True(Math.Abs(width2 - (2 * width1)) < 0.0001,
$"Width2 ({width2}) should be ~2x Width1 ({width1})");
}
+3 -3
View File
@@ -136,7 +136,7 @@ public class VwapsdTests
// Make multiple corrections
for (int i = 0; i < 10; i++)
{
var correctionBar = new TBar(DateTime.UtcNow, 150 + i, 160 + i, 140 + i, 155 + i, 2000 + i * 100);
var correctionBar = new TBar(DateTime.UtcNow, 150 + i, 160 + i, 140 + i, 155 + i, 2000 + (i * 100));
vwapsd.Update(correctionBar, isNew: false);
}
@@ -371,7 +371,7 @@ public class VwapsdTests
vwapsd.Update(bar2);
// VWAP = (100*1000 + 110*2000) / (1000+2000) = 320000/3000 = 106.666...
double expectedVwap = (100.0 * 1000 + 110.0 * 2000) / (1000 + 2000);
double expectedVwap = ((100.0 * 1000) + (110.0 * 2000)) / (1000 + 2000);
Assert.Equal(expectedVwap, vwapsd.Vwap.Value, precision: 10);
}
@@ -634,7 +634,7 @@ public class VwapsdTests
// VWAP should be closer to 100 due to higher volume
// VWAP = (100*10000 + 200*100) / (10000+100) = 1020000/10100 ≈ 100.99
double expectedVwap = (100.0 * 10000 + 200.0 * 100) / (10000 + 100);
double expectedVwap = ((100.0 * 10000) + (200.0 * 100)) / (10000 + 100);
Assert.Equal(expectedVwap, vwapsd.Vwap.Value, precision: 10);
Assert.True(vwapsd.Vwap.Value < 110, "VWAP should be heavily weighted toward 100");
}
@@ -305,7 +305,7 @@ public sealed class VwapsdValidationTests : IDisposable
// VWAP should be closer to 100 (high volume price)
// VWAP = (100 × 10000 + 200 × 100) / (10000 + 100) = 1020000 / 10100 ≈ 100.99
double expectedVwap = (100.0 * 10000 + 200.0 * 100) / (10000 + 100);
double expectedVwap = ((100.0 * 10000) + (200.0 * 100)) / (10000 + 100);
Assert.Equal(expectedVwap, vwapsd.Vwap.Value, precision: 10);
Assert.True(vwapsd.Vwap.Value < 110, "VWAP should be heavily weighted toward 100");
@@ -466,7 +466,7 @@ public sealed class VwapsdValidationTests : IDisposable
// Multiple zero-volume bars with different prices
for (int i = 0; i < 5; i++)
{
var zeroVolBar = new TBar(DateTime.UtcNow.AddMinutes(i + 1), 200 + i * 10, 200 + i * 10, 200 + i * 10, 200 + i * 10, 0);
var zeroVolBar = new TBar(DateTime.UtcNow.AddMinutes(i + 1), 200 + (i * 10), 200 + (i * 10), 200 + (i * 10), 200 + (i * 10), 0);
vwapsd.Update(zeroVolBar);
}