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/ultimate_oscillator.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/ultimate_oscillator.c')
| -rw-r--r-- | test/ultimate_oscillator.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/test/ultimate_oscillator.c b/test/ultimate_oscillator.c new file mode 100644 index 0000000..01bdb62 --- /dev/null +++ b/test/ultimate_oscillator.c @@ -0,0 +1,90 @@ +#include <stddef.h> +#include <stdlib.h> +#include <tgmath.h> +#include "ts.h" + +static fp_t _ts_min( fp_t const * const *x, uint_t start, uint_t count ) +{ + fp_t m = ts_l( x, start ); + for( uint_t i = 1; i < count; ++i ) + { + m = fmin( m, ts_l( x, start - i ) ); + } + return m; +} + +static fp_t _ts_max_h( fp_t const * const *x, uint_t start, uint_t count ) +{ + fp_t m = ts_h( x, start ); + for( uint_t i = 1; i < count; ++i ) + { + m = fmax( m, ts_h( x, start - i ) ); + } + return m; +} + +bool ts_test_ultimate_oscillator( void ) +{ + uint_t n = 60; + + fp_t o[60], h[60], l[60], c[60]; + for (uint_t i = 0; i < n; ++i) + { + o[i] = 10.0 + (fp_t)i; + h[i] = 12.0 + (fp_t)i; + l[i] = 8.0 + (fp_t)i; + c[i] = 11.0 + (fp_t)i; + } + + fp_t const * const x[] = { o, h, l, c }; + + uint_t offset = 54; + uint_t e_n = n - offset; + fp_t *e = calloc(e_n, sizeof(fp_t)); + if (!e) return false; + + for( uint_t i = offset; i < n; ++i ) + { + fp_t bp7 = 0, tr7 = 0; + fp_t bp14 = 0, tr14 = 0; + fp_t bp28 = 0, tr28 = 0; + + for( uint_t j = 0; j < 7; ++j ) + { + uint_t idx = i - 6 + j; + fp_t ll = _ts_min( x, idx, 7 ); + fp_t hh = _ts_max_h( x, idx, 7 ); + bp7 += ts_c( x, idx ) - ll; + tr7 += hh - ll; + } + + for( uint_t j = 0; j < 14; ++j ) + { + uint_t idx = i - 13 + j; + fp_t ll = _ts_min( x, idx, 14 ); + fp_t hh = _ts_max_h( x, idx, 14 ); + bp14 += ts_c( x, idx ) - ll; + tr14 += hh - ll; + } + + for( uint_t j = 0; j < 28; ++j ) + { + uint_t idx = i - 27 + j; + fp_t ll = _ts_min( x, idx, 28 ); + fp_t hh = _ts_max_h( x, idx, 28 ); + bp28 += ts_c( x, idx ) - ll; + tr28 += hh - ll; + } + + fp_t denom = 7.0 * tr7 + 3.0 * tr14 + tr28; + fp_t numer = 7.0 * bp7 + 3.0 * bp14 + bp28; + e[i - offset] = ( denom != 0 ) ? 100.0 * numer / denom : 50.0; + } + + fp_t const * const e_arr[1] = { e }; + + bool result = ts_test(ts_ultimate_oscillator, ts_ultimate_oscillator_offset, x, e_arr, n, (ts_constant_t *)NULL, &ts_ultimate_oscillator_p); + + free(e); + return result; +} |