normalization of methods

This commit is contained in:
Miha Kralj
2026-02-10 21:33:16 -08:00
parent 915d7a007b
commit 6d6259a47d
527 changed files with 10525 additions and 2123 deletions
+6 -6
View File
@@ -304,7 +304,7 @@ public class TviTests
}
// Batch
var batchResult = Tvi.Calculate(bars);
var batchResult = Tvi.Batch(bars);
Assert.Equal(bars.Count, batchResult.Count);
for (int i = 0; i < bars.Count; i++)
@@ -337,7 +337,7 @@ public class TviTests
var volume = bars.Volume.Values.ToArray();
var output = new double[bars.Count];
Tvi.Calculate(price, volume, output);
Tvi.Batch(price, volume, output);
for (int i = 0; i < bars.Count; i++)
{
@@ -352,7 +352,7 @@ public class TviTests
var volume = new double[99]; // Different length
var output = new double[100];
Assert.Throws<ArgumentException>(() => Tvi.Calculate(price, volume, output));
Assert.Throws<ArgumentException>(() => Tvi.Batch(price, volume, output));
}
[Fact]
@@ -362,8 +362,8 @@ public class TviTests
var volume = new double[100];
var output = new double[100];
Assert.Throws<ArgumentException>(() => Tvi.Calculate(price, volume, output, minTick: 0));
Assert.Throws<ArgumentException>(() => Tvi.Calculate(price, volume, output, minTick: -1));
Assert.Throws<ArgumentException>(() => Tvi.Batch(price, volume, output, minTick: 0));
Assert.Throws<ArgumentException>(() => Tvi.Batch(price, volume, output, minTick: -1));
}
[Fact]
@@ -373,7 +373,7 @@ public class TviTests
var volume = Array.Empty<double>();
var output = Array.Empty<double>();
Tvi.Calculate(price, volume, output);
Tvi.Batch(price, volume, output);
Assert.Empty(output);
}
+4 -4
View File
@@ -26,7 +26,7 @@ public class TviValidationTests
}
// Batch
var batchResult = Tvi.Calculate(_data.Bars, minTick);
var batchResult = Tvi.Batch(_data.Bars, minTick);
var batchValues = batchResult.Values.ToArray();
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-9);
@@ -50,7 +50,7 @@ public class TviValidationTests
var volume = _data.Bars.Volume.Values.ToArray();
var spanOutput = new double[close.Length];
Tvi.Calculate(close, volume, spanOutput, minTick);
Tvi.Batch(close, volume, spanOutput, minTick);
ValidationHelper.VerifyData(streamingValues.ToArray(), spanOutput, 0, 100, 1e-9);
}
@@ -139,14 +139,14 @@ public class TviValidationTests
}
// Batch
var batchResult = Tvi.Calculate(_data.Bars, minTick);
var batchResult = Tvi.Batch(_data.Bars, minTick);
var batchValues = batchResult.Values.ToArray();
// Span
var close = _data.Bars.Close.Values.ToArray();
var volume = _data.Bars.Volume.Values.ToArray();
var spanOutput = new double[close.Length];
Tvi.Calculate(close, volume, spanOutput, minTick);
Tvi.Batch(close, volume, spanOutput, minTick);
// Verify all modes match
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-9);
+10 -3
View File
@@ -207,7 +207,7 @@ public sealed class Tvi : ITValuePublisher
return new TSeries(t, v);
}
public static TSeries Calculate(TBarSeries source, double minTick = 0.125)
public static TSeries Batch(TBarSeries source, double minTick = 0.125)
{
if (source.Count == 0)
{
@@ -217,13 +217,13 @@ public sealed class Tvi : ITValuePublisher
var t = source.Open.Times.ToArray();
var v = new double[source.Count];
Calculate(source.Close.Values, source.Volume.Values, v, minTick);
Batch(source.Close.Values, source.Volume.Values, v, minTick);
return new TSeries(t, v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Calculate(ReadOnlySpan<double> price, ReadOnlySpan<double> volume, Span<double> output, double minTick = 0.125)
public static void Batch(ReadOnlySpan<double> price, ReadOnlySpan<double> volume, Span<double> output, double minTick = 0.125)
{
if (price.Length != volume.Length)
{
@@ -304,4 +304,11 @@ public sealed class Tvi : ITValuePublisher
}
}
}
public static (TSeries Results, Tvi Indicator) Calculate(TBarSeries source, double minTick = 0.125)
{
var indicator = new Tvi(minTick);
TSeries results = indicator.Update(source);
return (results, indicator);
}
}