summaryrefslogtreecommitdiffstats
path: root/test/coppock_curve.c
blob: 48239e45ee79061a93196339b6dd9fb666d14767 (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
26
#include <math.h>
#include <stddef.h>
#include "ts.h"

bool ts_test_coppock_curve( void )
{
	fp_t const x[] = { 100, 105, 98, 110, 102, 115, 108, 120, 106, 112, 118, 99, 113, 107, 121, 114, 109, 116, 103, 111, 119, 104, 117, 108, 122, 110, 115, 107, 121, 105 };

	fp_t const * const inp[1] = { x };

	/*
	 * Coppock = expanding WMA(ROC(14) + ROC(11)), full WMA(10) from idx 9,
	 * then rolling WMA(10).  ROC(k) = (x[i] - x[i-k]) / x[i-k] * 100.
	 * WMA weights: most recent value gets highest weight.
	 * Offset = 14, first output at index 14.
	 */
	fp_t const e[] = {
	    31.00000000, 27.44537815, 23.27989457, 20.98845532, 17.79356430,
	    15.48386172, 14.28049689, 12.48191637, 11.72007206, 10.86293252,
	     6.25323376,  3.24940269,  2.78976008,  0.81656550,  3.89753260,
	     4.22501503
	};
	fp_t const * const exp[1] = { e };

	return ts_test(ts_coppock_curve, ts_coppock_curve_offset, inp, exp, 30, (ts_constant_t *)NULL, &ts_coppock_curve_p);
}