docs: remove C# Implementation Considerations sections, clean up temp scripts, reorganize test files

- Remove 'C# Implementation Considerations' sections from 34 indicator .md files
- Delete 29 temp PowerShell scripts (_fix_mojibake.ps1, _hex_scan.ps1, etc.)
- Move test files into tests/ subdirectories for consistent project structure
- Add trader-focused bullet points to indicator documentation
This commit is contained in:
Miha Kralj
2026-03-12 12:34:16 -07:00
parent 8937b0c0fa
commit 060649192f
1149 changed files with 1780 additions and 3316 deletions
@@ -0,0 +1,210 @@
using TradingPlatform.BusinessLayer;
namespace QuanTAlib.Tests;
public class DecayIndicatorTests
{
[Fact]
public void DecayIndicator_Constructor_SetsDefaults()
{
var indicator = new DecayIndicator();
Assert.Equal(5, indicator.Period);
Assert.Equal(SourceType.Close, indicator.Source);
Assert.True(indicator.ShowColdValues);
Assert.Equal("DECAY - Linear Decay", indicator.Name);
Assert.False(indicator.SeparateWindow);
Assert.True(indicator.OnBackGround);
}
[Fact]
public void DecayIndicator_MinHistoryDepths_EqualsZero()
{
var indicator = new DecayIndicator { Period = 20 };
Assert.Equal(0, DecayIndicator.MinHistoryDepths);
Assert.Equal(0, ((IWatchlistIndicator)indicator).MinHistoryDepths);
}
[Fact]
public void DecayIndicator_ShortName_IncludesPeriodAndSource()
{
var indicator = new DecayIndicator { Period = 15 };
Assert.Contains("DECAY", indicator.ShortName, StringComparison.Ordinal);
Assert.Contains("15", indicator.ShortName, StringComparison.Ordinal);
}
[Fact]
public void DecayIndicator_Initialize_CreatesLineSeries()
{
var indicator = new DecayIndicator { Period = 5 };
indicator.Initialize();
Assert.Single(indicator.LinesSeries);
}
[Fact]
public void DecayIndicator_ProcessUpdate_HistoricalBar_ComputesValue()
{
var indicator = new DecayIndicator { Period = 5 };
indicator.Initialize();
var now = DateTime.UtcNow;
indicator.HistoricalData.AddBar(now, 100, 105, 95, 102);
var args = new UpdateArgs(UpdateReason.HistoricalBar);
indicator.ProcessUpdate(args);
Assert.Equal(1, indicator.LinesSeries[0].Count);
Assert.True(double.IsFinite(indicator.LinesSeries[0].GetValue(0)));
}
[Fact]
public void DecayIndicator_ProcessUpdate_NewBar_ComputesValue()
{
var indicator = new DecayIndicator { Period = 5 };
indicator.Initialize();
var now = DateTime.UtcNow;
indicator.HistoricalData.AddBar(now, 100, 105, 95, 102);
indicator.HistoricalData.AddBar(now.AddMinutes(1), 102, 108, 100, 106);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.NewBar));
Assert.Equal(2, indicator.LinesSeries[0].Count);
}
[Fact]
public void DecayIndicator_ProcessUpdate_NewTick_ProcessesWithoutError()
{
var indicator = new DecayIndicator { Period = 5 };
indicator.Initialize();
var now = DateTime.UtcNow;
indicator.HistoricalData.AddBar(now, 100, 105, 95, 102);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.NewTick));
Assert.Equal(2, indicator.LinesSeries[0].Count);
}
[Fact]
public void DecayIndicator_MultipleUpdates_ProducesCorrectSequence()
{
var indicator = new DecayIndicator { Period = 5 };
indicator.Initialize();
var now = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
indicator.HistoricalData.AddBar(
now.AddMinutes(i),
100 + (i * 2),
105 + (i * 2),
95 + (i * 2),
102 + (i * 2));
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
Assert.Equal(20, indicator.LinesSeries[0].Count);
for (int i = 0; i < 20; i++)
{
Assert.True(double.IsFinite(indicator.LinesSeries[0].GetValue(i)));
}
}
[Fact]
public void DecayIndicator_DifferentSourceTypes_Work()
{
var sources = new[] { SourceType.Open, SourceType.High, SourceType.Low, SourceType.Close, SourceType.HL2, SourceType.HLC3 };
foreach (var source in sources)
{
var indicator = new DecayIndicator { Period = 5, Source = source };
indicator.Initialize();
var now = DateTime.UtcNow;
indicator.HistoricalData.AddBar(now, 100, 110, 90, 105);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
Assert.True(double.IsFinite(indicator.LinesSeries[0].GetValue(0)),
$"Source {source} should produce finite value");
}
}
[Fact]
public void DecayIndicator_Period_CanBeChanged()
{
var indicator = new DecayIndicator { Period = 10 };
Assert.Equal(10, indicator.Period);
indicator.Period = 20;
Assert.Equal(20, indicator.Period);
Assert.Equal(0, DecayIndicator.MinHistoryDepths);
}
[Fact]
public void DecayIndicator_Uptrend_OutputFollowsPrice()
{
var indicator = new DecayIndicator { Period = 5 };
indicator.Initialize();
var now = DateTime.UtcNow;
for (int i = 0; i < 10; i++)
{
double price = 100 + (i * 5);
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
// In uptrend, decay output should equal close price (input > decayed)
double lastValue = indicator.LinesSeries[0].GetValue(0);
Assert.Equal(145, lastValue, 1); // last close = 100 + 9*5 = 145
}
[Fact]
public void DecayIndicator_FlatPrices_OutputEqualsInput()
{
var indicator = new DecayIndicator { Period = 5 };
indicator.Initialize();
var now = DateTime.UtcNow;
for (int i = 0; i < 5; i++)
{
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100, 105, 95, 100);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
double lastValue = indicator.LinesSeries[0].GetValue(0);
Assert.Equal(100, lastValue, 1);
}
[Fact]
public void DecayIndicator_DifferentPeriods_Work()
{
var periods = new[] { 1, 5, 10, 20 };
foreach (var period in periods)
{
var indicator = new DecayIndicator { Period = period };
indicator.Initialize();
var now = DateTime.UtcNow;
for (int i = 0; i < 10; i++)
{
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 102 + i, 98 + i, 101 + i);
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
}
Assert.Equal(10, indicator.LinesSeries[0].Count);
}
}
}
+427
View File
@@ -0,0 +1,427 @@
using Xunit;
namespace QuanTAlib.Tests;
public class DecayTests
{
private readonly TSeries _gbm;
private const int TestPeriod = 5;
private const int DataPoints = 100;
public DecayTests()
{
var gbm = new GBM(startPrice: 100, mu: 0.0, sigma: 0.5, seed: 42);
var bars = gbm.Fetch(DataPoints, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
_gbm = bars.Close;
}
#region Constructor Tests
[Fact]
public void Constructor_WithValidPeriod_SetsProperties()
{
var decay = new Decay(TestPeriod);
Assert.Equal($"Decay({TestPeriod})", decay.Name);
Assert.Equal(1, decay.WarmupPeriod);
}
[Fact]
public void Constructor_WithZeroPeriod_ThrowsArgumentException()
{
var ex = Assert.Throws<ArgumentException>(() => new Decay(0));
Assert.Equal("period", ex.ParamName);
}
[Fact]
public void Constructor_WithNegativePeriod_ThrowsArgumentException()
{
var ex = Assert.Throws<ArgumentException>(() => new Decay(-1));
Assert.Equal("period", ex.ParamName);
}
[Fact]
public void Constructor_WithSource_SubscribesToEvents()
{
var source = new TSeries(DataPoints);
var decay = new Decay(source, TestPeriod);
Assert.NotNull(decay);
}
#endregion
#region Basic Calculation Tests
[Fact]
public void Update_FirstBar_ReturnsInputValue()
{
var decay = new Decay(TestPeriod);
var tv = decay.Update(new TValue(DateTime.UtcNow, 100.0));
Assert.Equal(100.0, tv.Value);
}
[Fact]
public void Update_DecayingValues_OutputDecaysLinearly()
{
var decay = new Decay(5); // scale = 0.2
var time = DateTime.UtcNow;
// First bar at 1.0
decay.Update(new TValue(time, 1.0), true);
// Next bars at 0.0 — output should decay by 0.2 per bar
var tv1 = decay.Update(new TValue(time.AddSeconds(1), 0.0), true);
Assert.Equal(0.8, tv1.Value, 10); // 1.0 - 0.2
var tv2 = decay.Update(new TValue(time.AddSeconds(2), 0.0), true);
Assert.Equal(0.6, tv2.Value, 10); // 0.8 - 0.2
var tv3 = decay.Update(new TValue(time.AddSeconds(3), 0.0), true);
Assert.Equal(0.4, tv3.Value, 10); // 0.6 - 0.2
}
[Fact]
public void Update_RisingInput_FollowsInput()
{
var decay = new Decay(5);
var time = DateTime.UtcNow;
decay.Update(new TValue(time, 100.0), true);
var tv = decay.Update(new TValue(time.AddSeconds(1), 105.0), true);
Assert.Equal(105.0, tv.Value, 10); // input > decayed, so follows input
}
[Fact]
public void Last_IsAccessible()
{
var decay = new Decay(TestPeriod);
decay.Update(new TValue(DateTime.UtcNow, 100.0));
Assert.Equal(100.0, decay.Last.Value, 10);
}
[Fact]
public void IsHot_ReturnsFalseBeforeFirstBar()
{
var decay = new Decay(TestPeriod);
Assert.False(decay.IsHot);
}
[Fact]
public void IsHot_ReturnsTrueAfterFirstBar()
{
var decay = new Decay(TestPeriod);
decay.Update(new TValue(DateTime.UtcNow, 100.0));
Assert.True(decay.IsHot);
}
[Fact]
public void Name_IsAccessible()
{
var decay = new Decay(TestPeriod);
Assert.Equal($"Decay({TestPeriod})", decay.Name);
}
#endregion
#region State Management Tests
[Fact]
public void Update_WithIsNewTrue_AdvancesState()
{
var decay = new Decay(TestPeriod);
var time = DateTime.UtcNow;
decay.Update(new TValue(time, 100.0), true);
decay.Update(new TValue(time.AddSeconds(1), 105.0), true);
decay.Update(new TValue(time.AddSeconds(2), 110.0), true);
Assert.NotEqual(default, decay.Last);
}
[Fact]
public void Update_WithIsNewFalse_UpdatesCurrentState()
{
var decay = new Decay(5);
var time = DateTime.UtcNow;
decay.Update(new TValue(time, 1.0), true);
var first = decay.Update(new TValue(time.AddSeconds(1), 0.0), true);
// Correct same bar with different value
var corrected = decay.Update(new TValue(time.AddSeconds(1), 0.5), false);
// first: max(0.0, 1.0-0.2)=0.8
Assert.Equal(0.8, first.Value, 10);
// corrected: max(0.5, 1.0-0.2)=0.8
Assert.Equal(0.8, corrected.Value, 10);
}
[Fact]
public void Update_IterativeCorrections_RestoresPreviousState()
{
var decay = new Decay(5);
var time = DateTime.UtcNow;
decay.Update(new TValue(time, 1.0), true);
var baseline = decay.Update(new TValue(time.AddSeconds(1), 0.5), true);
// Make several corrections
decay.Update(new TValue(time.AddSeconds(1), 0.9), false);
decay.Update(new TValue(time.AddSeconds(1), 0.1), false);
var restored = decay.Update(new TValue(time.AddSeconds(1), 0.5), false);
Assert.Equal(baseline.Value, restored.Value, 10);
}
[Fact]
public void Reset_ClearsStateAndLastValidTracking()
{
var decay = new Decay(TestPeriod);
var time = DateTime.UtcNow;
for (int i = 0; i < 10; i++)
{
decay.Update(new TValue(time.AddSeconds(i), 100.0 + i));
}
decay.Reset();
Assert.Equal(default, decay.Last);
Assert.False(decay.IsHot);
}
#endregion
#region Robustness Tests
[Fact]
public void Update_WithNaN_UsesLastValidValue()
{
var decay = new Decay(5);
var time = DateTime.UtcNow;
decay.Update(new TValue(time, 1.0), true);
var afterNaN = decay.Update(new TValue(time.AddSeconds(1), double.NaN), true);
Assert.True(double.IsFinite(afterNaN.Value));
// NaN uses last valid (1.0), so max(1.0, 1.0-0.2)=1.0
Assert.Equal(1.0, afterNaN.Value, 10);
}
[Fact]
public void Update_WithInfinity_UsesLastValidValue()
{
var decay = new Decay(5);
var time = DateTime.UtcNow;
decay.Update(new TValue(time, 1.0), true);
var afterInf = decay.Update(new TValue(time.AddSeconds(1), double.PositiveInfinity), true);
Assert.True(double.IsFinite(afterInf.Value));
}
[Fact]
public void Update_BatchNaN_HandlesSafely()
{
var decay = new Decay(TestPeriod);
var time = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
var value = i % 3 == 0 ? double.NaN : 100.0 + i;
var tv = decay.Update(new TValue(time.AddSeconds(i), value), true);
Assert.True(double.IsFinite(tv.Value));
}
}
#endregion
#region Consistency Tests (All 4 modes must match)
[Fact]
public void AllModes_ProduceSameResults()
{
// Mode 1: Batch via TSeries
var batchResult = Decay.Batch(_gbm, TestPeriod);
// Mode 2: Streaming
var streamingDecay = new Decay(TestPeriod);
var streamingResult = new TSeries(DataPoints);
for (int i = 0; i < _gbm.Count; i++)
{
var tv = streamingDecay.Update(new TValue(_gbm[i].Time, _gbm[i].Value), true);
streamingResult.Add(tv, true);
}
// Mode 3: Span-based
Span<double> spanOutput = stackalloc double[DataPoints];
Decay.Batch(_gbm.Values, spanOutput, TestPeriod);
// Mode 4: Event-driven
var eventDecay = new Decay(TestPeriod);
var eventResult = new TSeries(DataPoints);
eventDecay.Pub += (object? _, in TValueEventArgs e) => eventResult.Add(e.Value, e.IsNew);
for (int i = 0; i < _gbm.Count; i++)
{
eventDecay.Update(new TValue(_gbm[i].Time, _gbm[i].Value), true);
}
int compareCount = Math.Min(100, DataPoints);
for (int i = DataPoints - compareCount; i < DataPoints; i++)
{
Assert.Equal(batchResult[i].Value, streamingResult[i].Value, 10);
Assert.Equal(batchResult[i].Value, spanOutput[i], 10);
Assert.Equal(batchResult[i].Value, eventResult[i].Value, 10);
}
}
#endregion
#region Span API Tests
[Fact]
public void Calculate_Span_ValidatesEmptySource()
{
var ex = Assert.Throws<ArgumentException>(() =>
{
ReadOnlySpan<double> empty = [];
Span<double> output = stackalloc double[1];
Decay.Batch(empty, output, TestPeriod);
});
Assert.Equal("source", ex.ParamName);
}
[Fact]
public void Calculate_Span_ValidatesOutputLength()
{
var ex = Assert.Throws<ArgumentException>(() =>
{
ReadOnlySpan<double> source = stackalloc double[] { 1, 2, 3, 4, 5 };
Span<double> output = stackalloc double[3]; // too short
Decay.Batch(source, output, TestPeriod);
});
Assert.Equal("output", ex.ParamName);
}
[Fact]
public void Calculate_Span_ValidatesPeriod()
{
var ex = Assert.Throws<ArgumentException>(() =>
{
ReadOnlySpan<double> source = stackalloc double[] { 1, 2, 3, 4, 5 };
Span<double> output = stackalloc double[5];
Decay.Batch(source, output, 0);
});
Assert.Equal("period", ex.ParamName);
}
[Fact]
public void Calculate_Span_MatchesTSeries()
{
var batchResult = Decay.Batch(_gbm, TestPeriod);
Span<double> spanOutput = stackalloc double[DataPoints];
Decay.Batch(_gbm.Values, spanOutput, TestPeriod);
for (int i = 0; i < DataPoints; i++)
{
Assert.Equal(batchResult[i].Value, spanOutput[i], 10);
}
}
[Fact]
public void Calculate_Span_LargeData_NoStackOverflow()
{
int largeSize = 10000;
double[] source = new double[largeSize];
double[] output = new double[largeSize];
for (int i = 0; i < largeSize; i++)
{
source[i] = 100.0 + (i * 0.1);
}
Decay.Batch(source, output, TestPeriod);
Assert.Equal(largeSize, output.Length);
}
#endregion
#region Chainability Tests
[Fact]
public void Pub_FiresOnUpdate()
{
var decay = new Decay(TestPeriod);
bool eventFired = false;
decay.Pub += (object? _, in TValueEventArgs e) => eventFired = true;
decay.Update(new TValue(DateTime.UtcNow, 100.0));
Assert.True(eventFired);
}
[Fact]
public void EventBasedChaining_Works()
{
var source = new TSeries(10);
var decay = new Decay(source, 2);
var results = new List<double>();
decay.Pub += (object? _, in TValueEventArgs e) => results.Add(e.Value.Value);
for (int i = 0; i < 10; i++)
{
source.Add(new TValue(DateTime.UtcNow.AddSeconds(i), 100.0 + i), true);
}
Assert.Equal(10, results.Count);
}
#endregion
#region Decay-Specific Tests
[Fact]
public void Decay_Period1_DecaysByOneEachBar()
{
var decay = new Decay(1); // scale = 1.0
var time = DateTime.UtcNow;
decay.Update(new TValue(time, 5.0), true);
var tv = decay.Update(new TValue(time.AddSeconds(1), 0.0), true);
// max(0.0, 5.0-1.0) = 4.0
Assert.Equal(4.0, tv.Value, 10);
}
[Fact]
public void Decay_ConstantInput_OutputEqualsInput()
{
var decay = new Decay(5);
var time = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
var tv = decay.Update(new TValue(time.AddSeconds(i), 100.0), true);
Assert.Equal(100.0, tv.Value, 10);
}
}
[Fact]
public void Decay_OutputNeverBelowInput()
{
var decay = new Decay(10);
var time = DateTime.UtcNow;
var rng = new Random(42);
for (int i = 0; i < 100; i++)
{
double input = rng.NextDouble() * 200;
var tv = decay.Update(new TValue(time.AddSeconds(i), input), true);
Assert.True(tv.Value >= input || Math.Abs(tv.Value - input) < 1e-10,
$"Output {tv.Value} should be >= input {input}");
}
}
#endregion
}
@@ -0,0 +1,230 @@
using Xunit;
using Xunit.Abstractions;
namespace QuanTAlib.Tests;
/// <summary>
/// Validation tests for DECAY (Linear Decay) against the Tulip Indicators algorithm.
/// The Tulip .NET binding does not expose decay/edecay directly, so validation
/// uses manual computation of the Tulip ti_decay algorithm:
/// output[0] = input[0]
/// output[i] = max(input[i], output[i-1] - 1.0/period)
/// </summary>
public sealed class DecayValidationTests(ITestOutputHelper output) : IDisposable
{
private readonly ValidationTestData _testData = new();
private readonly ITestOutputHelper _output = output;
private bool _disposed;
private const int TestPeriod = 5;
private const double TulipTolerance = 1e-9;
public void Dispose()
{
Dispose(disposing: true);
}
private void Dispose(bool disposing)
{
if (_disposed) { return; }
_disposed = true;
if (disposing) { _testData?.Dispose(); }
}
/// <summary>
/// Reference implementation of Tulip ti_decay for validation.
/// </summary>
private static double[] TulipDecay(double[] input, int period)
{
double[] output = new double[input.Length];
double scale = 1.0 / period;
output[0] = input[0];
for (int i = 1; i < input.Length; i++)
{
double d = output[i - 1] - scale;
output[i] = input[i] > d ? input[i] : d;
}
return output;
}
#region Tulip Algorithm Validation
[Fact]
public void Decay_MatchesTulipDecay_Batch()
{
double[] input = _testData.RawData.ToArray();
var quantResult = Decay.Batch(_testData.Data, TestPeriod);
double[] tulipResult = TulipDecay(input, TestPeriod);
int count = quantResult.Count;
int start = Math.Max(0, count - ValidationHelper.DefaultVerificationCount);
for (int i = start; i < count; i++)
{
Assert.True(
Math.Abs(quantResult[i].Value - tulipResult[i]) <= TulipTolerance,
$"Mismatch at index {i}: QuanTAlib={quantResult[i].Value:G17}, Tulip={tulipResult[i]:G17}");
}
_output.WriteLine("Decay Batch validated successfully against Tulip decay algorithm");
}
[Fact]
public void Decay_MatchesTulipDecay_Streaming()
{
double[] input = _testData.RawData.ToArray();
var decay = new Decay(TestPeriod);
var streamingResults = new List<double>();
foreach (var item in _testData.Data)
{
streamingResults.Add(decay.Update(item).Value);
}
double[] tulipResult = TulipDecay(input, TestPeriod);
int count = streamingResults.Count;
int start = Math.Max(0, count - ValidationHelper.DefaultVerificationCount);
for (int i = start; i < count; i++)
{
Assert.True(
Math.Abs(streamingResults[i] - tulipResult[i]) <= TulipTolerance,
$"Mismatch at index {i}: QuanTAlib={streamingResults[i]:G17}, Tulip={tulipResult[i]:G17}");
}
_output.WriteLine("Decay Streaming validated successfully against Tulip decay algorithm");
}
[Fact]
public void Decay_MatchesTulipDecay_Span()
{
double[] input = _testData.RawData.ToArray();
var quantOutput = new double[input.Length];
Decay.Batch(new ReadOnlySpan<double>(input), quantOutput, TestPeriod);
double[] tulipResult = TulipDecay(input, TestPeriod);
int count = quantOutput.Length;
int start = Math.Max(0, count - ValidationHelper.DefaultVerificationCount);
for (int i = start; i < count; i++)
{
Assert.True(
Math.Abs(quantOutput[i] - tulipResult[i]) <= TulipTolerance,
$"Mismatch at index {i}: QuanTAlib={quantOutput[i]:G17}, Tulip={tulipResult[i]:G17}");
}
_output.WriteLine("Decay Span validated successfully against Tulip decay algorithm");
}
#endregion
#region Different Periods
[Theory]
[InlineData(1)]
[InlineData(5)]
[InlineData(10)]
[InlineData(20)]
[InlineData(50)]
public void Decay_MatchesTulipDecay_DifferentPeriods(int period)
{
double[] input = _testData.RawData.ToArray();
var quantResult = Decay.Batch(_testData.Data, period);
double[] tulipResult = TulipDecay(input, period);
int count = quantResult.Count;
int start = Math.Max(0, count - ValidationHelper.DefaultVerificationCount);
for (int i = start; i < count; i++)
{
Assert.True(
Math.Abs(quantResult[i].Value - tulipResult[i]) <= TulipTolerance,
$"Period={period}, Mismatch at index {i}: QuanTAlib={quantResult[i].Value:G17}, Tulip={tulipResult[i]:G17}");
}
}
#endregion
#region Edge Cases
[Fact]
public void Decay_HandlesConstantValues()
{
var constantData = new TSeries(100);
for (int i = 0; i < 100; i++)
{
constantData.Add(new TValue(DateTime.UtcNow.AddSeconds(i), 100.0), true);
}
var result = Decay.Batch(constantData, TestPeriod);
// Constant input: output always equals input since input >= decayed
for (int i = 0; i < 100; i++)
{
Assert.Equal(100.0, result[i].Value, TulipTolerance);
}
}
[Fact]
public void Decay_HandlesLinearlyDecreasing()
{
double[] input = new double[20];
for (int i = 0; i < 20; i++)
{
input[i] = 100.0 - i;
}
var quantOutput = new double[20];
Decay.Batch(input, quantOutput, TestPeriod);
double[] tulipResult = TulipDecay(input, TestPeriod);
for (int i = 0; i < 20; i++)
{
Assert.Equal(tulipResult[i], quantOutput[i], TulipTolerance);
}
}
[Fact]
public void Batch_MatchesStreaming_IdenticalResults()
{
var batchResult = Decay.Batch(_testData.Data, TestPeriod);
var decay = new Decay(TestPeriod);
var streamingResults = new List<double>();
foreach (var item in _testData.Data)
{
streamingResults.Add(decay.Update(item).Value);
}
int count = _testData.Data.Count;
int start = Math.Max(0, count - ValidationHelper.DefaultVerificationCount);
for (int i = start; i < count; i++)
{
Assert.Equal(batchResult[i].Value, streamingResults[i], ValidationHelper.DefaultTolerance);
}
_output.WriteLine("Decay Batch vs Streaming consistency validated");
}
[Fact]
public void Decay_OutputAlwaysGreaterOrEqualInput()
{
double[] input = _testData.RawData.ToArray();
var quantOutput = new double[input.Length];
Decay.Batch(input, quantOutput, TestPeriod);
for (int i = 0; i < input.Length; i++)
{
Assert.True(quantOutput[i] >= input[i] - 1e-15,
$"Output {quantOutput[i]} must be >= input {input[i]} at index {i}");
}
}
#endregion
}