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/twiggs_money_flow.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/twiggs_money_flow.c')
| -rw-r--r-- | test/twiggs_money_flow.c | 41 |
1 files changed, 41 insertions, 0 deletions
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 <math.h> +#include <stddef.h> +#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); +} |