summaryrefslogtreecommitdiffstats
path: root/test/macd.c
blob: 34d636546d5afca520bed16f76d46c9d983b7cdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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);
}