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/apo.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/apo.c')
| -rw-r--r-- | test/apo.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/apo.c b/test/apo.c new file mode 100644 index 0000000..7af9f5e --- /dev/null +++ b/test/apo.c @@ -0,0 +1,41 @@ +#include <math.h> +#include <stddef.h> +#include "ts.h" + +bool ts_test_apo( void ) +{ + fp_t const x[] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; + + fp_t const * const inp[1] = { x }; + + /* fast=3, slow=5: fast_a=1/3, slow_a=1/5 */ + /* fast EMA: 10, 10.333, 10.889, 11.593, 12.395, 13.263, 14.176, 15.117, 16.078, 17.052 */ + /* slow EMA: 10, 10.2, 10.44, 10.752, 11.131, 11.575, 12.085, 12.666, 13.326, 14.062 */ + /* APO: 0.1333, 0.4481, 0.8405, 1.2634, 1.6876, 2.0930, 2.4545, 2.7521, 2.9901 */ + + fp_t fast_e = 10, slow_e = 10; + fp_t fast_a = 1.0 / 3, slow_a = 1.0 / 5; + fp_t e[6] = { 0 }; + + uint_t offset = 4; + for( uint_t i = 1; i <= offset; ++i ) + { + fast_e = fast_e + fast_a * ( x[i] - fast_e ); + slow_e = slow_e + slow_a * ( x[i] - slow_e ); + } + e[0] = fast_e - slow_e; + + for( uint_t i = offset + 1; i < 10; ++i ) + { + fast_e = fast_e + fast_a * ( x[i] - fast_e ); + slow_e = slow_e + slow_a * ( x[i] - slow_e ); + e[i - offset] = fast_e - slow_e; + } + + fp_t const * const exp[1] = { e }; + + typedef struct { fp_t fast; fp_t slow; } c_t; + c_t c = { .fast = 3, .slow = 5 }; + + return ts_test(ts_apo, ts_apo_offset, inp, exp, sizeof( x ) / sizeof( *x ), (ts_constant_t *)&c, &ts_apo_p); +} |