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/twiggs_money_flow.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/twiggs_money_flow.c (limited to 'test/twiggs_money_flow.c') diff --git a/test/twiggs_money_flow.c b/test/twiggs_money_flow.c new file mode 100644 index 0000000..8fb5471 --- /dev/null +++ b/test/twiggs_money_flow.c @@ -0,0 +1,41 @@ +#include +#include +#include "ts.h" + +bool ts_test_twiggs_money_flow( void ) +{ + fp_t x_data[37] = { 0 }; + for( uint_t i = 0; i < 37; ++i ) + { + x_data[i] = (fp_t)(10 + i); + } + + fp_t const * const x[] = { x_data }; + + fp_t pos_sum = 0; + fp_t neg_sum = 0; + + for( uint_t i = 1; i <= 35; ++i ) + { + fp_t change = x_data[i] - x_data[i - 1]; + if( change >= 0 ) pos_sum += change; + else neg_sum += fabs( change ); + } + + fp_t e[2] = { 0 }; + fp_t total = pos_sum + neg_sum; + e[0] = ( total != 0 ) ? ( pos_sum - neg_sum ) / total * 100.0 : 0; + + fp_t change = x_data[36] - x_data[35]; + fp_t old_change = x_data[1] - x_data[0]; + if( change >= 0 ) pos_sum += change; + else neg_sum += fabs( change ); + if( old_change >= 0 ) pos_sum -= old_change; + else neg_sum -= fabs( old_change ); + total = pos_sum + neg_sum; + e[1] = ( total != 0 ) ? ( pos_sum - neg_sum ) / total * 100.0 : 0; + + fp_t const * const e_arr[1] = { e }; + + return ts_test(ts_twiggs_money_flow, ts_twiggs_money_flow_offset, x, e_arr, 37, (ts_constant_t *)NULL, &ts_twiggs_money_flow_p); +} -- cgit v1.3.1