diff options
| author | Ethan Werner <mail@ethanwerner.com> | 2026-07-01 09:42:39 +0400 |
|---|---|---|
| committer | Ethan Werner <mail@ethanwerner.com> | 2026-07-01 09:42:39 +0400 |
| commit | 07e18043145f3d91c8ea7ec3ad41b3c905585277 (patch) | |
| tree | 2bdeae46973f4bdfce263679a4008ac768011f28 /test/cmo.c | |
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
Diffstat (limited to 'test/cmo.c')
| -rw-r--r-- | test/cmo.c | 25 |
1 files changed, 25 insertions, 0 deletions
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 <math.h> +#include <stddef.h> +#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); +} |