mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-20 03:28:05 +00:00
normalization of methods
This commit is contained in:
@@ -215,7 +215,7 @@ public class MidpointTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batch = Midpoint.Calculate(source, period);
|
||||
var batch = Midpoint.Batch(source, period);
|
||||
|
||||
// Compare last values (after warmup)
|
||||
for (int i = period; i < source.Count; i++)
|
||||
@@ -234,12 +234,12 @@ public class MidpointTests
|
||||
var source = bars.Close;
|
||||
|
||||
// TSeries batch
|
||||
var batchResult = Midpoint.Calculate(source, period);
|
||||
var batchResult = Midpoint.Batch(source, period);
|
||||
|
||||
// Span calculation
|
||||
var sourceArray = source.Values.ToArray();
|
||||
var output = new double[count];
|
||||
Midpoint.Calculate(sourceArray.AsSpan(), output.AsSpan(), period);
|
||||
Midpoint.Batch(sourceArray.AsSpan(), output.AsSpan(), period);
|
||||
|
||||
for (int i = 0; i < source.Count; i++)
|
||||
{
|
||||
@@ -253,21 +253,21 @@ public class MidpointTests
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
Span<double> output = stackalloc double[10];
|
||||
Midpoint.Calculate(ReadOnlySpan<double>.Empty, output, 5);
|
||||
Midpoint.Batch(ReadOnlySpan<double>.Empty, output, 5);
|
||||
});
|
||||
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
ReadOnlySpan<double> source = stackalloc double[10];
|
||||
Span<double> output = stackalloc double[5];
|
||||
Midpoint.Calculate(source, output, 5);
|
||||
Midpoint.Batch(source, output, 5);
|
||||
});
|
||||
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
ReadOnlySpan<double> source = stackalloc double[10];
|
||||
Span<double> output = stackalloc double[10];
|
||||
Midpoint.Calculate(source, output, 0);
|
||||
Midpoint.Batch(source, output, 0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ public sealed class MidpointValidationTests : IDisposable
|
||||
{
|
||||
// Calculate QuanTAlib Midpoint (Span API)
|
||||
double[] qOutput = new double[sourceData.Length];
|
||||
Midpoint.Calculate(sourceData.AsSpan(), qOutput.AsSpan(), period);
|
||||
Midpoint.Batch(sourceData.AsSpan(), qOutput.AsSpan(), period);
|
||||
|
||||
// Calculate TA-Lib MIDPOINT
|
||||
var retCode = TALib.Functions.MidPoint<double>(sourceData, 0..^0, talibOutput, out var outRange, period);
|
||||
|
||||
@@ -23,6 +23,7 @@ public sealed class Midpoint : AbstractBase
|
||||
private readonly Lowest _lowest;
|
||||
private readonly ITValuePublisher? _source;
|
||||
private readonly TValuePublishedHandler? _handler;
|
||||
private bool _disposed;
|
||||
|
||||
public override bool IsHot => _highest.IsHot && _lowest.IsHot;
|
||||
|
||||
@@ -57,9 +58,13 @@ public sealed class Midpoint : AbstractBase
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && _source != null && _handler != null)
|
||||
if (!_disposed)
|
||||
{
|
||||
_source.Pub -= _handler;
|
||||
if (disposing && _source != null && _handler != null)
|
||||
{
|
||||
_source.Pub -= _handler;
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
@@ -106,7 +111,7 @@ public sealed class Midpoint : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
public static TSeries Calculate(TSeries source, int period)
|
||||
public static TSeries Batch(TSeries source, int period)
|
||||
{
|
||||
var indicator = new Midpoint(period);
|
||||
return indicator.Update(source);
|
||||
@@ -115,7 +120,7 @@ public sealed class Midpoint : AbstractBase
|
||||
/// <summary>
|
||||
/// Calculates rolling midpoint over a span of values.
|
||||
/// </summary>
|
||||
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period)
|
||||
public static void Batch(ReadOnlySpan<double> source, Span<double> output, int period)
|
||||
{
|
||||
if (source.Length == 0)
|
||||
{
|
||||
@@ -150,8 +155,8 @@ public sealed class Midpoint : AbstractBase
|
||||
|
||||
try
|
||||
{
|
||||
Highest.Calculate(source, highBuffer, period);
|
||||
Lowest.Calculate(source, lowBuffer, period);
|
||||
Highest.Batch(source, highBuffer, period);
|
||||
Lowest.Batch(source, lowBuffer, period);
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
@@ -172,10 +177,17 @@ public sealed class Midpoint : AbstractBase
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Midpoint Indicator) Calculate(TSeries source, int period)
|
||||
{
|
||||
var indicator = new Midpoint(period);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_highest.Reset();
|
||||
_lowest.Reset();
|
||||
Last = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user