mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-16 01:28:05 +00:00
fix: address code review issues in indicators and core components
This commit is contained in:
@@ -82,6 +82,22 @@ public sealed class RingBuffer : IEnumerable<double>
|
||||
get => _sum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recalculates the sum by iterating over all elements.
|
||||
/// Useful for correcting floating-point drift after many updates.
|
||||
/// </summary>
|
||||
public double RecalculateSum()
|
||||
{
|
||||
double sum = 0;
|
||||
var span = GetSpan();
|
||||
for (int i = 0; i < span.Length; i++)
|
||||
{
|
||||
sum += span[i];
|
||||
}
|
||||
_sum = sum;
|
||||
return sum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Average of all elements in the buffer.
|
||||
/// Returns 0 if buffer is empty.
|
||||
|
||||
@@ -129,12 +129,10 @@ public class TBarSeries : IReadOnlyList<TBar>
|
||||
throw new ArgumentException("All arrays must have the same length");
|
||||
}
|
||||
|
||||
_t.AddRange(tArr);
|
||||
_o.AddRange(oArr);
|
||||
_h.AddRange(hArr);
|
||||
_l.AddRange(lArr);
|
||||
_c.AddRange(cArr);
|
||||
_v.AddRange(vArr);
|
||||
for (int i = 0; i < tArr.Length; i++)
|
||||
{
|
||||
Add(tArr[i], oArr[i], hArr[i], lArr[i], cArr[i], vArr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<TBar> GetEnumerator()
|
||||
|
||||
@@ -24,7 +24,7 @@ public readonly struct TValue : IEquatable<TValue>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public TValue(DateTime time, double value)
|
||||
{
|
||||
Time = time.Ticks;
|
||||
Time = time.Kind == DateTimeKind.Utc ? time.Ticks : time.ToUniversalTime().Ticks;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public readonly struct TValue : IEquatable<TValue>
|
||||
public override string ToString() => $"[{AsDateTime:yyyy-MM-dd HH:mm:ss}, {Value:F2}]";
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(TValue other) => Time == other.Time && Math.Abs(Value - other.Value) < 1e-9;
|
||||
public bool Equals(TValue other) => Time == other.Time && Value == other.Value;
|
||||
|
||||
public override bool Equals(object? obj) => obj is TValue other && Equals(other);
|
||||
public override int GetHashCode() => HashCode.Combine(Time, Value);
|
||||
|
||||
Reference in New Issue
Block a user