mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-23 04:58:08 +00:00
style patterns
This commit is contained in:
@@ -164,4 +164,4 @@ public class HammaIndicatorTests
|
||||
Assert.Equal(20, indicator.Period);
|
||||
Assert.Equal(0, HammaIndicator.MinHistoryDepths);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,4 +55,4 @@ public class HammaIndicator : Indicator, IWatchlistIndicator
|
||||
|
||||
Series.SetValue(result.Value, ma.IsHot, ShowColdValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,4 +409,4 @@ public class HammaTests
|
||||
Assert.Equal(i * 10.0, result.Value, 1e-9);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,4 +203,4 @@ public sealed class HammaValidationTests : IDisposable
|
||||
// All edge weights should be equal
|
||||
Assert.Equal(w0, w4, 1e-10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,9 @@ public sealed class Hamma : AbstractBase
|
||||
public Hamma(int period = 10)
|
||||
{
|
||||
if (period <= 0)
|
||||
{
|
||||
throw new ArgumentException("Period must be greater than 0", nameof(period));
|
||||
}
|
||||
|
||||
_period = period;
|
||||
_buffer = new RingBuffer(period);
|
||||
@@ -184,7 +186,10 @@ public sealed class Hamma : AbstractBase
|
||||
|
||||
public override TSeries Update(TSeries source)
|
||||
{
|
||||
if (source.Count == 0) return new TSeries([], []);
|
||||
if (source.Count == 0)
|
||||
{
|
||||
return new TSeries([], []);
|
||||
}
|
||||
|
||||
int len = source.Count;
|
||||
var t = new List<long>(len);
|
||||
@@ -224,7 +229,10 @@ public sealed class Hamma : AbstractBase
|
||||
private double CalculateWeightedSum()
|
||||
{
|
||||
int count = _buffer.Count;
|
||||
if (count == 0) return 0;
|
||||
if (count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (count < _period)
|
||||
{
|
||||
@@ -283,9 +291,14 @@ public sealed class Hamma : AbstractBase
|
||||
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period = 10)
|
||||
{
|
||||
if (period <= 0)
|
||||
{
|
||||
throw new ArgumentException("Period must be greater than 0", nameof(period));
|
||||
}
|
||||
|
||||
if (source.Length != output.Length)
|
||||
{
|
||||
throw new ArgumentException("Source and output must have the same length", nameof(output));
|
||||
}
|
||||
|
||||
// Allocation Strategy: Stack for small periods, Pool for large
|
||||
double[]? weightsArray = period > 256 ? ArrayPool<double>.Shared.Rent(period) : null;
|
||||
@@ -381,8 +394,15 @@ public sealed class Hamma : AbstractBase
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (weightsArray != null) ArrayPool<double>.Shared.Return(weightsArray);
|
||||
if (bufferArray != null) ArrayPool<double>.Shared.Return(bufferArray);
|
||||
if (weightsArray != null)
|
||||
{
|
||||
ArrayPool<double>.Shared.Return(weightsArray);
|
||||
}
|
||||
|
||||
if (bufferArray != null)
|
||||
{
|
||||
ArrayPool<double>.Shared.Return(bufferArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user