summaryrefslogtreecommitdiffstats
path: root/lib/pretty_good_oscillator.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/pretty_good_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 'lib/pretty_good_oscillator.c')
-rw-r--r--lib/pretty_good_oscillator.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/pretty_good_oscillator.c b/lib/pretty_good_oscillator.c
new file mode 100644
index 0000000..65a05c2
--- /dev/null
+++ b/lib/pretty_good_oscillator.c
@@ -0,0 +1,64 @@
+// Pretty Good Oscillator
+//
+// pretty_good_oscillator
+//
+// Pretty Good Oscillator
+//
+//
+//
+// Inputs: 1
+// Outputs: 1
+// Constants: 0
+
+
+#include "ts.h"
+
+
+ts_parameter_t const ts_pretty_good_oscillator_p = { .n_inputs = 1, .n_outputs = 1, .n_constants = 0, .params_size = 0 };
+
+uint_t ts_pretty_good_oscillator_offset( ts_constant_t const *c )
+{
+ ( void )c;
+ return ( 0 );
+}
+
+int ts_pretty_good_oscillator(
+ 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_pretty_good_oscillator_p );
+ (void)c;
+ if (n == 0) return -1;
+ fp_t ema14 = x[0][0];
+ fp_t ema30 = x[0][0];
+ fp_t ema90 = x[0][0];
+ fp_t a14 = 15.0 / (19.0 * 14);
+ fp_t a30 = 15.0 / (19.0 * 30);
+ fp_t a90 = 15.0 / (19.0 * 90);
+
+ for( uint_t i = 0; i < n; ++i )
+ {
+ if( i > 0 )
+ {
+ ema14 = ema14 + a14 * (x[0][i] - ema14);
+ ema30 = ema30 + a30 * (x[0][i] - ema30);
+ ema90 = ema90 + a90 * (x[0][i] - ema90);
+ }
+
+ fp_t arr[3] = {ema14, ema30, ema90};
+ for( uint_t a = 0; a < 2; ++a )
+ for( uint_t b = a + 1; b < 3; ++b )
+ if( arr[a] > arr[b] ) { fp_t t = arr[a]; arr[a] = arr[b]; arr[b] = t; }
+
+ fp_t median = arr[1];
+
+ if( median == 0 )
+ y[0][i] = 0;
+ else
+ y[0][i] = (x[0][i] / median - 1.0);
+ }
+ return 0;
+}
+