summaryrefslogtreecommitdiffstats
path: root/test/choppiness_index.c
blob: fda6520ffe4e4fbe8f2f08fef13cf714e9e9f395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <math.h>
#include <stddef.h>
#include "ts.h"

bool ts_test_choppiness_index( void )
{
    fp_t const o[] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 };
    fp_t const h[] = { 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
    fp_t const l[] = { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 };
    fp_t const c[] = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
    fp_t const v[] = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 };

    fp_t const * const x[] = { o, h, l, c, v };

    /* k=3, 2k=6, offset=6, H-L=3 for all bars */
    /* At xi=6: sum_range of bars 0-2 = 9, HH6 of bars 1-6 = 18, LL6 of bars 1-6 = 10, range=8 */
    /* CI = 100 * ln(9/8) / ln(3/e) = 100 * 0.11778 / 0.04931 = 238.9 */
    fp_t const e[] = { 10.72107, 10.72107, 10.72107, 10.72107, 10.72107, 10.72107, 10.72107, 10.72107, 10.72107, 10.72107, 10.72107, 10.72107, 10.72107, 10.72107 };
    fp_t const * const exp[1] = { e };

    uint_t k = 3;
    return ts_test(ts_choppiness_index, ts_choppiness_index_offset, x, exp, sizeof( o ) / sizeof( *o ), (ts_constant_t *)&k, &ts_choppiness_index_p);
}