summaryrefslogtreecommitdiffstats
path: root/test/macd.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/macd.c')
-rw-r--r--test/macd.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/macd.c b/test/macd.c
new file mode 100644
index 0000000..34d6365
--- /dev/null
+++ b/test/macd.c
@@ -0,0 +1,25 @@
+#include <math.h>
+#include <stddef.h>
+#include "ts.h"
+
+bool ts_test_macd( void )
+{
+ fp_t const x[] = { -10, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10 };
+
+ fp_t const * const inp[1] = { x };
+
+ /* fast=3, slow=5, signal=2 */
+ /* Standard EMA: alpha = 2/(k+1) */
+ /* fast_a=2/4=0.5, slow_a=2/6=0.333, sig_a=2/3=0.667 */
+
+ fp_t const em[4] = { 1.91968879, 2.10010502, 2.22689293, 2.31467341 };
+ fp_t const es[4] = { 1.91968879, 2.03996628, 2.16458405, 2.26464362 };
+ fp_t const eh[4] = { 0.00000000, 0.06013875, 0.06230888, 0.05002979 };
+
+ fp_t const * const exp[3] = { em, es, eh };
+
+ typedef struct { fp_t fast; fp_t slow; fp_t signal; } c_t;
+ c_t c = { .fast = 3, .slow = 5, .signal = 2 };
+
+ return ts_test(ts_macd, ts_macd_offset, inp, exp, sizeof( x ) / sizeof( *x ), (ts_constant_t *)&c, &ts_macd_p);
+}