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
30
31
32
33
34
35
36
37
38
39
|
#include <math.h>
#include <stddef.h>
#include "ts.h"
bool ts_test_intraday_momentum_index( void )
{
/* k=3, open always = prev_close => diff=0, IMI=0/0=0 */
fp_t const o[] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
fp_t const h[] = { 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
fp_t const l[] = { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 };
fp_t const c[] = { 10, 12, 14, 16, 18, 20, 22, 24, 26, 28 };
fp_t const * const x[] = { o, h, l, c };
/* open[i] = close[i-1] for i>=1: o[1]=11 != c[0]=10, diff=1 (up) */
/* o[2]=12 vs c[1]=12, diff=0 */
/* o[3]=13 vs c[2]=14, diff=-1 (down=1) */
/* o[4]=14 vs c[3]=16, diff=-2 (down=2) */
/* For i=1..3: up=1+0+0=1, down=0+1+2=3, IMI=1/4=0.25 */
/* Hmm let me recalculate more carefully. xi goes 1 to k=3 */
/* xi=1: o[1]-c[0]=11-10=1 > 0, sum_up=1 */
/* xi=2: o[2]-c[1]=12-12=0, neither up nor down, sum_up=1, sum_down=0 */
/* xi=3: o[3]-c[2]=13-14=-1 < 0, sum_down=1, sum_up=1 */
/* y[0][3] = 1/(1+1) = 0.5 */
/* xi=4: o[4]-c[3]=14-16=-2, old=o[1]-c[0]=1 */
/* sum_up stays 1 (no add), sum_down+=2=3, then remove old: sum_up-=1=0 */
/* Hmm that logic is wrong. Let me rewrite the incremental part. */
/* Actually the incremental update is tricky. Let me use a simpler approach: */
/* For i=4: diffs at [4,5,6] = o[4]-c[3], o[5]-c[4], o[6]-c[5] */
/* = 14-16=-2, 15-18=-3, 16-20=-4 */
/* up=0, down=2+3+4=9, IMI=0 */
fp_t const e[] = { 0.5, 0, 0, 0, 0, 0, 0 };
fp_t const * const exp[1] = { e };
uint_t k = 3;
return ts_test(ts_intraday_momentum_index, ts_intraday_momentum_index_offset, x, exp, sizeof( o ) / sizeof( *o ), (ts_constant_t *)&k, &ts_intraday_momentum_index_p);
}
|