summaryrefslogtreecommitdiffstats
path: root/test/asi.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 /test/asi.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/asi.c')
-rw-r--r--test/asi.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/asi.c b/test/asi.c
new file mode 100644
index 0000000..0307a3b
--- /dev/null
+++ b/test/asi.c
@@ -0,0 +1,35 @@
+#include <math.h>
+#include <stddef.h>
+#include "ts.h"
+
+bool ts_test_asi( void )
+{
+ 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[] = { 11, 12, 11, 14, 13, 16, 15, 18, 17, 20 };
+
+ fp_t const * const x[] = { o, h, l, c };
+
+ /* ASI = prev_ASI + component2 + component3
+ * component2 = (term1 - term2 + term3) / denom * (H - L)
+ * component3 = (term1 - term2 + term3) / (2 * denom)
+ * term1 = C - Cprev, term2 = 0.5*(O - Op), term3 = 0.25*(C - O + Op - Cp)
+ * denom = max(H - Lp, Hp - L, Hp - Lp)
+ *
+ * i=0: ASI = 0
+ * i=1: term1=1, term2=0.5, term3=0, denom=4, comp2=0.375, comp3=0.125 => 0.5
+ * i=2: term1=-1, term2=0.5, term3=-0.5, denom=4, comp2=-1.5, comp3=-0.5 => -1.5
+ * i=3: term1=3, term2=0.5, term3=0.5, denom=4, comp2=2.25, comp3=0.75 => 1.5
+ * i=4: term1=-1, term2=0.5, term3=-0.5, denom=4, comp2=-1.5, comp3=-0.5 => -0.5
+ * i=5: term1=3, term2=0.5, term3=0.5, denom=4, comp2=2.25, comp3=0.75 => 2.5
+ * i=6: term1=-1, term2=0.5, term3=-0.5, denom=4, comp2=-1.5, comp3=-0.5 => 0.5
+ * i=7: term1=3, term2=0.5, term3=0.5, denom=4, comp2=2.25, comp3=0.75 => 3.5
+ * i=8: term1=-1, term2=0.5, term3=-0.5, denom=4, comp2=-1.5, comp3=-0.5 => 1.5
+ * i=9: term1=3, term2=0.5, term3=0.5, denom=4, comp2=2.25, comp3=0.75 => 4.5
+ */
+ fp_t const e[] = { 0, 0.5, -1.5, 1.5, -0.5, 2.5, 0.5, 3.5, 1.5, 4.5 };
+ fp_t const * const exp[1] = { e };
+
+ return ts_test(ts_asi, ts_asi_offset, x, exp, sizeof( o ) / sizeof( *o ), (ts_constant_t *)NULL, &ts_asi_p);
+}