mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-24 05:28:05 +00:00
style patterns
This commit is contained in:
@@ -134,4 +134,4 @@ public class BpfIndicatorTests
|
||||
Assert.Equal(60, indicator.LowerPeriod);
|
||||
Assert.Equal(20, indicator.UpperPeriod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,4 +116,4 @@ public class BpfTests
|
||||
// Last value should be close to 0
|
||||
Assert.True(Math.Abs(output[^1]) < 1e-6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ public class BpfValidationTests
|
||||
double[] sine15 = new double[T]; // Period 15 (Inside band, 10 < P < 40). Should pass.
|
||||
double[] sine100 = new double[T]; // Period 100 (Too slow, should be blocked by HP(40)). HP(40) passes P < 40.
|
||||
|
||||
for (int i = 0; i < T; i++) {
|
||||
for (int i = 0; i < T; i++)
|
||||
{
|
||||
sine5[i] = Math.Sin(2 * Math.PI * i / 5.0);
|
||||
sine15[i] = Math.Sin(2 * Math.PI * i / 15.0);
|
||||
sine100[i] = Math.Sin(2 * Math.PI * i / 100.0);
|
||||
|
||||
+16
-3
@@ -53,9 +53,14 @@ public sealed class Bpf : AbstractBase
|
||||
public Bpf(int lowerPeriod, int upperPeriod)
|
||||
{
|
||||
if (lowerPeriod < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(lowerPeriod), "Lower period must be >= 1");
|
||||
}
|
||||
|
||||
if (upperPeriod < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(upperPeriod), "Upper period must be >= 1");
|
||||
}
|
||||
|
||||
LowerPeriod = lowerPeriod;
|
||||
UpperPeriod = upperPeriod;
|
||||
@@ -95,7 +100,10 @@ public sealed class Bpf : AbstractBase
|
||||
|
||||
public override TSeries Update(TSeries source)
|
||||
{
|
||||
if (source.Count == 0) return [];
|
||||
if (source.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
double[] values = source.Values.ToArray();
|
||||
double[] results = new double[values.Length];
|
||||
@@ -186,7 +194,9 @@ public sealed class Bpf : AbstractBase
|
||||
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int lowerPeriod, int upperPeriod)
|
||||
{
|
||||
if (source.Length != output.Length)
|
||||
{
|
||||
throw new ArgumentException("Source and output spans must be of the same length.", nameof(output));
|
||||
}
|
||||
|
||||
// Coefficients
|
||||
double sqrt2Pi = Math.Sqrt(2.0) * Math.PI;
|
||||
@@ -213,7 +223,10 @@ public sealed class Bpf : AbstractBase
|
||||
if (source.Length > 0)
|
||||
{
|
||||
lastValid = source[0];
|
||||
if (!double.IsFinite(lastValid)) lastValid = 0;
|
||||
if (!double.IsFinite(lastValid))
|
||||
{
|
||||
lastValid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < source.Length; i++)
|
||||
@@ -260,4 +273,4 @@ public sealed class Bpf : AbstractBase
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user