[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
@@ -374,7 +374,7 @@ public class AtrnTests
var batch = Atrn.Batch(bars, DefaultPeriod);
Assert.NotNull(indicator);
Assert.True(indicator.WarmupPeriod >= DefaultPeriod + 10 * DefaultPeriod);
Assert.True(indicator.WarmupPeriod >= DefaultPeriod + (10 * DefaultPeriod));
Assert.Equal(batch.Count, results.Count);
for (int i = 0; i < results.Count; i++)
@@ -166,7 +166,7 @@ public sealed class AtrnValidationTests : IDisposable
for (int i = 0; i < lookbackWindow + 100; i++)
{
constantBars.Add(new TBar(
startTime + i * TimeSpan.FromMinutes(1).Ticks,
startTime + (i * TimeSpan.FromMinutes(1).Ticks),
price, // Open
price + 5.0, // High (constant +5)
price - 5.0, // Low (constant -5)
@@ -215,7 +215,7 @@ public sealed class AtrnValidationTests : IDisposable
double range = 1.0 + (i * 0.1);
bars.Add(new TBar(
startTime + i * TimeSpan.FromMinutes(1).Ticks,
startTime + (i * TimeSpan.FromMinutes(1).Ticks),
price,
price + range,
price - range,
@@ -261,7 +261,7 @@ public sealed class AtrnValidationTests : IDisposable
double range = Math.Max(0.1, 10.0 - (i * 0.05));
bars.Add(new TBar(
startTime + i * TimeSpan.FromMinutes(1).Ticks,
startTime + (i * TimeSpan.FromMinutes(1).Ticks),
price,
price + range,
price - range,
@@ -59,7 +59,7 @@ public class BbwIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
double basePrice = 100 + i * 2 + (i % 2 == 0 ? 5 : -5); // Add some volatility
double basePrice = 100 + (i * 2) + (i % 2 == 0 ? 5 : -5); // Add some volatility
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 5, basePrice - 5, basePrice + 2, 1000);
// Process update for each bar to simulate history loading
+2 -2
View File
@@ -379,7 +379,7 @@ public class BbwTests
for (int i = 0; i < 10; i++)
{
bbw.Update(new TValue(DateTime.UtcNow, 100 + i * 0.1));
bbw.Update(new TValue(DateTime.UtcNow, 100 + (i * 0.1)));
}
double lowVolatilityBbw = bbw.Last.Value;
@@ -387,7 +387,7 @@ public class BbwTests
for (int i = 0; i < 10; i++)
{
bbw.Update(new TValue(DateTime.UtcNow, 100 + i * 10));
bbw.Update(new TValue(DateTime.UtcNow, 100 + (i * 10)));
}
double highVolatilityBbw = bbw.Last.Value;
@@ -61,7 +61,7 @@ public class BbwnIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double basePrice = 100 + i * 2 + (i % 2 == 0 ? 5 : -5); // Add some volatility
double basePrice = 100 + (i * 2) + (i % 2 == 0 ? 5 : -5); // Add some volatility
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 5, basePrice - 5, basePrice + 2, 1000);
// Process update for each bar to simulate history loading
@@ -61,7 +61,7 @@ public class BbwpIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double basePrice = 100 + i * 2 + (i % 2 == 0 ? 5 : -5); // Add some volatility
double basePrice = 100 + (i * 2) + (i % 2 == 0 ? 5 : -5); // Add some volatility
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 5, basePrice - 5, basePrice + 2, 1000);
// Process update for each bar to simulate history loading
@@ -141,7 +141,7 @@ public class BbwpValidationTests
// Feed low volatility data first
for (int i = 0; i < 25; i++)
{
bbwp.Update(new TValue(DateTime.UtcNow.Ticks + i, 100.0 + (i % 2) * 0.1));
bbwp.Update(new TValue(DateTime.UtcNow.Ticks + i, 100.0 + ((i % 2) * 0.1)));
}
// Then introduce a high volatility spike
@@ -59,7 +59,7 @@ public class CcvIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double basePrice = 100 + i * 2 + (i % 2 == 0 ? 5 : -5); // Add some volatility
double basePrice = 100 + (i * 2) + (i % 2 == 0 ? 5 : -5); // Add some volatility
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 5, basePrice - 5, basePrice + 2, 1000);
// Process update for each bar to simulate history loading
+1 -1
View File
@@ -341,7 +341,7 @@ public class CcvTests
// Stable prices (small changes)
for (int i = 0; i < 20; i++)
{
ccvStable.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + i * 0.01));
ccvStable.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + (i * 0.01)));
}
// Volatile prices (alternating)
@@ -160,7 +160,7 @@ public class CcvValidationTests
double priceLow = 100.0;
for (int i = 0; i < 20; i++)
{
priceLow *= (1 + 0.001 * (i % 2 == 0 ? 1 : -1)); // ±0.1%
priceLow *= (1 + (0.001 * (i % 2 == 0 ? 1 : -1))); // ±0.1%
ccvLow.Update(new TValue(DateTime.UtcNow.AddMinutes(i), priceLow));
}
@@ -168,7 +168,7 @@ public class CcvValidationTests
double priceHigh = 100.0;
for (int i = 0; i < 20; i++)
{
priceHigh *= (1 + 0.05 * (i % 2 == 0 ? 1 : -1)); // ±5%
priceHigh *= (1 + (0.05 * (i % 2 == 0 ? 1 : -1))); // ±5%
ccvHigh.Update(new TValue(DateTime.UtcNow.AddMinutes(i), priceHigh));
}
@@ -61,7 +61,7 @@ public class CvIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double basePrice = 100 + i * 2 + (i % 2 == 0 ? 5 : -5); // Add some volatility
double basePrice = 100 + (i * 2) + (i % 2 == 0 ? 5 : -5); // Add some volatility
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 5, basePrice - 5, basePrice + 2, 1000);
// Process update for each bar to simulate history loading
+4 -4
View File
@@ -354,7 +354,7 @@ public class CvTests
// Stable prices (small changes)
for (int i = 0; i < 20; i++)
{
cvStable.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + i * 0.01));
cvStable.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + (i * 0.01)));
}
// Volatile prices (alternating)
@@ -399,7 +399,7 @@ public class CvTests
// Low volatility period
for (int i = 0; i < 15; i++)
{
cv.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + i * 0.1));
cv.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + (i * 0.1)));
}
double lowVolResult = cv.Last.Value;
@@ -420,7 +420,7 @@ public class CvTests
// Establish long-run variance
for (int i = 0; i < 15; i++)
{
cv.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + i * 0.5));
cv.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + (i * 0.5)));
}
// Introduce shock
@@ -430,7 +430,7 @@ public class CvTests
// Let it decay
for (int i = 16; i < 50; i++)
{
cv.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + (i - 16) * 0.1));
cv.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + ((i - 16) * 0.1)));
}
double decayedVol = cv.Last.Value;
@@ -77,7 +77,7 @@ public class CvValidationTests
// Warmup with stable prices
for (int i = 0; i < 25; i++)
{
double price = 100.0 * (1 + 0.001 * (i % 2 == 0 ? 1 : -1));
double price = 100.0 * (1 + (0.001 * (i % 2 == 0 ? 1 : -1)));
cv.Update(new TValue(DateTime.UtcNow.AddMinutes(i), price));
}
@@ -95,7 +95,7 @@ public class CvValidationTests
double lastVol = shockVol;
for (int i = 0; i < 50; i++)
{
double price = 120.0 * (1 + 0.0001 * (i % 2 == 0 ? 1 : -1)); // Very stable prices
double price = 120.0 * (1 + (0.0001 * (i % 2 == 0 ? 1 : -1))); // Very stable prices
cv.Update(new TValue(DateTime.UtcNow.AddMinutes(31 + i), price));
lastVol = cv.Last.Value;
}
@@ -117,7 +117,7 @@ public class CvValidationTests
// Warmup
for (int i = 0; i < 25; i++)
{
cv.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100.0 + i * 0.1));
cv.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100.0 + (i * 0.1)));
}
// Series of large moves
@@ -172,7 +172,7 @@ public class CvValidationTests
for (int i = period; i < logReturns.Length; i++)
{
double prevReturn = logReturns[i - 1];
variance = omega + alpha * prevReturn * prevReturn + beta * variance;
variance = omega + (alpha * prevReturn * prevReturn) + (beta * variance);
}
// Expected annualized volatility
@@ -331,7 +331,7 @@ public class CvValidationTests
// Warmup with stable prices then shock
for (int i = 0; i < 25; i++)
{
double price = 100.0 + i * 0.1;
double price = 100.0 + (i * 0.1);
cvLowBeta.Update(new TValue(DateTime.UtcNow.AddMinutes(i), price));
cvHighBeta.Update(new TValue(DateTime.UtcNow.AddMinutes(i), price));
}
@@ -346,7 +346,7 @@ public class CvValidationTests
// Continue with stable prices - track decay
for (int i = 0; i < 20; i++)
{
double price = 120.0 + i * 0.05;
double price = 120.0 + (i * 0.05);
cvLowBeta.Update(new TValue(DateTime.UtcNow.AddMinutes(31 + i), price));
cvHighBeta.Update(new TValue(DateTime.UtcNow.AddMinutes(31 + i), price));
}
@@ -209,7 +209,7 @@ public class CviIndicatorTests
for (int i = 20; i < 35; i++)
{
double basePrice = 100;
double range = 1 + (i - 20) * 0.5; // Gradually increasing range
double range = 1 + ((i - 20) * 0.5); // Gradually increasing range
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + range, basePrice - range, basePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -240,7 +240,7 @@ public class CviIndicatorTests
for (int i = 20; i < 35; i++)
{
double basePrice = 100;
double range = Math.Max(1, 10 - (i - 20) * 0.5); // Gradually decreasing range
double range = Math.Max(1, 10 - ((i - 20) * 0.5)); // Gradually decreasing range
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + range, basePrice - range, basePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
+5 -5
View File
@@ -384,10 +384,10 @@ public class CviTests
// Start with small range, expand over time
for (int i = 0; i < 20; i++)
{
double range = 5 + i * 0.5; // Expanding range
double range = 5 + (i * 0.5); // Expanding range
var bar = new TBar(
DateTime.UtcNow.AddMinutes(i).Ticks,
100.0, 100.0 + range / 2, 100.0 - range / 2, 100.0, 1000.0
100.0, 100.0 + (range / 2), 100.0 - (range / 2), 100.0, 1000.0
);
cvi.Update(bar);
}
@@ -404,14 +404,14 @@ public class CviTests
// Start with large range, contract over time
for (int i = 0; i < 20; i++)
{
double range = 20 - i * 0.5; // Contracting range
double range = 20 - (i * 0.5); // Contracting range
if (range < 1)
{
range = 1;
}
var bar = new TBar(
DateTime.UtcNow.AddMinutes(i).Ticks,
100.0, 100.0 + range / 2, 100.0 - range / 2, 100.0, 1000.0
100.0, 100.0 + (range / 2), 100.0 - (range / 2), 100.0, 1000.0
);
cvi.Update(bar);
}
@@ -451,7 +451,7 @@ public class CviTests
// Feed pre-calculated range values via TValue
for (int i = 0; i < 20; i++)
{
var result = cvi.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 5.0 + i * 0.1));
var result = cvi.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 5.0 + (i * 0.1)));
Assert.True(double.IsFinite(result.Value));
}
@@ -87,10 +87,10 @@ public class CviValidationTests
// Gradually expanding range
for (int i = 0; i < 20; i++)
{
double range = 5 + i * 0.5; // Expanding from 5 to 14.5
double range = 5 + (i * 0.5); // Expanding from 5 to 14.5
var bar = new TBar(
DateTime.UtcNow.AddMinutes(i).Ticks,
100.0, 100.0 + range / 2, 100.0 - range / 2, 100.0, 1000.0
100.0, 100.0 + (range / 2), 100.0 - (range / 2), 100.0, 1000.0
);
cvi.Update(bar);
}
@@ -110,14 +110,14 @@ public class CviValidationTests
// Gradually contracting range
for (int i = 0; i < 20; i++)
{
double range = 20 - i * 0.5; // Contracting from 20 to 10.5
double range = 20 - (i * 0.5); // Contracting from 20 to 10.5
if (range < 1)
{
range = 1;
}
var bar = new TBar(
DateTime.UtcNow.AddMinutes(i).Ticks,
100.0, 100.0 + range / 2, 100.0 - range / 2, 100.0, 1000.0
100.0, 100.0 + (range / 2), 100.0 - (range / 2), 100.0, 1000.0
);
cvi.Update(bar);
}
@@ -144,7 +144,7 @@ public class CviValidationTests
emas[0] = ranges[0];
for (int i = 1; i < ranges.Length; i++)
{
emas[i] = (ranges[i] - emas[i - 1]) * alpha + emas[i - 1];
emas[i] = ((ranges[i] - emas[i - 1]) * alpha) + emas[i - 1];
}
// Calculate ROC for last point
@@ -407,7 +407,7 @@ public class CviValidationTests
double range = (i % 2 == 0) ? 5.0 : 20.0;
var bar = new TBar(
DateTime.UtcNow.AddMinutes(i).Ticks,
100.0, 100.0 + range / 2, 100.0 - range / 2, 100.0, 1000.0
100.0, 100.0 + (range / 2), 100.0 - (range / 2), 100.0, 1000.0
);
cvi.Update(bar);
}
+1 -1
View File
@@ -351,7 +351,7 @@ public class EwmaTests
// Stable prices (small changes)
for (int i = 0; i < 20; i++)
{
ewmaStable.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + i * 0.01));
ewmaStable.Update(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + (i * 0.01)));
}
// Volatile prices (alternating)
@@ -295,7 +295,7 @@ public class EwmaValidationTests
var ewma = new Ewma(5, false);
for (int i = 0; i < 20; i++)
{
double price = 0.0001 + (i % 2) * 0.00001;
double price = 0.0001 + ((i % 2) * 0.00001);
var result = ewma.Update(new TValue(DateTime.UtcNow.AddMinutes(i), price));
Assert.True(double.IsFinite(result.Value));
Assert.True(result.Value >= 0);
@@ -308,7 +308,7 @@ public class EwmaValidationTests
var ewma = new Ewma(5, false);
for (int i = 0; i < 20; i++)
{
double price = 1e10 + (i % 2) * 1e9;
double price = 1e10 + ((i % 2) * 1e9);
var result = ewma.Update(new TValue(DateTime.UtcNow.AddMinutes(i), price));
Assert.True(double.IsFinite(result.Value));
Assert.True(result.Value >= 0);
@@ -398,7 +398,7 @@ public class EwmaValidationTests
// Multiple corrections
for (int j = 0; j < 10; j++)
{
double correctedPrice = 100 + j * 5;
double correctedPrice = 100 + (j * 5);
var result = ewma.Update(new TValue(DateTime.UtcNow, correctedPrice), isNew: false);
Assert.True(double.IsFinite(result.Value));
Assert.True(result.Value >= 0);
@@ -227,7 +227,7 @@ public class GkvIndicatorTests
// Same data for both
for (int i = 0; i < 30; i++)
{
double basePrice = 100 + i * 0.5;
double basePrice = 100 + (i * 0.5);
indicatorRaw.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 3, basePrice - 3, basePrice + 1, 1000);
indicatorRaw.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -25,7 +25,7 @@ public class GkvValidationTests
[Fact]
public void Gkv_GarmanKlassCoefficient_IsCorrect()
{
double expectedCoeff = 2.0 * Math.Log(2) - 1.0;
double expectedCoeff = (2.0 * Math.Log(2)) - 1.0;
Assert.Equal(0.38629436111989, expectedCoeff, 10);
}
@@ -38,7 +38,7 @@ public class GkvValidationTests
[InlineData(10, 0.9)] // 1 - 1/10 = 9/10
public void Gkv_RmaDecay_IsCorrect(int period, double expectedDecay)
{
double decay = 1.0 - 1.0 / period;
double decay = 1.0 - (1.0 / period);
Assert.Equal(expectedDecay, decay, 10);
}
@@ -59,7 +59,7 @@ public class GkvValidationTests
double lnC = Math.Log(close);
double term1 = 0.5 * Math.Pow(lnH - lnL, 2);
double coeff = 2.0 * Math.Log(2) - 1.0;
double coeff = (2.0 * Math.Log(2)) - 1.0;
double term2 = coeff * Math.Pow(lnC - lnO, 2);
double expectedGk = term1 - term2;
@@ -87,7 +87,7 @@ public class GkvValidationTests
double lnC = Math.Log(price);
double term1 = 0.5 * Math.Pow(lnH - lnL, 2); // 0
double coeff = 2.0 * Math.Log(2) - 1.0;
double coeff = (2.0 * Math.Log(2)) - 1.0;
double term2 = coeff * Math.Pow(lnC - lnO, 2); // 0
double gk = term1 - term2;
@@ -104,7 +104,7 @@ public class GkvValidationTests
[InlineData(14, 100)] // Very late - correction should be minimal
public void Gkv_BiasCorrection_WorksCorrectly(int period, int count)
{
double decay = 1.0 - 1.0 / period;
double decay = 1.0 - (1.0 / period);
double e = Math.Pow(decay, count);
double correctionFactor = 1.0 / (1.0 - e);
@@ -610,7 +610,7 @@ public class GkvValidationTests
double lnC = Math.Log(close);
double term1 = 0.5 * Math.Pow(lnH - lnL, 2);
double coeff = 2.0 * Math.Log(2) - 1.0;
double coeff = (2.0 * Math.Log(2)) - 1.0;
double term2 = coeff * Math.Pow(lnC - lnO, 2);
return term1 - term2;
@@ -227,7 +227,7 @@ public class HlvIndicatorTests
// Same data for both
for (int i = 0; i < 30; i++)
{
double basePrice = 100 + i * 0.5;
double basePrice = 100 + (i * 0.5);
indicatorRaw.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 3, basePrice - 3, basePrice + 1, 1000);
indicatorRaw.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -37,7 +37,7 @@ public class HlvValidationTests
[InlineData(10, 0.9)] // 1 - 1/10 = 9/10
public void Hlv_RmaDecay_IsCorrect(int period, double expectedDecay)
{
double decay = 1.0 - 1.0 / period;
double decay = 1.0 - (1.0 / period);
Assert.Equal(expectedDecay, decay, 10);
}
@@ -92,7 +92,7 @@ public class HlvValidationTests
[InlineData(14, 100)] // Very late - correction should be minimal
public void Hlv_BiasCorrection_WorksCorrectly(int period, int count)
{
double decay = 1.0 - 1.0 / period;
double decay = 1.0 - (1.0 / period);
double e = Math.Pow(decay, count);
double correctionFactor = 1.0 / (1.0 - e);
@@ -58,7 +58,7 @@ public class HvIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + i * 0.5 + Math.Sin(i * 0.3) * 2; // Trending with variation
double closePrice = 100 + (i * 0.5) + (Math.Sin(i * 0.3) * 2); // Trending with variation
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
// Process update for each bar to simulate history loading
@@ -81,7 +81,7 @@ public class HvIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + i * 0.3;
double closePrice = 100 + (i * 0.3);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
}
@@ -107,7 +107,7 @@ public class HvIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 50; i++)
{
double closePrice = 100 + i * 0.2 + Math.Sin(i * 0.5) * 3;
double closePrice = 100 + (i * 0.2) + (Math.Sin(i * 0.5) * 3);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -191,7 +191,7 @@ public class HvIndicatorTests
// Indicator 1: low volatility (small price changes)
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + i * 0.01; // Small consistent changes
double closePrice = 100 + (i * 0.01); // Small consistent changes
indicator1.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 0.5, closePrice + 0.5, closePrice - 0.5, closePrice, 1000);
indicator1.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -199,7 +199,7 @@ public class HvIndicatorTests
// Indicator 2: high volatility (large price swings)
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + Math.Sin(i * 0.5) * 10; // Large swings
double closePrice = 100 + (Math.Sin(i * 0.5) * 10); // Large swings
indicator2.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 2, closePrice + 2, closePrice - 2, closePrice, 1000);
indicator2.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -225,7 +225,7 @@ public class HvIndicatorTests
// Same data for both - trending with variation
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + i * 0.5 + Math.Sin(i * 0.3) * 2;
double closePrice = 100 + (i * 0.5) + (Math.Sin(i * 0.3) * 2);
indicatorRaw.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
indicatorRaw.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -261,7 +261,7 @@ public class HvIndicatorTests
// Same close prices but different high/low
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + i * 0.5;
double closePrice = 100 + (i * 0.5);
// Indicator 1: narrow range
indicator1.HistoricalData.AddBar(now.AddMinutes(i), closePrice, closePrice + 1, closePrice - 1, closePrice, 1000);
indicator1.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -314,7 +314,7 @@ public class HvIndicatorTests
for (int i = 0; i < 30; i++)
{
double rate = (i % 2 == 0) ? 1.02 : 1.005;
double closePrice = 100 * Math.Pow(rate, i / 2 + 1) * (i % 2 == 0 ? 1.0 : rate);
double closePrice = 100 * Math.Pow(rate, (i / 2) + 1) * (i % 2 == 0 ? 1.0 : rate);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 1, closePrice - 1, closePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -481,7 +481,7 @@ public class HvValidationTests
// Multiple corrections on same price
for (int j = 0; j < 5; j++)
{
var tempPrice = new TValue(prices[19].Time, prices[19].Value * (1.0 + j * 0.01));
var tempPrice = new TValue(prices[19].Time, prices[19].Value * (1.0 + (j * 0.01)));
hv.Update(tempPrice, isNew: false);
}
@@ -57,7 +57,7 @@ public class JvoltyIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double basePrice = 100 + i * 2 + (i % 2 == 0 ? 5 : -5); // Add some volatility
double basePrice = 100 + (i * 2) + (i % 2 == 0 ? 5 : -5); // Add some volatility
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 5, basePrice - 5, basePrice + 2, 1000);
// Process update for each bar to simulate history loading
@@ -57,7 +57,7 @@ public class JvoltynIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double basePrice = 100 + i * 2 + (i % 2 == 0 ? 5 : -5); // Add some volatility
double basePrice = 100 + (i * 2) + (i % 2 == 0 ? 5 : -5); // Add some volatility
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 5, basePrice - 5, basePrice + 2, 1000);
// Process update for each bar to simulate history loading
@@ -186,7 +186,7 @@ public class JvoltynIndicatorTests
for (int i = 0; i < 100; i++)
{
// Create varying volatility patterns
double basePrice = 100 + (i % 10) * 5 + (i % 2 == 0 ? 20 : -15);
double basePrice = 100 + ((i % 10) * 5) + (i % 2 == 0 ? 20 : -15);
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 10, basePrice - 10, basePrice + 3, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -226,7 +226,7 @@ public class RsvIndicatorTests
// Same data for both
for (int i = 0; i < 30; i++)
{
double basePrice = 100 + i * 0.5;
double basePrice = 100 + (i * 0.5);
indicatorRaw.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 3, basePrice - 3, basePrice + 1, 1000);
indicatorRaw.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -313,7 +313,7 @@ public class RsvIndicatorTests
// Strong uptrend with consistent volatility
for (int i = 0; i < 30; i++)
{
double basePrice = 100 + i * 2; // Trending up
double basePrice = 100 + (i * 2); // Trending up
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 3, basePrice - 2, basePrice + 1, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -56,7 +56,7 @@ public class RsvValidationTests
double lnLO = Math.Log(price / price); // log(1) = 0
double lnLC = Math.Log(price / price); // log(1) = 0
double rsVariance = lnHO * lnHC + lnLO * lnLC; // 0
double rsVariance = (lnHO * lnHC) + (lnLO * lnLC); // 0
Assert.Equal(0.0, rsVariance, 15);
}
@@ -153,7 +153,7 @@ public class RsvValidationTests
// Strongly trending market (continuous up moves)
for (int i = 0; i < 30; i++)
{
double basePrice = 100 + i * 2; // Strong uptrend
double basePrice = 100 + (i * 2); // Strong uptrend
var bar = new TBar(
DateTime.UtcNow.AddMinutes(i).Ticks,
basePrice, basePrice + 3, basePrice - 2, basePrice + 2, 1000.0
@@ -698,7 +698,7 @@ public class RsvValidationTests
double lnLO = Math.Log(low / open);
double lnLC = Math.Log(low / close);
return lnHO * lnHC + lnLO * lnLC;
return (lnHO * lnHC) + (lnLO * lnLC);
}
private static double Variance(List<double> values)
@@ -57,7 +57,7 @@ public class RvIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + i * 0.5 + Math.Sin(i * 0.3) * 2;
double closePrice = 100 + (i * 0.5) + (Math.Sin(i * 0.3) * 2);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
var args = new UpdateArgs(UpdateReason.HistoricalBar);
@@ -78,7 +78,7 @@ public class RvIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + i * 0.3;
double closePrice = 100 + (i * 0.3);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
}
@@ -103,7 +103,7 @@ public class RvIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 50; i++)
{
double closePrice = 100 + i * 0.2 + Math.Sin(i * 0.5) * 3;
double closePrice = 100 + (i * 0.2) + (Math.Sin(i * 0.5) * 3);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -188,7 +188,7 @@ public class RvIndicatorTests
// Low volatility
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + i * 0.01;
double closePrice = 100 + (i * 0.01);
indicator1.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 0.5, closePrice + 0.5, closePrice - 0.5, closePrice, 1000);
indicator1.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -196,7 +196,7 @@ public class RvIndicatorTests
// High volatility
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + Math.Sin(i * 0.5) * 10;
double closePrice = 100 + (Math.Sin(i * 0.5) * 10);
indicator2.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 2, closePrice + 2, closePrice - 2, closePrice, 1000);
indicator2.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -221,7 +221,7 @@ public class RvIndicatorTests
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + i * 0.5 + Math.Sin(i * 0.3) * 2;
double closePrice = 100 + (i * 0.5) + (Math.Sin(i * 0.3) * 2);
indicatorRaw.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
indicatorRaw.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -254,7 +254,7 @@ public class RvIndicatorTests
for (int i = 0; i < 30; i++)
{
double closePrice = 100 + i * 0.5;
double closePrice = 100 + (i * 0.5);
// Narrow range
indicator1.HistoricalData.AddBar(now.AddMinutes(i), closePrice, closePrice + 1, closePrice - 1, closePrice, 1000);
indicator1.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -303,7 +303,7 @@ public class RvIndicatorTests
for (int i = 0; i < 30; i++)
{
double rate = (i % 2 == 0) ? 1.02 : 1.005;
double closePrice = 100 * Math.Pow(rate, i / 2 + 1) * (i % 2 == 0 ? 1.0 : rate);
double closePrice = 100 * Math.Pow(rate, (i / 2) + 1) * (i % 2 == 0 ? 1.0 : rate);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 1, closePrice - 1, closePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -326,7 +326,7 @@ public class RvIndicatorTests
for (int i = 0; i < 50; i++)
{
double closePrice = 100 + Math.Sin(i * 0.3) * 5;
double closePrice = 100 + (Math.Sin(i * 0.3) * 5);
indicator1.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 1, closePrice - 1, closePrice, 1000);
indicator1.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -426,7 +426,7 @@ public class RvValidationTests
for (int j = 0; j < 5; j++)
{
var tempPrice = new TValue(prices[19].Time, prices[19].Value * (1.0 + j * 0.01));
var tempPrice = new TValue(prices[19].Time, prices[19].Value * (1.0 + (j * 0.01)));
rv.Update(tempPrice, isNew: false);
}
@@ -58,7 +58,7 @@ public class RviIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 50; i++)
{
double closePrice = 100 + i * 0.5 + Math.Sin(i * 0.3) * 2;
double closePrice = 100 + (i * 0.5) + (Math.Sin(i * 0.3) * 2);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
var args = new UpdateArgs(UpdateReason.HistoricalBar);
@@ -79,7 +79,7 @@ public class RviIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 50; i++)
{
double closePrice = 100 + i * 0.3;
double closePrice = 100 + (i * 0.3);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
}
@@ -105,7 +105,7 @@ public class RviIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 60; i++)
{
double closePrice = 100 + i * 0.2 + Math.Sin(i * 0.5) * 3;
double closePrice = 100 + (i * 0.2) + (Math.Sin(i * 0.5) * 3);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -129,7 +129,7 @@ public class RviIndicatorTests
var now = DateTime.UtcNow;
for (int i = 0; i < 60; i++)
{
double closePrice = 100 + i * 0.2 + Math.Sin(i * 0.5) * 3;
double closePrice = 100 + (i * 0.2) + (Math.Sin(i * 0.5) * 3);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -198,7 +198,7 @@ public class RviIndicatorTests
// Strong uptrend: price consistently rising
for (int i = 0; i < 60; i++)
{
double closePrice = 100 + i * 1.5; // Strong consistent uptrend
double closePrice = 100 + (i * 1.5); // Strong consistent uptrend
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -220,7 +220,7 @@ public class RviIndicatorTests
// Strong downtrend: price consistently falling
for (int i = 0; i < 60; i++)
{
double closePrice = 200 - i * 1.5; // Strong consistent downtrend
double closePrice = 200 - (i * 1.5); // Strong consistent downtrend
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 1, closePrice + 2, closePrice - 2, closePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -242,7 +242,7 @@ public class RviIndicatorTests
// Mixed data with various price movements
for (int i = 0; i < 100; i++)
{
double closePrice = 100 + Math.Sin(i * 0.2) * 20 + (i % 3 == 0 ? 5 : -3);
double closePrice = 100 + (Math.Sin(i * 0.2) * 20) + (i % 3 == 0 ? 5 : -3);
indicator.HistoricalData.AddBar(now.AddMinutes(i), closePrice - 2, closePrice + 3, closePrice - 3, closePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -272,7 +272,7 @@ public class RviIndicatorTests
// Same close prices, different open/high/low
for (int i = 0; i < 60; i++)
{
double closePrice = 100 + i * 0.5;
double closePrice = 100 + (i * 0.5);
// Indicator 1: narrow range
indicator1.HistoricalData.AddBar(now.AddMinutes(i), closePrice, closePrice + 1, closePrice - 1, closePrice, 1000);
indicator1.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -182,7 +182,7 @@ public class UiIndicatorTests
// Price rises then drops - creates drawdown
for (int i = 0; i < 10; i++)
{
double price = 100 + i * 2; // Rise to 118
double price = 100 + (i * 2); // Rise to 118
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 1, price - 1, price, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -190,7 +190,7 @@ public class UiIndicatorTests
// Now drop the price
for (int i = 10; i < 20; i++)
{
double price = 118 - (i - 10) * 3; // Drop from 118 to 88
double price = 118 - ((i - 10) * 3); // Drop from 118 to 88
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 1, price - 1, price, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -219,7 +219,7 @@ public class UiIndicatorTests
}
for (int i = 10; i < 20; i++)
{
double price = 109 - (i - 10) * 0.5; // Small drop
double price = 109 - ((i - 10) * 0.5); // Small drop
indicator1.HistoricalData.AddBar(now.AddMinutes(i), price, price + 0.5, price - 0.5, price, 1000);
indicator1.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -233,7 +233,7 @@ public class UiIndicatorTests
}
for (int i = 10; i < 20; i++)
{
double price = 109 - (i - 10) * 2; // Large drop
double price = 109 - ((i - 10) * 2); // Large drop
indicator2.HistoricalData.AddBar(now.AddMinutes(i), price, price + 0.5, price - 0.5, price, 1000);
indicator2.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -311,7 +311,7 @@ public class UiIndicatorTests
// Drawdown - price drops significantly
for (int i = 10; i < 15; i++)
{
double price = 109 - (i - 10) * 4; // Drop from 109 to 89
double price = 109 - ((i - 10) * 4); // Drop from 109 to 89
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 1, price - 1, price, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -322,7 +322,7 @@ public class UiIndicatorTests
// Need at least 10 more bars of rising prices to fully replace the drawdown window
for (int i = 15; i < 30; i++)
{
double price = 89 + (i - 15) * 3; // Rise from 89 to 134 (well past old high of 109)
double price = 89 + ((i - 15) * 3); // Rise from 89 to 134 (well past old high of 109)
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 1, price - 1, price, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
+1 -1
View File
@@ -512,7 +512,7 @@ public class UiTests
for (int i = 0; i < dataLen; i++)
{
source[i] = 100 + Math.Sin(i * 0.1) * 10;
source[i] = 100 + (Math.Sin(i * 0.1) * 10);
}
// Should not throw - uses ArrayPool for large period
@@ -309,7 +309,7 @@ public class UiValidationTests
for (int i = 0; i < 10; i++)
{
double price = 100.0 + Math.Sin(i * 0.1) * 0.001; // Tiny movements
double price = 100.0 + (Math.Sin(i * 0.1) * 0.001); // Tiny movements
var result = ui.Update(new TValue(time.AddSeconds(i), price));
Assert.True(double.IsFinite(result.Value));
@@ -387,7 +387,7 @@ public class UiValidationTests
// Multiple corrections on same bar
for (int j = 0; j < 5; j++)
{
ui.Update(new TValue(time.AddSeconds(4), 100 + j * 2), isNew: false);
ui.Update(new TValue(time.AddSeconds(4), 100 + (j * 2)), isNew: false);
}
// Final correction back to original
@@ -58,7 +58,7 @@ public class VovIndicatorTests
for (int i = 0; i < 50; i++)
{
// Create price movement that generates volatility
double basePrice = 100 + Math.Sin(i * 0.3) * (5 + i * 0.1);
double basePrice = 100 + (Math.Sin(i * 0.3) * (5 + (i * 0.1)));
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 2, basePrice - 2, basePrice, 1000);
// Process update for each bar to simulate history loading
@@ -108,7 +108,7 @@ public class VovIndicatorTests
for (int i = 0; i < 60; i++)
{
// Create price movement with varying amplitude
double basePrice = 100 + Math.Sin(i * 0.2) * 5;
double basePrice = 100 + (Math.Sin(i * 0.2) * 5);
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 2, basePrice - 2, basePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -197,7 +197,7 @@ public class VovIndicatorTests
// Low volatility period
for (int i = 0; i < 15; i++)
{
double price = 100 + (i % 2) * 0.5; // Small oscillations
double price = 100 + ((i % 2) * 0.5); // Small oscillations
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 0.5, price - 0.5, price, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -205,7 +205,7 @@ public class VovIndicatorTests
// High volatility period
for (int i = 15; i < 30; i++)
{
double price = 100 + (i % 2) * 10; // Large oscillations
double price = 100 + ((i % 2) * 10); // Large oscillations
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 5, price - 5, price, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -227,7 +227,7 @@ public class VovIndicatorTests
// Price with varying close but constant OHLC range
for (int i = 0; i < 20; i++)
{
double close = 100 + Math.Sin(i * 0.5) * 5; // Varying close
double close = 100 + (Math.Sin(i * 0.5) * 5); // Varying close
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100, 110, 90, close, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -252,7 +252,7 @@ public class VovIndicatorTests
for (int i = 0; i < 60; i++)
{
double price = 100 + Math.Sin(i * 0.3) * 5;
double price = 100 + (Math.Sin(i * 0.3) * 5);
indicator1.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price, 1000);
indicator2.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price, 1000);
indicator1.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -303,7 +303,7 @@ public class VovIndicatorTests
// Stable volatility regime
for (int i = 0; i < 20; i++)
{
double price = 100 + Math.Sin(i * 0.5) * 2;
double price = 100 + (Math.Sin(i * 0.5) * 2);
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 1, price - 1, price, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -313,8 +313,8 @@ public class VovIndicatorTests
// Transition to variable volatility
for (int i = 20; i < 40; i++)
{
double amplitude = 2 + (i - 20) * 0.5; // Increasing amplitude
double price = 100 + Math.Sin(i * 0.5) * amplitude;
double amplitude = 2 + ((i - 20) * 0.5); // Increasing amplitude
double price = 100 + (Math.Sin(i * 0.5) * amplitude);
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + amplitude, price - amplitude, price, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
+3 -3
View File
@@ -132,7 +132,7 @@ public class VovTests
// First phase: low volatility
for (int i = 0; i < 20; i++)
{
vov.Update(new TValue(DateTime.UtcNow, 100.0 + (i % 2) * 0.1));
vov.Update(new TValue(DateTime.UtcNow, 100.0 + ((i % 2) * 0.1)));
}
double lowVolVov = vov.Last.Value;
@@ -145,12 +145,12 @@ public class VovTests
// High volatility period
for (int j = 0; j < 5; j++)
{
vov.Update(new TValue(DateTime.UtcNow, 100.0 + (j % 2) * 10.0));
vov.Update(new TValue(DateTime.UtcNow, 100.0 + ((j % 2) * 10.0)));
}
// Low volatility period
for (int j = 0; j < 5; j++)
{
vov.Update(new TValue(DateTime.UtcNow, 100.0 + (j % 2) * 0.1));
vov.Update(new TValue(DateTime.UtcNow, 100.0 + ((j % 2) * 0.1)));
}
}
double highVolVov = vov.Last.Value;
@@ -127,14 +127,14 @@ public class VovValidationTests
// Low volatility period
for (int i = 0; i < 10; i++)
{
double price = 100 + Math.Sin(i * 0.3) * 0.5; // Small oscillations
double price = 100 + (Math.Sin(i * 0.3) * 0.5); // Small oscillations
vov.Update(new TValue(time.AddSeconds(i), price));
}
// High volatility period
for (int i = 10; i < 20; i++)
{
double price = 100 + Math.Sin(i * 0.3) * 10; // Large oscillations
double price = 100 + (Math.Sin(i * 0.3) * 10); // Large oscillations
vov.Update(new TValue(time.AddSeconds(i), price));
}
@@ -299,7 +299,7 @@ public class VovValidationTests
// Multiple corrections on same bar
for (int j = 0; j < 5; j++)
{
vov.Update(new TValue(time.AddSeconds(9), 100 + j * 5), isNew: false);
vov.Update(new TValue(time.AddSeconds(9), 100 + (j * 5)), isNew: false);
}
// Final correction back to original
@@ -535,7 +535,7 @@ public class VovValidationTests
// Stable volatility regime
for (int i = 0; i < 20; i++)
{
double price = 100 + Math.Sin(i * 0.5) * 2; // Consistent amplitude
double price = 100 + (Math.Sin(i * 0.5) * 2); // Consistent amplitude
vov.Update(new TValue(time.AddSeconds(i), price));
}
double stableVov = vov.Last.Value;
@@ -543,7 +543,7 @@ public class VovValidationTests
// Transition to higher volatility
for (int i = 20; i < 35; i++)
{
double price = 100 + Math.Sin(i * 0.5) * (2 + (i - 20) * 0.5); // Increasing amplitude
double price = 100 + (Math.Sin(i * 0.5) * (2 + ((i - 20) * 0.5))); // Increasing amplitude
vov.Update(new TValue(time.AddSeconds(i), price));
}
double transitionVov = vov.Last.Value;
@@ -56,7 +56,7 @@ public class VrIndicatorTests
for (int i = 0; i < 50; i++)
{
// Create price movement that generates volatility
double basePrice = 100 + Math.Sin(i * 0.3) * (5 + i * 0.1);
double basePrice = 100 + (Math.Sin(i * 0.3) * (5 + (i * 0.1)));
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 2, basePrice - 2, basePrice, 1000);
// Process update for each bar to simulate history loading
@@ -106,7 +106,7 @@ public class VrIndicatorTests
for (int i = 0; i < 60; i++)
{
// Create price movement with varying amplitude
double basePrice = 100 + Math.Sin(i * 0.2) * 5;
double basePrice = 100 + (Math.Sin(i * 0.2) * 5);
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 2, basePrice - 2, basePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -205,7 +205,7 @@ public class VrIndicatorTests
// Price with varying HLC
for (int i = 0; i < 20; i++)
{
double close = 100 + Math.Sin(i * 0.3) * 3;
double close = 100 + (Math.Sin(i * 0.3) * 3);
double high = close + 2 + Math.Abs(Math.Sin(i * 0.5));
double low = close - 2 - Math.Abs(Math.Cos(i * 0.5));
indicator.HistoricalData.AddBar(now.AddMinutes(i), close, high, low, close, 1000);
@@ -261,7 +261,7 @@ public class VrIndicatorTests
for (int i = 0; i < 60; i++)
{
double price = 100 + Math.Sin(i * 0.3) * 5;
double price = 100 + (Math.Sin(i * 0.3) * 5);
indicator1.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price, 1000);
indicator2.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price, 1000);
indicator1.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -365,8 +365,8 @@ public class VrIndicatorTests
// Normal market with consistent volatility
for (int i = 0; i < 100; i++)
{
double price = 100 + Math.Sin(i * 0.1) * 2;
double range = 2 + Math.Sin(i * 0.2) * 0.5; // Consistent range
double price = 100 + (Math.Sin(i * 0.1) * 2);
double range = 2 + (Math.Sin(i * 0.2) * 0.5); // Consistent range
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + range, price - range, price, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
+2 -2
View File
@@ -614,8 +614,8 @@ public class VrTests
// Build up history with varying volatility
for (int i = 0; i < 50; i++)
{
double range = 2.0 + (i % 5) * 0.5; // Varying range
vr.Update(new TBar(DateTime.UtcNow, 100, 100 + range, 100 - range, 100 + range / 2, 1000));
double range = 2.0 + ((i % 5) * 0.5); // Varying range
vr.Update(new TBar(DateTime.UtcNow, 100, 100 + range, 100 - range, 100 + (range / 2), 1000));
}
// VR should oscillate around 1.0 over time
@@ -374,7 +374,7 @@ public class VrValidationTests
// Low volatility consolidation
for (int i = 0; i < 50; i++)
{
vr.Update(new TBar(DateTime.UtcNow, 100, 101, 99, 100 + (i % 2) * 0.5, 1000));
vr.Update(new TBar(DateTime.UtcNow, 100, 101, 99, 100 + ((i % 2) * 0.5), 1000));
}
double consolidationVr = vr.Last.Value;
@@ -407,7 +407,7 @@ public class VrValidationTests
// Gradually increase volatility
for (int i = 0; i < 20; i++)
{
double range = 1 + i * 0.5;
double range = 1 + (i * 0.5);
var result = vr.Update(new TBar(DateTime.UtcNow, 100, 100 + range, 100 - range, 100, 1000));
vrValues.Add(result.Value);
}
@@ -56,7 +56,7 @@ public class YzvIndicatorTests
for (int i = 0; i < 50; i++)
{
// Create price movement that generates volatility
double basePrice = 100 + Math.Sin(i * 0.3) * (5 + i * 0.1);
double basePrice = 100 + (Math.Sin(i * 0.3) * (5 + (i * 0.1)));
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 2, basePrice - 2, basePrice, 1000);
// Process update for each bar to simulate history loading
@@ -106,7 +106,7 @@ public class YzvIndicatorTests
for (int i = 0; i < 60; i++)
{
// Create price movement with varying amplitude
double basePrice = 100 + Math.Sin(i * 0.2) * 5;
double basePrice = 100 + (Math.Sin(i * 0.2) * 5);
indicator.HistoricalData.AddBar(now.AddMinutes(i), basePrice, basePrice + 2, basePrice - 2, basePrice, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -204,10 +204,10 @@ public class YzvIndicatorTests
// Price with varying OHLC
for (int i = 0; i < 20; i++)
{
double open = 100 + Math.Sin(i * 0.3) * 3;
double open = 100 + (Math.Sin(i * 0.3) * 3);
double high = open + 2 + Math.Abs(Math.Sin(i * 0.5));
double low = open - 2 - Math.Abs(Math.Cos(i * 0.5));
double close = open + Math.Sin(i * 0.4) * 2;
double close = open + (Math.Sin(i * 0.4) * 2);
indicator.HistoricalData.AddBar(now.AddMinutes(i), open, high, low, close, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -232,7 +232,7 @@ public class YzvIndicatorTests
for (int i = 0; i < 60; i++)
{
double price = 100 + Math.Sin(i * 0.3) * 5;
double price = 100 + (Math.Sin(i * 0.3) * 5);
indicator1.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price, 1000);
indicator2.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price, 1000);
indicator1.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
@@ -292,7 +292,7 @@ public class YzvIndicatorTests
// Large gap up (open much higher than previous close)
for (int i = 10; i < 20; i++)
{
double open = 120 + (i - 10) * 2; // Large gaps
double open = 120 + ((i - 10) * 2); // Large gaps
indicator.HistoricalData.AddBar(now.AddMinutes(i), open, open + 2, open - 2, open + 1, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -316,7 +316,7 @@ public class YzvIndicatorTests
// Low volatility regime
for (int i = 0; i < 20; i++)
{
double price = 100 + Math.Sin(i * 0.5) * 0.5; // Small movements
double price = 100 + (Math.Sin(i * 0.5) * 0.5); // Small movements
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 0.2, price - 0.2, price, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
@@ -326,7 +326,7 @@ public class YzvIndicatorTests
// High volatility regime
for (int i = 20; i < 40; i++)
{
double price = 100 + Math.Sin(i * 0.5) * 10; // Large movements
double price = 100 + (Math.Sin(i * 0.5) * 10); // Large movements
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 5, price - 5, price, 1000);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
+2 -2
View File
@@ -112,14 +112,14 @@ public class YzvTests
// Low volatility: small H-L range
for (int i = 0; i < 30; i++)
{
double price = 100.0 + (i % 2) * 0.1;
double price = 100.0 + ((i % 2) * 0.1);
yzvLow.Update(new TBar(DateTime.UtcNow, price, price + 0.05, price - 0.05, price, 1000));
}
// High volatility: large H-L range
for (int i = 0; i < 30; i++)
{
double price = 100.0 + (i % 2) * 5.0;
double price = 100.0 + ((i % 2) * 5.0);
yzvHigh.Update(new TBar(DateTime.UtcNow, price, price + 5.0, price - 5.0, price + 2.0, 1000));
}
@@ -41,12 +41,12 @@ public class YzvValidationTests
double sOSq = ro * ro;
double sCSq = rc * rc;
double sRsSq = rh * (rh - rc) + rl * (rl - rc);
double sRsSq = (rh * (rh - rc)) + (rl * (rl - rc));
double ratioN = (double)(period + 1) / (period - 1);
double kYz = 0.34 / (1.34 + ratioN);
double sSqDaily = sOSq + kYz * sCSq + (1.0 - kYz) * sRsSq;
double sSqDaily = sOSq + (kYz * sCSq) + ((1.0 - kYz) * sRsSq);
// First bar: RMA = value, eComp = 1 - alpha
double alpha = 1.0 / period;
@@ -85,7 +85,7 @@ public class YzvValidationTests
double ratioN = (double)(period + 1) / (period - 1);
double kYz = 0.34 / (1.34 + ratioN);
double expectedK = 0.34 / (1.34 + 21.0 / 19.0);
double expectedK = 0.34 / (1.34 + (21.0 / 19.0));
Assert.Equal(expectedK, kYz, 10);
// Verify k is in reasonable range (0 < k < 0.5)
@@ -103,7 +103,7 @@ public class YzvValidationTests
double rh = Math.Log(high / open);
double rl = Math.Log(low / open);
double sRsSq = rh * (rh - rc) + rl * (rl - rc);
double sRsSq = (rh * (rh - rc)) + (rl * (rl - rc));
// Verify this is positive for typical bar
Assert.True(sRsSq >= 0, "Rogers-Satchell should be non-negative for valid OHLC");
@@ -225,8 +225,8 @@ public class YzvValidationTests
double moveSmall = 1.0;
double moveLarge = 10.0;
yzvSmall.Update(new TBar(DateTime.UtcNow, baseSmall, baseSmall + moveSmall, baseSmall - moveSmall, baseSmall + (i % 2) * moveSmall, 1000));
yzvLarge.Update(new TBar(DateTime.UtcNow, baseLarge, baseLarge + moveLarge, baseLarge - moveLarge, baseLarge + (i % 2) * moveLarge, 1000));
yzvSmall.Update(new TBar(DateTime.UtcNow, baseSmall, baseSmall + moveSmall, baseSmall - moveSmall, baseSmall + ((i % 2) * moveSmall), 1000));
yzvLarge.Update(new TBar(DateTime.UtcNow, baseLarge, baseLarge + moveLarge, baseLarge - moveLarge, baseLarge + ((i % 2) * moveLarge), 1000));
}
// Larger moves should produce larger YZV (roughly 10x)
@@ -272,7 +272,7 @@ public class YzvValidationTests
// No gap scenario
for (int i = 0; i < 30; i++)
{
double close = 100 + i * 0.1;
double close = 100 + (i * 0.1);
yzvNoGap.Update(new TBar(DateTime.UtcNow, close, close + 1, close - 1, close, 1000));
}
@@ -297,7 +297,7 @@ public class YzvValidationTests
// No gap scenario
for (int i = 0; i < 30; i++)
{
double close = 100 - i * 0.1;
double close = 100 - (i * 0.1);
yzvNoGap.Update(new TBar(DateTime.UtcNow, close, close + 1, close - 1, close, 1000));
}