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/starc_lower.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 lib/starc_lower.c (limited to 'lib/starc_lower.c') diff --git a/lib/starc_lower.c b/lib/starc_lower.c new file mode 100644 index 0000000..97ac02f --- /dev/null +++ b/lib/starc_lower.c @@ -0,0 +1,74 @@ +// Starc Lower +// +// starc_lower +// +// STARC Lower Band +// +// +// +// Inputs: 4 +// Outputs: 1 +// Constants: 2 + + +#include +#include "ts.h" + +typedef struct { + uint_t k; + fp_t mult; +} ts_starc_lower_params_t; + +ts_parameter_t const ts_starc_lower_p = { .n_inputs = 4, .n_outputs = 1, .n_constants = 2, .params_size = sizeof(ts_starc_lower_params_t) }; + +uint_t ts_starc_lower_offset( ts_constant_t const *c ) +{ + ( void )c; + return ( c ? ((ts_starc_lower_params_t *)c)->k > 0 ? ((ts_starc_lower_params_t *)c)->k - 1 : 0 : 0 ); +} + +int ts_starc_lower( + 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_starc_lower_p ); + if ( !c ) return -1; + uint_t k = ((ts_starc_lower_params_t *)c)->k; + if( k == 0 ) return -1; + fp_t mult = ((ts_starc_lower_params_t *)c)->mult; + + uint_t half_k = k / 2; + if (n <= half_k) return -1; + + uint_t last = k - 1; + for( uint_t i = k - 1; i < n - half_k; ++i ) + { + fp_t middle_sum = 0; + fp_t atr_sum = 0; + + for( uint_t j = 0; j < k; ++j ) + { + uint_t idx = i - half_k + j; + middle_sum += ts_c( x, idx ); + + fp_t tr = ts_h( x, idx ) - ts_l( x, idx ); + if( idx > 0 ) + { + fp_t h_pc = fabs( ts_h( x, idx ) - ts_c( x, idx - 1 ) ); + fp_t l_pc = fabs( ts_l( x, idx ) - ts_c( x, idx - 1 ) ); + if( h_pc > tr ) tr = h_pc; + if( l_pc > tr ) tr = l_pc; + } + atr_sum += tr; + } + + y[0][i] = middle_sum / k - mult * atr_sum / k; + last = i; + } + for( uint_t i = last + 1; i < n; ++i ) + y[0][i] = y[0][last]; + return 0; +} + -- cgit v1.3.1