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 --- lib/alligator.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/alligator.c (limited to 'lib/alligator.c') diff --git a/lib/alligator.c b/lib/alligator.c new file mode 100644 index 0000000..81450b0 --- /dev/null +++ b/lib/alligator.c @@ -0,0 +1,70 @@ +// Alligator Indicator +// +// William Elder's Alligator uses three SMAs shifted forward in time: +// Jaw: SMA(13) shifted 8 bars +// Teeth: SMA(8) shifted 5 bars +// Lips: SMA(5) shifted 3 bars +// +// X_n - 1 +// Y_n - 3 +// C_n - 0 + +#include "ts.h" + + +ts_parameter_t const ts_alligator_p = { .n_inputs = 1, .n_outputs = 3, .n_constants = 0, .params_size = 0 }; + +uint_t ts_alligator_offset( ts_constant_t const *c ) +{ + ( void )c; + return ( 12 ); +} + +int ts_alligator( + fp_t * const *y, uint_t y_n, + fp_t const * const *x, uint_t x_n, + uint_t n, ts_constant_t const *c +) +{ + TS_PROLOGUE( ts_alligator_p ); + (void)c; + if( n == 0 ) return -1; + /* Jaw: SMA(13) shifted 8 positions */ + /* Teeth: SMA(8) shifted 5 positions */ + /* Lips: SMA(5) shifted 3 positions */ + + /* Jaw: SMA13 of x[i-8..i+4], displayed at i */ + for (uint_t i = 8; i - 8 + 13 <= n; ++i) + { + fp_t sum = 0; + for (uint_t j = 0; j < 13; ++j) + { + sum += x[0][i - 8 + j]; + } + y[0][i] = sum / 13; + } + + /* Teeth: SMA8 of x[i-5..i+2], displayed at i */ + for (uint_t i = 5; i - 5 + 8 <= n; ++i) + { + fp_t sum = 0; + for (uint_t j = 0; j < 8; ++j) + { + sum += x[0][i - 5 + j]; + } + y[1][i] = sum / 8; + } + + /* Lips: SMA5 of x[i-3..i+1], displayed at i */ + for (uint_t i = 3; i - 3 + 5 <= n; ++i) + { + fp_t sum = 0; + for (uint_t j = 0; j < 5; ++j) + { + sum += x[0][i - 3 + j]; + } + y[2][i] = sum / 5; + } + return 0; +} + -- cgit v1.3.1