mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-24 05:28:05 +00:00
normalization of methods
This commit is contained in:
@@ -397,7 +397,7 @@ public class JvoltyTests
|
||||
|
||||
// Span calculation
|
||||
var output = new double[series.Count];
|
||||
Jvolty.Calculate(series.Values, output, 10);
|
||||
Jvolty.Batch(series.Values, output, 10);
|
||||
|
||||
// Compare last value (after warmup)
|
||||
Assert.Equal(streamingLast, output[series.Count - 1], 1e-6);
|
||||
@@ -435,7 +435,7 @@ public class JvoltyTests
|
||||
var source = new double[10];
|
||||
var output = new double[5]; // Wrong size
|
||||
|
||||
var ex = Assert.Throws<ArgumentException>(() => Jvolty.Calculate(source, output, 10));
|
||||
var ex = Assert.Throws<ArgumentException>(() => Jvolty.Batch(source, output, 10));
|
||||
Assert.Equal("output", ex.ParamName);
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ public class JvoltyTests
|
||||
var source = Array.Empty<double>();
|
||||
var output = Array.Empty<double>();
|
||||
|
||||
var exception = Record.Exception(() => Jvolty.Calculate(source, output, 10));
|
||||
var exception = Record.Exception(() => Jvolty.Batch(source, output, 10));
|
||||
Assert.Null(exception);
|
||||
}
|
||||
|
||||
@@ -455,7 +455,7 @@ public class JvoltyTests
|
||||
var source = new double[10];
|
||||
var output = new double[10];
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Jvolty.Calculate(source, output, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Jvolty.Batch(source, output, 0));
|
||||
}
|
||||
|
||||
// ============== Edge Cases ==============
|
||||
|
||||
@@ -37,6 +37,7 @@ public sealed class Jvolty : 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;
|
||||
@@ -293,9 +294,13 @@ public sealed class Jvolty : 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);
|
||||
}
|
||||
@@ -320,7 +325,7 @@ public sealed class Jvolty : 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)
|
||||
{
|
||||
@@ -341,6 +346,13 @@ public sealed class Jvolty : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Jvolty Indicator) Calculate(TSeries source, int period)
|
||||
{
|
||||
var indicator = new Jvolty(period);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private double CalculateTrimmedMean(double fallback)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user