Refactor code formatting and improve consistency across various test files

- Removed unnecessary blank lines in multiple test files to enhance readability.
- Ensured consistent spacing and formatting in the `Trima`, `Usf`, `Vidya`, `Wma`, and `Atr` test classes.
- Updated comments for clarity and consistency in the `Atr` and `Adl` classes.
- Adjusted project files for better structure and maintainability.
This commit is contained in:
Miha Kralj
2025-12-28 17:44:08 -08:00
parent ad6eebf812
commit 13d7c1215d
169 changed files with 10815 additions and 10814 deletions
+5 -5
View File
@@ -25,7 +25,7 @@ public class StdDevTests
// Sample StdDev: Sqrt(4.571428...) = 2.1380899...
var data = new double[] { 2, 4, 4, 4, 5, 5, 7, 9 };
// Test Population StdDev
var popStd = new StdDev(8, isPopulation: true);
foreach (var val in data)
@@ -48,7 +48,7 @@ public class StdDevTests
{
int period = 5;
var stdDev = new StdDev(period);
for (int i = 0; i < period; i++)
{
Assert.False(stdDev.IsHot);
@@ -79,7 +79,7 @@ public class StdDevTests
int count = 1000;
var data = new double[count];
var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 123);
for (int i = 0; i < count; i++)
{
data[i] = gbm.Next().Close;
@@ -104,7 +104,7 @@ public class StdDevTests
Assert.Equal(iterativeResults[i], batchResults[i], precision: 6);
}
}
[Fact]
public void Update_TSeries_Matches_Iterative()
{
@@ -112,7 +112,7 @@ public class StdDevTests
int count = 1000;
var data = new TSeries();
var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 123);
for (int i = 0; i < count; i++)
{
var bar = gbm.Next();
@@ -27,7 +27,7 @@ public class StdDevValidationTests
var skenderList = skenderStdDev.ToList();
var quotes = _data.SkenderQuotes.ToList();
for (int i = 0; i < quotes.Count; i++)
{
var tValue = stdDev.Update(new TValue(quotes[i].Date, (double)quotes[i].Close));
@@ -46,7 +46,7 @@ public class StdDevValidationTests
// TA-Lib STDDEV uses Population Standard Deviation (N)
int period = 20;
var stdDev = new StdDev(period, isPopulation: true);
var quotes = _data.SkenderQuotes.ToList();
double[] input = quotes.Select(q => (double)q.Close).ToArray();
double[] output = new double[input.Length];
@@ -74,18 +74,18 @@ public class StdDevValidationTests
// Tulip STDDEV uses Population Standard Deviation (N)
int period = 20;
var stdDev = new StdDev(period, isPopulation: true);
var quotes = _data.SkenderQuotes.ToList();
double[] input = quotes.Select(q => (double)q.Close).ToArray();
// Tulip calculation
var stdDevInd = Tulip.Indicators.stddev;
double[][] inputs = { input };
double[] options = { period };
double[][] outputs = { new double[input.Length - stdDevInd.Start(options)] };
stdDevInd.Run(inputs, options, outputs);
double[] output = outputs[0];
int lookback = stdDevInd.Start(options);
@@ -107,7 +107,7 @@ public class StdDevValidationTests
int period = 20;
var stdDev = new StdDev(period, isPopulation: false);
var popStdDev = new StdDev(period, isPopulation: true);
var quotes = _data.SkenderQuotes.ToList();
double[] input = quotes.Select(q => (double)q.Close).ToArray();
@@ -121,7 +121,7 @@ public class StdDevValidationTests
var window = input[(i - period + 1)..(i + 1)];
double expected = Statistics.StandardDeviation(window);
double expectedPop = Statistics.PopulationStandardDeviation(window);
Assert.Equal(expected, val.Value, ValidationHelper.DefaultTolerance);
Assert.Equal(expectedPop, popVal.Value, ValidationHelper.DefaultTolerance);
}
+9 -9
View File
@@ -14,10 +14,10 @@ namespace QuanTAlib;
/// </summary>
/// <remarks>
/// Standard Deviation is the square root of Variance.
///
///
/// Formula:
/// StdDev = Sqrt(Variance)
///
///
/// This implementation wraps the optimized Variance indicator and applies a square root.
/// </remarks>
[SkipLocalsInit]
@@ -47,7 +47,7 @@ public sealed class StdDev : AbstractBase
public override TValue Update(TValue input, bool isNew = true)
{
TValue varResult = _variance.Update(input, isNew);
// Sqrt(Variance)
// Handle potential negative zero or extremely small negative noise from Variance
double val = varResult.Value;
@@ -73,12 +73,12 @@ public sealed class StdDev : AbstractBase
// 1. Calculate Variance
Variance.Batch(source.Values, vSpan, _period, _isPopulation);
// 2. Calculate Sqrt in-place
SqrtSpan(vSpan);
source.Times.CopyTo(tSpan);
// Prime the state
// We need to feed the last 'period' values into the _variance instance
// so that subsequent streaming updates work correctly.
@@ -122,7 +122,7 @@ public sealed class StdDev : AbstractBase
{
// 1. Calculate Variance
Variance.Batch(source, output, period, isPopulation);
// 2. Sqrt
SqrtSpan(output);
}
@@ -139,7 +139,7 @@ public sealed class StdDev : AbstractBase
const int VectorWidth = 8;
int simdEnd = len - (len % VectorWidth);
ref double dataRef = ref MemoryMarshal.GetReference(data);
for (; i < simdEnd; i += VectorWidth)
{
var v = Vector512.LoadUnsafe(ref Unsafe.Add(ref dataRef, i));
@@ -153,7 +153,7 @@ public sealed class StdDev : AbstractBase
const int VectorWidth = 4;
int simdEnd = len - (len % VectorWidth);
ref double dataRef = ref MemoryMarshal.GetReference(data);
for (; i < simdEnd; i += VectorWidth)
{
var v = Vector256.LoadUnsafe(ref Unsafe.Add(ref dataRef, i));
@@ -167,7 +167,7 @@ public sealed class StdDev : AbstractBase
const int VectorWidth = 2;
int simdEnd = len - (len % VectorWidth);
ref double dataRef = ref MemoryMarshal.GetReference(data);
for (; i < simdEnd; i += VectorWidth)
{
var v = Vector128.LoadUnsafe(ref Unsafe.Add(ref dataRef, i));