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
27
28
29
|
#include <math.h>
#include <stddef.h>
#include "ts.h"
bool ts_test_zigzag( void )
{
/* threshold=5% */
/* Prices: 100, 102, 104, 108, 110, 105, 95, 90, 94, 98 */
fp_t const x[] = { 100, 102, 104, 108, 110, 105, 95, 90, 94, 98 };
fp_t const * const inp[1] = { x };
/* i=0: zz=100, dir=0 */
/* i=1: change=(102-100)/100*100=2% < 5%, no change */
/* i=2: change=4% < 5%, no change */
/* i=3: change=8% >= 5%, zz=108, dir=1 */
/* i=4: change=(110-108)/108*100=1.85% < 5%, no change */
/* i=5: change=(105-108)/108*100=-2.78% > -5%, no change */
/* i=6: change=(95-108)/108*100=-12.04% <= -5%, zz=95, dir=-1 */
/* i=7: change=(90-95)/95*100=-5.26% <= -5%, zz=90, dir=-1 */
/* i=8: change=(94-90)/90*100=4.44% < 5%, no change */
/* i=9: change=(98-90)/90*100=8.89% >= 5%, zz=98, dir=1 */
fp_t const ezz[] = { 100, 100, 100, 108, 108, 108, 95, 95, 95, 95 };
fp_t const ed[] = { 0, 0, 0, 1, 1, 1, -1, -1, -1, -1 };
fp_t const * const exp[2] = { ezz, ed };
fp_t threshold = 5;
return ts_test(ts_zigzag, ts_zigzag_offset, inp, exp, sizeof( x ) / sizeof( *x ), (ts_constant_t *)&threshold, &ts_zigzag_p);
}
|