mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 05:48:06 +00:00
normalization of methods
This commit is contained in:
@@ -152,7 +152,7 @@ public class BwmaTests
|
||||
}
|
||||
|
||||
var spanResults = new double[series.Count];
|
||||
Bwma.Calculate(series.Values, spanResults, 10);
|
||||
Bwma.Batch(series.Values, spanResults, 10);
|
||||
|
||||
for (int i = 0; i < spanResults.Length; i++)
|
||||
{
|
||||
@@ -175,7 +175,7 @@ public class BwmaTests
|
||||
}
|
||||
|
||||
var spanResults = new double[series.Count];
|
||||
Bwma.Calculate(series.Values, spanResults, 10, 2);
|
||||
Bwma.Batch(series.Values, spanResults, 10, 2);
|
||||
|
||||
for (int i = 0; i < spanResults.Length; i++)
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ public sealed class BwmaValidationTests : IDisposable
|
||||
// 3. Span API
|
||||
ReadOnlySpan<double> sourceData = _testData.RawData.Span;
|
||||
double[] spanOutput = new double[sourceData.Length];
|
||||
Bwma.Calculate(sourceData, spanOutput.AsSpan(), period, order);
|
||||
Bwma.Batch(sourceData, spanOutput.AsSpan(), period, order);
|
||||
|
||||
// Verify streaming vs batch
|
||||
Assert.Equal(streamingResults.Count, batchResults.Count);
|
||||
@@ -257,7 +257,7 @@ public sealed class BwmaValidationTests : IDisposable
|
||||
|
||||
// Span
|
||||
double[] spanOutput = new double[dataWithNaN.Count];
|
||||
Bwma.Calculate(dataWithNaN.Values, spanOutput.AsSpan(), period);
|
||||
Bwma.Batch(dataWithNaN.Values, spanOutput.AsSpan(), period);
|
||||
|
||||
// Verify all produce same results
|
||||
for (int i = 0; i < streamingResults.Count; i++)
|
||||
|
||||
@@ -26,6 +26,7 @@ public sealed class Bwma : AbstractBase
|
||||
private readonly ITValuePublisher? _source;
|
||||
private readonly TValuePublishedHandler? _pubHandler;
|
||||
private bool _isNew = true;
|
||||
private bool _disposed;
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
private record struct State
|
||||
@@ -81,9 +82,13 @@ public sealed class Bwma : AbstractBase
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && _source != null && _pubHandler != null)
|
||||
if (!_disposed)
|
||||
{
|
||||
_source.Pub -= _pubHandler;
|
||||
if (disposing && _source != null && _pubHandler != null)
|
||||
{
|
||||
_source.Pub -= _pubHandler;
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
@@ -199,7 +204,7 @@ public sealed class Bwma : AbstractBase
|
||||
var tSpan = CollectionsMarshal.AsSpan(t);
|
||||
var vSpan = CollectionsMarshal.AsSpan(v);
|
||||
|
||||
Calculate(source.Values, vSpan, _period, _order);
|
||||
Batch(source.Values, vSpan, _period, _order);
|
||||
source.Times.CopyTo(tSpan);
|
||||
|
||||
_buffer.Clear();
|
||||
@@ -338,7 +343,7 @@ public sealed class Bwma : AbstractBase
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period, int order = 0)
|
||||
public static void Batch(ReadOnlySpan<double> source, Span<double> output, int period, int order = 0)
|
||||
{
|
||||
if (period <= 0)
|
||||
{
|
||||
@@ -477,6 +482,13 @@ public sealed class Bwma : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Bwma Indicator) Calculate(TSeries source, int period, int order = 0)
|
||||
{
|
||||
var indicator = new Bwma(period, order);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_buffer.Clear();
|
||||
@@ -484,4 +496,4 @@ public sealed class Bwma : AbstractBase
|
||||
_p_state = _state;
|
||||
Last = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user