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/intraday_momentum_index.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/intraday_momentum_index.c')
| -rw-r--r-- | test/intraday_momentum_index.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/intraday_momentum_index.c b/test/intraday_momentum_index.c new file mode 100644 index 0000000..4044faf --- /dev/null +++ b/test/intraday_momentum_index.c @@ -0,0 +1,39 @@ +#include <math.h> +#include <stddef.h> +#include "ts.h" + +bool ts_test_intraday_momentum_index( void ) +{ + /* k=3, open always = prev_close => diff=0, IMI=0/0=0 */ + 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[] = { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }; + fp_t const c[] = { 10, 12, 14, 16, 18, 20, 22, 24, 26, 28 }; + + fp_t const * const x[] = { o, h, l, c }; + + /* open[i] = close[i-1] for i>=1: o[1]=11 != c[0]=10, diff=1 (up) */ + /* o[2]=12 vs c[1]=12, diff=0 */ + /* o[3]=13 vs c[2]=14, diff=-1 (down=1) */ + /* o[4]=14 vs c[3]=16, diff=-2 (down=2) */ + /* For i=1..3: up=1+0+0=1, down=0+1+2=3, IMI=1/4=0.25 */ + /* Hmm let me recalculate more carefully. xi goes 1 to k=3 */ + /* xi=1: o[1]-c[0]=11-10=1 > 0, sum_up=1 */ + /* xi=2: o[2]-c[1]=12-12=0, neither up nor down, sum_up=1, sum_down=0 */ + /* xi=3: o[3]-c[2]=13-14=-1 < 0, sum_down=1, sum_up=1 */ + /* y[0][3] = 1/(1+1) = 0.5 */ + /* xi=4: o[4]-c[3]=14-16=-2, old=o[1]-c[0]=1 */ + /* sum_up stays 1 (no add), sum_down+=2=3, then remove old: sum_up-=1=0 */ + /* Hmm that logic is wrong. Let me rewrite the incremental part. */ + + /* Actually the incremental update is tricky. Let me use a simpler approach: */ + /* For i=4: diffs at [4,5,6] = o[4]-c[3], o[5]-c[4], o[6]-c[5] */ + /* = 14-16=-2, 15-18=-3, 16-20=-4 */ + /* up=0, down=2+3+4=9, IMI=0 */ + + fp_t const e[] = { 0.5, 0, 0, 0, 0, 0, 0 }; + fp_t const * const exp[1] = { e }; + + uint_t k = 3; + return ts_test(ts_intraday_momentum_index, ts_intraday_momentum_index_offset, x, exp, sizeof( o ) / sizeof( *o ), (ts_constant_t *)&k, &ts_intraday_momentum_index_p); +} |