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/macd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/macd.c (limited to 'test/macd.c') diff --git a/test/macd.c b/test/macd.c new file mode 100644 index 0000000..34d6365 --- /dev/null +++ b/test/macd.c @@ -0,0 +1,25 @@ +#include +#include +#include "ts.h" + +bool ts_test_macd( void ) +{ + fp_t const x[] = { -10, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10 }; + + fp_t const * const inp[1] = { x }; + + /* fast=3, slow=5, signal=2 */ + /* Standard EMA: alpha = 2/(k+1) */ + /* fast_a=2/4=0.5, slow_a=2/6=0.333, sig_a=2/3=0.667 */ + + fp_t const em[4] = { 1.91968879, 2.10010502, 2.22689293, 2.31467341 }; + fp_t const es[4] = { 1.91968879, 2.03996628, 2.16458405, 2.26464362 }; + fp_t const eh[4] = { 0.00000000, 0.06013875, 0.06230888, 0.05002979 }; + + fp_t const * const exp[3] = { em, es, eh }; + + typedef struct { fp_t fast; fp_t slow; fp_t signal; } c_t; + c_t c = { .fast = 3, .slow = 5, .signal = 2 }; + + return ts_test(ts_macd, ts_macd_offset, inp, exp, sizeof( x ) / sizeof( *x ), (ts_constant_t *)&c, &ts_macd_p); +} -- cgit v1.3.1