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/oscillator_cross.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/oscillator_cross.c (limited to 'test/oscillator_cross.c') diff --git a/test/oscillator_cross.c b/test/oscillator_cross.c new file mode 100644 index 0000000..323718b --- /dev/null +++ b/test/oscillator_cross.c @@ -0,0 +1,40 @@ +#include +#include +#include "ts.h" + +bool ts_test_oscillator_cross( void ) +{ + /* Data that goes down then up, producing a clear crossover */ + fp_t const x[] = { 10, 9, 8, 7, 6, 5, 6, 7, 8, 9 }; + + fp_t const * const inp[1] = { x }; + + /* fast=2, slow=4 */ + fp_t fast_e = 10, slow_e = 10; + fp_t fast_a = 1.0 / 2, slow_a = 1.0 / 4; + fp_t e[6] = { 0 }; + + for( uint_t i = 1; i < 10; ++i ) + { + fp_t pf = fast_e, ps = slow_e; + fast_e = fast_e + fast_a * ( x[i] - fast_e ); + slow_e = slow_e + slow_a * ( x[i] - slow_e ); + + if( i >= 4 ) + { + if( fast_e > slow_e && pf <= ps ) + e[i - 4] = 1; + else if( fast_e < slow_e && pf >= ps ) + e[i - 4] = -1; + else + e[i - 4] = 0; + } + } + + fp_t const * const exp[1] = { e }; + + typedef struct { fp_t fast; fp_t slow; } c_t; + c_t c = { .fast = 2, .slow = 4 }; + + return ts_test(ts_oscillator_cross, ts_oscillator_cross_offset, inp, exp, sizeof( x ) / sizeof( *x ), (ts_constant_t *)&c, &ts_oscillator_cross_p); +} -- cgit v1.3.1