mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-24 13:38:05 +00:00
style patterns
This commit is contained in:
@@ -164,4 +164,4 @@ public class HanmaIndicatorTests
|
||||
Assert.Equal(20, indicator.Period);
|
||||
Assert.Equal(0, HanmaIndicator.MinHistoryDepths);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,4 +55,4 @@ public class HanmaIndicator : Indicator, IWatchlistIndicator
|
||||
|
||||
Series.SetValue(result.Value, ma.IsHot, ShowColdValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,4 +444,4 @@ public class HanmaTests
|
||||
// Result should be 100.0 (weighted average of middle values only)
|
||||
Assert.Equal(100.0, hanma.Last.Value, 1e-9);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,4 +172,4 @@ public class HanmaValidationTests
|
||||
// Should be different (different window coefficients)
|
||||
Assert.NotEqual(hanmaResults.Last.Value, hammaResults.Last.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,9 @@ public sealed class Hanma : AbstractBase
|
||||
public Hanma(int period = 10)
|
||||
{
|
||||
if (period <= 0)
|
||||
{
|
||||
throw new ArgumentException("Period must be greater than 0", nameof(period));
|
||||
}
|
||||
|
||||
_period = period;
|
||||
_buffer = new RingBuffer(period);
|
||||
@@ -178,7 +180,10 @@ public sealed class Hanma : 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);
|
||||
@@ -218,7 +223,10 @@ public sealed class Hanma : AbstractBase
|
||||
private double CalculateWeightedSum()
|
||||
{
|
||||
int count = _buffer.Count;
|
||||
if (count == 0) return 0;
|
||||
if (count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (count < _period)
|
||||
{
|
||||
@@ -289,9 +297,14 @@ public sealed class Hanma : 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;
|
||||
@@ -393,15 +406,22 @@ public sealed class Hanma : AbstractBase
|
||||
if (startIdx + count <= period)
|
||||
{
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
avg += buffer[startIdx + j];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int p1Len = period - startIdx;
|
||||
for (int j = 0; j < p1Len; j++)
|
||||
{
|
||||
avg += buffer[startIdx + j];
|
||||
}
|
||||
|
||||
for (int j = 0; j < count - p1Len; j++)
|
||||
{
|
||||
avg += buffer[j];
|
||||
}
|
||||
}
|
||||
output[i] = avg / count;
|
||||
}
|
||||
@@ -410,8 +430,15 @@ public sealed class Hanma : 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,4 +449,4 @@ public sealed class Hanma : AbstractBase
|
||||
_p_state = _state;
|
||||
Last = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user