mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 04:28:04 +00:00
normalization of methods
This commit is contained in:
@@ -92,7 +92,7 @@ public class AdoscTests
|
||||
}
|
||||
|
||||
var spanOutput = new double[_bars.Count];
|
||||
Adosc.Calculate(_bars.High.Values, _bars.Low.Values, _bars.Close.Values, _bars.Volume.Values, spanOutput, 3, 10);
|
||||
Adosc.Batch(_bars.High.Values, _bars.Low.Values, _bars.Close.Values, _bars.Volume.Values, spanOutput, 3, 10);
|
||||
|
||||
for (int i = 0; i < _bars.Count; i++)
|
||||
{
|
||||
@@ -176,7 +176,7 @@ public class AdoscTests
|
||||
double[] volume = [1000, 1100, 1200, 1300, 1400];
|
||||
double[] output = new double[5];
|
||||
|
||||
Adosc.Calculate(high, low, close, volume, output, 3, 5);
|
||||
Adosc.Batch(high, low, close, volume, output, 3, 5);
|
||||
|
||||
// Verify output is finite
|
||||
for (int i = 0; i < output.Length; i++)
|
||||
@@ -191,7 +191,7 @@ public class AdoscTests
|
||||
var batchResult = Adosc.Batch(_bars, 3, 10);
|
||||
|
||||
var spanOutput = new double[_bars.Count];
|
||||
Adosc.Calculate(_bars.High.Values, _bars.Low.Values, _bars.Close.Values, _bars.Volume.Values, spanOutput, 3, 10);
|
||||
Adosc.Batch(_bars.High.Values, _bars.Low.Values, _bars.Close.Values, _bars.Volume.Values, spanOutput, 3, 10);
|
||||
|
||||
for (int i = 0; i < _bars.Count; i++)
|
||||
{
|
||||
|
||||
@@ -66,7 +66,7 @@ public sealed class AdoscValidationTests : IDisposable
|
||||
|
||||
// 3. Span Mode
|
||||
double[] spanOutput = new double[close.Length];
|
||||
Adosc.Calculate(high, low, close, volume, spanOutput, fastPeriod, slowPeriod);
|
||||
Adosc.Batch(high, low, close, volume, spanOutput, fastPeriod, slowPeriod);
|
||||
ValidationHelper.VerifyData(spanOutput, output, outRange, lookback: slowPeriod - 1, tolerance: ValidationHelper.TalibTolerance);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public sealed class AdoscValidationTests : IDisposable
|
||||
|
||||
// 3. Span Mode
|
||||
double[] spanOutput = new double[close.Length];
|
||||
Adosc.Calculate(high, low, close, volume, spanOutput, fastPeriod, slowPeriod);
|
||||
Adosc.Batch(high, low, close, volume, spanOutput, fastPeriod, slowPeriod);
|
||||
ValidationHelper.VerifyData(spanOutput, output, lookback: start, tolerance: ValidationHelper.TulipTolerance);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public sealed class AdoscValidationTests : IDisposable
|
||||
double[] close = _testData.Bars.Close.Values.ToArray();
|
||||
double[] volume = _testData.Bars.Volume.Values.ToArray();
|
||||
double[] spanOutput = new double[close.Length];
|
||||
Adosc.Calculate(high, low, close, volume, spanOutput, fastPeriod, slowPeriod);
|
||||
Adosc.Batch(high, low, close, volume, spanOutput, fastPeriod, slowPeriod);
|
||||
ValidationHelper.VerifyData<ChaikinOscResult>(spanOutput, skenderResults, (x) => x.Oscillator, tolerance: ValidationHelper.SkenderTolerance);
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public sealed class AdoscValidationTests : IDisposable
|
||||
double[] close = _testData.Bars.Close.Values.ToArray();
|
||||
double[] volume = _testData.Bars.Volume.Values.ToArray();
|
||||
double[] spanOutput = new double[close.Length];
|
||||
Adosc.Calculate(high, low, close, volume, spanOutput, fastPeriod, slowPeriod);
|
||||
Adosc.Batch(high, low, close, volume, spanOutput, fastPeriod, slowPeriod);
|
||||
ValidationHelper.VerifyData(spanOutput, output, lookback: 0, tolerance: ValidationHelper.OoplesTolerance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,9 @@ public sealed class Adosc : ITValuePublisher
|
||||
return new TSeries(t, v);
|
||||
}
|
||||
|
||||
// EMA compensator threshold (same as in Ema.cs)
|
||||
private const double COMPENSATOR_THRESHOLD = 1e-10;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates ADOSC for the entire series using a new instance.
|
||||
/// </summary>
|
||||
@@ -149,9 +152,6 @@ public sealed class Adosc : ITValuePublisher
|
||||
return adosc.Update(source);
|
||||
}
|
||||
|
||||
// EMA compensator threshold (same as in Ema.cs)
|
||||
private const double COMPENSATOR_THRESHOLD = 1e-10;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates ADOSC for the entire span using a single-pass algorithm.
|
||||
/// Zero allocation for maximum performance.
|
||||
@@ -165,7 +165,7 @@ public sealed class Adosc : ITValuePublisher
|
||||
/// <param name="fastPeriod">Fast EMA period (default 3)</param>
|
||||
/// <param name="slowPeriod">Slow EMA period (default 10)</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Calculate(ReadOnlySpan<double> high, ReadOnlySpan<double> low, ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output, int fastPeriod = 3, int slowPeriod = 10)
|
||||
public static void Batch(ReadOnlySpan<double> high, ReadOnlySpan<double> low, ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output, int fastPeriod = 3, int slowPeriod = 10)
|
||||
{
|
||||
if (high.Length != low.Length || high.Length != close.Length ||
|
||||
high.Length != volume.Length || high.Length != output.Length)
|
||||
@@ -276,4 +276,11 @@ public sealed class Adosc : ITValuePublisher
|
||||
output[i] = fastValue - slowValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Adosc Indicator) Calculate(TBarSeries source, int fastPeriod = 3, int slowPeriod = 10)
|
||||
{
|
||||
var indicator = new Adosc(fastPeriod, slowPeriod);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user