style patterns

This commit is contained in:
Miha Kralj
2026-01-25 16:01:45 -08:00
parent 2836f253c4
commit e59665c8f0
399 changed files with 6892 additions and 1323 deletions
+1 -1
View File
@@ -166,4 +166,4 @@ public class CmaIndicatorTests
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.NewBar));
Assert.Equal(20.0, indicator.LinesSeries[0].GetValue(0), 1e-10); // CMA = (10+20+30)/3 = 20
}
}
}
+6 -1
View File
@@ -401,7 +401,9 @@ public class CmaTests
var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 42);
for (int i = 0; i < source.Length; i++)
{
source[i] = gbm.Next().Close;
}
// Warm up
Cma.Batch(source.AsSpan(), output.AsSpan());
@@ -520,7 +522,10 @@ public class CmaTests
public void Calculate_ReturnsCorrectResultsAndHotIndicator()
{
var series = new TSeries();
for (int i = 1; i <= 10; i++) series.Add(DateTime.UtcNow, i * 10);
for (int i = 1; i <= 10; i++)
{
series.Add(DateTime.UtcNow, i * 10);
}
// 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
var (results, indicator) = Cma.Calculate(series);
+19 -4
View File
@@ -96,7 +96,10 @@ public sealed class Cma : AbstractBase
/// <param name="step">Time interval between values (not used for CMA)</param>
public override void Prime(ReadOnlySpan<double> source, TimeSpan? step = null)
{
if (source.Length == 0) return;
if (source.Length == 0)
{
return;
}
// Reset state
_state = default;
@@ -162,7 +165,10 @@ public sealed class Cma : AbstractBase
public override TSeries Update(TSeries source)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
int len = source.Count;
var t = new List<long>(len);
@@ -207,10 +213,15 @@ public sealed class Cma : AbstractBase
public static void Batch(ReadOnlySpan<double> source, Span<double> output)
{
if (source.Length != output.Length)
{
throw new ArgumentException("Source and output must have the same length", nameof(output));
}
int len = source.Length;
if (len == 0) return;
if (len == 0)
{
return;
}
double mean = 0;
double lastValid = double.NaN;
@@ -230,9 +241,13 @@ public sealed class Cma : AbstractBase
{
double val = source[i];
if (double.IsFinite(val))
{
lastValid = val;
}
else
{
val = lastValid;
}
// M_n = M_(n-1) + alpha * delta using FMA for single-rounding precision
double alpha = 1.0 / (i + 1);
@@ -264,4 +279,4 @@ public sealed class Cma : AbstractBase
_p_state = default;
Last = default;
}
}
}