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
@@ -157,4 +157,4 @@ public class SinemaIndicatorTests
Assert.Equal(20, indicator.Period);
Assert.Equal(0, SinemaIndicator.MinHistoryDepths);
}
}
}
+1 -1
View File
@@ -51,4 +51,4 @@ public sealed class SinemaIndicator : Indicator, IWatchlistIndicator
double value = _sinema.Update(new TValue(item.TimeLeft.Ticks, _priceSelector(item)), isNew).Value;
_series.SetValue(value, _sinema.IsHot, ShowColdValues);
}
}
}
+7 -2
View File
@@ -420,7 +420,9 @@ public class SinemaTests
double[] output = new double[10000];
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
Sinema.Batch(source.AsSpan(), output.AsSpan(), 100);
@@ -562,7 +564,10 @@ public class SinemaTests
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);
}
var (results, indicator) = Sinema.Calculate(series, 5);
@@ -579,4 +584,4 @@ public class SinemaTests
indicator.Update(new TValue(DateTime.UtcNow, 110));
Assert.True(double.IsFinite(indicator.Last.Value));
}
}
}
@@ -27,7 +27,11 @@ public sealed class SinemaValidationTests : IDisposable
private void Dispose(bool disposing)
{
if (_disposed) return;
if (_disposed)
{
return;
}
_disposed = true;
if (disposing)
{
@@ -319,4 +323,4 @@ public sealed class SinemaValidationTests : IDisposable
_output.WriteLine($"SINEMA({period}) all modes consistent: {batchResult:F10}");
}
}
}
+41 -5
View File
@@ -44,7 +44,9 @@ public sealed class Sinema : AbstractBase
public Sinema(int period)
{
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
_period = period;
_buffer = new RingBuffer(period);
@@ -101,7 +103,10 @@ public sealed class Sinema : AbstractBase
/// <param name="step">Optional time step (unused)</param>
public override void Prime(ReadOnlySpan<double> source, TimeSpan? step = null)
{
if (source.Length == 0) return;
if (source.Length == 0)
{
return;
}
// Reset state
_buffer.Clear();
@@ -165,7 +170,10 @@ public sealed class Sinema : AbstractBase
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private double CalculateFromBuffer()
{
if (_buffer.Count == 0) return double.NaN;
if (_buffer.Count == 0)
{
return double.NaN;
}
int count = _buffer.Count;
double sum = 0;
@@ -222,7 +230,10 @@ public sealed class Sinema : 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);
@@ -269,12 +280,20 @@ public sealed class Sinema : AbstractBase
public static void Batch(ReadOnlySpan<double> source, Span<double> output, int period)
{
if (source.Length != output.Length)
{
throw new ArgumentException("Source and output must have the same length", nameof(output));
}
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
int len = source.Length;
if (len == 0) return;
if (len == 0)
{
return;
}
CalculateScalarCore(source, output, period);
}
@@ -318,9 +337,13 @@ public sealed class Sinema : AbstractBase
{
double val = source[i];
if (double.IsFinite(val))
{
lastValid = val;
}
else
{
val = lastValid;
}
buffer[i] = val;
@@ -351,14 +374,20 @@ public sealed class Sinema : AbstractBase
{
double val = source[i];
if (double.IsFinite(val))
{
lastValid = val;
}
else
{
val = lastValid;
}
buffer[bufferIndex] = val;
bufferIndex++;
if (bufferIndex >= period)
{
bufferIndex = 0;
}
// Calculate weighted sum using circular buffer
double sum = 0;
@@ -368,7 +397,9 @@ public sealed class Sinema : AbstractBase
sum += buffer[bufIdx] * weights[j];
bufIdx++;
if (bufIdx >= period)
{
bufIdx = 0;
}
}
output[i] = sum / fullWeightSum;
@@ -377,9 +408,14 @@ public sealed class Sinema : AbstractBase
finally
{
if (rentedBuffer != null)
{
ArrayPool<double>.Shared.Return(rentedBuffer);
}
if (rentedWeights != null)
{
ArrayPool<double>.Shared.Return(rentedWeights);
}
}
}
@@ -407,4 +443,4 @@ public sealed class Sinema : AbstractBase
_p_state = default;
Last = default;
}
}
}