From 07e18043145f3d91c8ea7ec3ad41b3c905585277 Mon Sep 17 00:00:00 2001 From: Ethan Werner Date: Wed, 1 Jul 2026 09:42:39 +0400 Subject: initial commit: ts time series analysis library v0.1.0 - 354 financial and mathematical time-series indicators - Uniform C11 API with consistent function signatures - 349 passing tests with -Werror - Static and shared library builds - pkg-config integration - Python bindings - Fuzzing and sanitizer support - Security hardening flags --- test/adx.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/adx.c (limited to 'test/adx.c') diff --git a/test/adx.c b/test/adx.c new file mode 100644 index 0000000..e8df67e --- /dev/null +++ b/test/adx.c @@ -0,0 +1,61 @@ +#include +#include +#include "ts.h" + +bool ts_test_adx( void ) +{ + uint_t n = 14; + uint_t k = 3; + + /* Monotonically rising data: +DM=1 each bar, -DM=0, TR=3 */ + fp_t *x[4]; + x[0] = malloc( n * sizeof( fp_t ) ); + x[1] = malloc( n * sizeof( fp_t ) ); + x[2] = malloc( n * sizeof( fp_t ) ); + x[3] = malloc( n * sizeof( fp_t ) ); + + for ( uint_t i = 0; i < n; ++i ) + { + x[0][i] = 10 + i; + x[1][i] = 12 + i; + x[2][i] = 9 + i; + x[3][i] = 11 + i; + } + + /* Expected: +DI=100/3, -DI=0, DX=100, ADX=100 (converged EMAs) */ + fp_t edp[] = { 100.0 / 3, 100.0 / 3, 100.0 / 3, 100.0 / 3, 100.0 / 3, 100.0 / 3, 100.0 / 3, 100.0 / 3, 100.0 / 3, 100.0 / 3 }; + fp_t edm[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + fp_t edx[] = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }; + fp_t ead[] = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }; + fp_t *e[4] = { edp, edm, edx, ead }; + + uint_t offset = k + 1; + uint_t y_n = n - offset; + + /* Allocate full-size output since the function writes to absolute + * indices [offset..n-1], not compacted [0..y_n-1] */ + fp_t *y[4]; + for ( uint_t i = 0; i < 4; ++i ) + y[i] = calloc( n, sizeof( fp_t ) ); + + uint8_t c[TS_CONSTANT_SIZE] = { 0 }; + *( uint_t * )c = k; + + ts_adx(y, ts_adx_p.n_outputs, (fp_t const * const *)x, ts_adx_p.n_inputs, n, (ts_constant_t const *)c); + + bool result = true; + for ( uint_t i = 0; i < 4; ++i ) + { + for ( uint_t j = 0; j < y_n; ++j ) + { + if ( fabs( y[i][offset + j] - e[i][j] ) > TS_TEST_EPSILON ) + result = false; + } + } + + for ( uint_t i = 0; i < 4; ++i ) + free( y[i] ); + free( x[0] ); free( x[1] ); free( x[2] ); free( x[3] ); + + return result; +} -- cgit v1.3.1