Files
QuanTAlib/lib/cycles/ht_phasor/HtPhasor.Validation.Tests.cs
T
Miha Kralj 26280ce80b Add Choppiness Index (CHOP) implementation and tests
- Implemented ChopIndicator for Quantower with configurable period and cold value display.
- Created Chop class for calculating the Choppiness Index with detailed documentation.
- Added comprehensive unit tests for Chop functionality, covering various market conditions and edge cases.
- Developed markdown documentation for CHOP, detailing its historical context, mathematical foundation, and usage examples.
- Established a remediation plan for channel indicators documentation, identifying gaps and prioritizing updates.
2026-02-05 19:42:49 -08:00

55 lines
1.8 KiB
C#

using QuanTAlib;
using TALib;
using Xunit;
namespace QuanTAlib.Tests;
public sealed class HtPhasorValidationTests
{
[Fact]
public void HtPhasor_Matches_TALib_InPhase_Quadrature()
{
// Arrange
const int seed = 42;
const int length = 600;
var gbm = new GBM(startPrice: 100.0, mu: 0.0, sigma: 0.2, seed: seed);
long[] times = new long[length];
double[] prices = new double[length];
for (int i = 0; i < length; i++)
{
bool isNew = true;
var bar = gbm.Next(ref isNew);
times[i] = bar.Time;
prices[i] = bar.Close;
}
// Act
double[] talibInPhase = new double[length];
double[] talibQuadrature = new double[length];
var rc = TALib.Functions.HtPhasor(prices, 0..^0, talibInPhase, talibQuadrature, out var outRange);
Assert.Equal(TALib.Core.RetCode.Success, rc);
var qt = new HtPhasor();
double[] qInPhase = new double[length];
double[] qQuadrature = new double[length];
for (int i = 0; i < length; i++)
{
var result = qt.Update(new TValue(times[i], prices[i]));
qInPhase[i] = result.Value;
qQuadrature[i] = qt.Quadrature;
}
// Assert
// TALib outputs start at outBegIdx; compare overlapping region
int start = outRange.Start.Value;
int outLength = outRange.End.Value - outRange.Start.Value; // End is exclusive
const double tol = 1e-9;
for (int i = 0; i < outLength; i++)
{
int srcIdx = start + i;
Assert.InRange(qInPhase[srcIdx], talibInPhase[i] - tol, talibInPhase[i] + tol);
Assert.InRange(qQuadrature[srcIdx], talibQuadrature[i] - tol, talibQuadrature[i] + tol);
}
}
}