mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 22:08:05 +00:00
normalization of methods
This commit is contained in:
@@ -424,7 +424,7 @@ public class JvoltynTests
|
||||
|
||||
// Span calculation
|
||||
var output = new double[series.Count];
|
||||
Jvoltyn.Calculate(series.Values, output, 10);
|
||||
Jvoltyn.Batch(series.Values, output, 10);
|
||||
|
||||
// Compare last value (after warmup)
|
||||
Assert.Equal(streamingLast, output[series.Count - 1], 1e-6);
|
||||
@@ -503,7 +503,7 @@ public class JvoltynTests
|
||||
var source = new double[10];
|
||||
var output = new double[5]; // Wrong size
|
||||
|
||||
var ex = Assert.Throws<ArgumentException>(() => Jvoltyn.Calculate(source, output, 10));
|
||||
var ex = Assert.Throws<ArgumentException>(() => Jvoltyn.Batch(source, output, 10));
|
||||
Assert.Equal("output", ex.ParamName);
|
||||
}
|
||||
|
||||
@@ -513,7 +513,7 @@ public class JvoltynTests
|
||||
var source = Array.Empty<double>();
|
||||
var output = Array.Empty<double>();
|
||||
|
||||
var exception = Record.Exception(() => Jvoltyn.Calculate(source, output, 10));
|
||||
var exception = Record.Exception(() => Jvoltyn.Batch(source, output, 10));
|
||||
Assert.Null(exception);
|
||||
}
|
||||
|
||||
@@ -523,7 +523,7 @@ public class JvoltynTests
|
||||
var source = new double[10];
|
||||
var output = new double[10];
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Jvoltyn.Calculate(source, output, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Jvoltyn.Batch(source, output, 0));
|
||||
}
|
||||
|
||||
// ============== Edge Cases ==============
|
||||
|
||||
@@ -38,6 +38,7 @@ public sealed class Jvoltyn : AbstractBase
|
||||
private readonly RingBuffer _volBuffer;
|
||||
private readonly TValuePublishedHandler _handler;
|
||||
private readonly ITValuePublisher? _source;
|
||||
private bool _disposed;
|
||||
|
||||
// Streaming state (current + previous snapshot for isNew=false)
|
||||
private State _s;
|
||||
@@ -305,9 +306,13 @@ public sealed class Jvoltyn : AbstractBase
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && _source != null)
|
||||
if (!_disposed)
|
||||
{
|
||||
_source.Pub -= _handler;
|
||||
if (disposing && _source != null)
|
||||
{
|
||||
_source.Pub -= _handler;
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
@@ -332,7 +337,7 @@ public sealed class Jvoltyn : AbstractBase
|
||||
/// <summary>
|
||||
/// Static helper for span-based calculation.
|
||||
/// </summary>
|
||||
public static void Calculate(ReadOnlySpan<double> source,
|
||||
public static void Batch(ReadOnlySpan<double> source,
|
||||
Span<double> output,
|
||||
int period)
|
||||
{
|
||||
@@ -353,6 +358,13 @@ public sealed class Jvoltyn : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Jvoltyn Indicator) Calculate(TSeries source, int period)
|
||||
{
|
||||
var indicator = new Jvoltyn(period);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private double CalculateTrimmedMean(double fallback)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user