mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-19 19:18:05 +00:00
[CodeFactor] Apply fixes to commit 4a01f03
This commit is contained in:
@@ -94,7 +94,7 @@ public class CcorValidationTests
|
||||
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
double val = 100.0 + 10.0 * Math.Sin(2.0 * Math.PI * i / period);
|
||||
double val = 100.0 + (10.0 * Math.Sin(2.0 * Math.PI * i / period));
|
||||
ccor.Update(new TValue(DateTime.UtcNow.AddMinutes(i), val), true);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class CcorValidationTests
|
||||
$"Sine wave should produce non-trivial phasor: Real={ccor.Real:F4}, Imag={ccor.Imag:F4}");
|
||||
|
||||
// R² + I² should be near 1 for a pure tone at the matched frequency
|
||||
double magnitude = Math.Sqrt(ccor.Real * ccor.Real + ccor.Imag * ccor.Imag);
|
||||
double magnitude = Math.Sqrt((ccor.Real * ccor.Real) + (ccor.Imag * ccor.Imag));
|
||||
Assert.True(magnitude > 0.5,
|
||||
$"Phasor magnitude should be significant for matched sine: {magnitude:F4}");
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class CcorValidationTests
|
||||
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
double val = 100.0 + 10.0 * Math.Sin(2.0 * Math.PI * i / period);
|
||||
double val = 100.0 + (10.0 * Math.Sin(2.0 * Math.PI * i / period));
|
||||
ccor.Update(new TValue(DateTime.UtcNow.AddMinutes(i), val), true);
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ public class CcorValidationTests
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
ind.Update(new TValue(t0.AddMinutes(i),
|
||||
100.0 + 10.0 * Math.Sin(2.0 * Math.PI * i / 20.0)), isNew: true);
|
||||
100.0 + (10.0 * Math.Sin(2.0 * Math.PI * i / 20.0))), isNew: true);
|
||||
}
|
||||
|
||||
// Anchor bar
|
||||
|
||||
@@ -158,7 +158,7 @@ public sealed class Ccor : AbstractBase
|
||||
// Phasor angle (degrees) with quadrant resolution
|
||||
if (imagVal != 0.0)
|
||||
{
|
||||
angleVal = 90.0 + Math.Atan(realVal / imagVal) * (180.0 / Math.PI);
|
||||
angleVal = 90.0 + (Math.Atan(realVal / imagVal) * (180.0 / Math.PI));
|
||||
}
|
||||
if (imagVal > 0.0)
|
||||
{
|
||||
@@ -342,7 +342,7 @@ public sealed class Ccor : AbstractBase
|
||||
|
||||
for (int k = 0; k < n; k++)
|
||||
{
|
||||
int idx = ((bufIdx - 1 - k) % period + period) % period;
|
||||
int idx = (((bufIdx - 1 - k) % period) + period) % period;
|
||||
double x = priceBuf[idx];
|
||||
double y = cosTab[k];
|
||||
sx += x;
|
||||
@@ -353,8 +353,8 @@ public sealed class Ccor : AbstractBase
|
||||
}
|
||||
|
||||
double nd = n;
|
||||
double dp = (nd * sxx - sx * sx) * (nd * syy - sy * sy);
|
||||
realVal = dp > 0.0 ? Math.Clamp((nd * sxy - sx * sy) / Math.Sqrt(dp), -1.0, 1.0) : 0.0;
|
||||
double dp = ((nd * sxx) - (sx * sx)) * ((nd * syy) - (sy * sy));
|
||||
realVal = dp > 0.0 ? Math.Clamp(((nd * sxy) - (sx * sy)) / Math.Sqrt(dp), -1.0, 1.0) : 0.0;
|
||||
}
|
||||
|
||||
output[i] = realVal;
|
||||
@@ -423,13 +423,13 @@ public sealed class Ccor : AbstractBase
|
||||
}
|
||||
|
||||
double nd = n;
|
||||
double denomProd = (nd * sxx - sx * sx) * (nd * syy - sy * sy);
|
||||
double denomProd = ((nd * sxx) - (sx * sx)) * ((nd * syy) - (sy * sy));
|
||||
if (denomProd <= 0.0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double r = (nd * sxy - sx * sy) / Math.Sqrt(denomProd);
|
||||
double r = ((nd * sxy) - (sx * sy)) / Math.Sqrt(denomProd);
|
||||
return Math.Clamp(r, -1.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user