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/mfi.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/mfi.c (limited to 'test/mfi.c') diff --git a/test/mfi.c b/test/mfi.c new file mode 100644 index 0000000..1d83db4 --- /dev/null +++ b/test/mfi.c @@ -0,0 +1,59 @@ +#include +#include "ts.h" + +bool ts_test_mfi( void ) +{ + uint_t k = 3; + + fp_t const o[] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; + fp_t const h[] = { 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 }; + fp_t const l[] = { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }; + fp_t const c[] = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; + fp_t const v[] = { 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 }; + + fp_t const * const x[] = { o, h, l, c, v }; + + fp_t tp[10] = { 0 }; + for( uint_t i = 0; i < 10; ++i ) + { + tp[i] = ( h[i] + l[i] + c[i] ) / 3.0; + } + + fp_t pos_sum = 0; + fp_t neg_sum = 0; + + for( uint_t i = 1; i <= k; ++i ) + { + fp_t raw_mf = tp[i] * v[i]; + if( tp[i] > tp[i - 1] ) + { + pos_sum += raw_mf; + } + else + { + neg_sum += raw_mf; + } + } + + fp_t e[10] = { 0 }; + e[0] = ( neg_sum == 0 ) ? 100.0 : 100.0 - 100.0 / ( 1.0 + pos_sum / neg_sum ); + + for( uint_t i = k + 1; i < 10; ++i ) + { + fp_t cur_raw_mf = tp[i] * v[i]; + if( tp[i] > tp[i - 1] ) pos_sum += cur_raw_mf; + else neg_sum += cur_raw_mf; + + fp_t old_raw_mf = tp[i - k] * v[i - k]; + if( tp[i - k] > tp[i - k - 1] ) pos_sum -= old_raw_mf; + else neg_sum -= old_raw_mf; + + e[i - k] = ( neg_sum == 0 ) ? 100.0 : 100.0 - 100.0 / ( 1.0 + pos_sum / neg_sum ); + } + + fp_t const * const e_arr[1] = { e }; + + uint_t c_val = k; + + return ts_test(ts_mfi, ts_mfi_offset, x, e_arr, 10, (ts_constant_t *)&c_val, &ts_mfi_p); +} -- cgit v1.3.1