summaryrefslogtreecommitdiffstats
path: root/lib/ease_of_movement.c
diff options
context:
space:
mode:
authorEthan Werner <mail@ethanwerner.com>2026-07-01 09:42:39 +0400
committerEthan Werner <mail@ethanwerner.com>2026-07-01 09:42:39 +0400
commit07e18043145f3d91c8ea7ec3ad41b3c905585277 (patch)
tree2bdeae46973f4bdfce263679a4008ac768011f28 /lib/ease_of_movement.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 'lib/ease_of_movement.c')
-rw-r--r--lib/ease_of_movement.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/ease_of_movement.c b/lib/ease_of_movement.c
new file mode 100644
index 0000000..d16f32c
--- /dev/null
+++ b/lib/ease_of_movement.c
@@ -0,0 +1,71 @@
+// Ease of Movement
+//
+// ease_of_movement - EOM
+//
+// SMA of (midpoint change) / (volume / range), volume-based momentum
+//
+// Inputs: 5 (OHLCV)
+// Outputs: 1 (EOM)
+// Constants: 1 (period)
+
+#include <stdlib.h>
+#include "ts.h"
+
+typedef struct {
+ uint_t k;
+} ts_ease_of_movement_params_t;
+
+ts_parameter_t const ts_ease_of_movement_p = { .n_inputs = 5, .n_outputs = 1, .n_constants = 1, .params_size = sizeof(ts_ease_of_movement_params_t) };
+
+uint_t ts_ease_of_movement_offset( ts_constant_t const *c )
+{
+ ( void )c;
+ return ( 3 );
+}
+
+int ts_ease_of_movement(
+ fp_t * const *y, uint_t y_n,
+ fp_t const * const *x, uint_t x_n,
+ uint_t n, ts_constant_t const *c
+)
+{
+ TS_PROLOGUE( ts_ease_of_movement_p );
+ if ( !c ) return -1;
+ uint_t k = ((ts_ease_of_movement_params_t *)c)->k;
+ if (k == 0 || n <= k) return -1;
+
+ fp_t *eom = calloc( n, sizeof( fp_t ) );
+ if( !eom ) return -1;
+
+ for( uint_t i = 1; i < n; ++i )
+ {
+ fp_t hl = ts_h( x, i ) - ts_l( x, i );
+ if( hl == 0 ) continue;
+ fp_t br = ts_v( x, i ) / hl;
+ if( br == 0 ) continue;
+ fp_t cur_mid = ( ts_h( x, i ) + ts_l( x, i ) ) / 2.0;
+ fp_t prev_mid = ( ts_h( x, i - 1 ) + ts_l( x, i - 1 ) ) / 2.0;
+ eom[i] = ( cur_mid - prev_mid ) / br;
+ }
+
+ {
+ for (uint_t i = 0; i < k; ++i) y[0][i] = 0;
+
+ fp_t sum = 0;
+ for( uint_t i = 1; i <= k; ++i )
+ {
+ sum += eom[i];
+ }
+ y[0][k] = sum / (fp_t)k;
+ for( uint_t i = k + 1; i < n; ++i )
+ {
+ sum = sum - eom[i - k] + eom[i];
+ y[0][i] = sum / (fp_t)k;
+ }
+ }
+
+ free( eom );
+ return 0;
+}
+
+