diff options
Diffstat (limited to 'test/choppiness_index.c')
| -rw-r--r-- | test/choppiness_index.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/choppiness_index.c b/test/choppiness_index.c new file mode 100644 index 0000000..fda6520 --- /dev/null +++ b/test/choppiness_index.c @@ -0,0 +1,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); +} |