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/cmo.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/cmo.c (limited to 'test/cmo.c') diff --git a/test/cmo.c b/test/cmo.c new file mode 100644 index 0000000..00fdb66 --- /dev/null +++ b/test/cmo.c @@ -0,0 +1,25 @@ +#include +#include +#include "ts.h" + +bool ts_test_cmo( void ) +{ + /* k=3, prices: 10, 12, 14, 13, 15, 16, 18, 17, 19, 20 */ + fp_t const x[] = { 10, 12, 14, 13, 15, 16, 18, 17, 19, 20 }; + + fp_t const * const inp[1] = { x }; + + /* i=1: diff=+2, i=2: diff=+2, i=3: diff=-1 */ + /* First window (i=1..3): up=2+2+0=4, down=0+0+1=1, CMO=100*(4-1)/(4+1)=60 */ + /* Slide: add i=4 diff=+2, remove i=1 diff=+2: up=4-2+2=4, down=1-0+0=1, CMO=60 */ + /* Slide: add i=5 diff=+1, remove i=2 diff=+2: up=4-2+1=3, down=1-0+0=1, CMO=100*(3-1)/(3+1)=50 */ + /* Slide: add i=6 diff=+2, remove i=3 diff=-1: up=3-0+2=5, down=1-1+0=0, CMO=100*(5-0)/(5+0)=100 */ + /* Slide: add i=7 diff=-1, remove i=4 diff=+2: up=5-2+0=3, down=0-0+1=1, CMO=100*(3-1)/(3+1)=50 */ + /* Slide: add i=8 diff=+2, remove i=5 diff=+1: up=3-1+2=4, down=1-0+0=1, CMO=100*(4-1)/(4+1)=60 */ + /* Slide: add i=9 diff=+1, remove i=6 diff=+2: up=4-2+1=3, down=1-0+0=1, CMO=50 */ + fp_t const e[] = { 60, 60, 50, 100, 50, 60, 50 }; + fp_t const * const exp[1] = { e }; + + uint_t k = 3; + return ts_test(ts_cmo, ts_cmo_offset, inp, exp, sizeof( x ) / sizeof( *x ), (ts_constant_t *)&k, &ts_cmo_p); +} -- cgit v1.3.1