summaryrefslogtreecommitdiffstats
path: root/test/price_rate_of_change.c
blob: ec3eb9c7f1c5161fc92918854c8c64ee69172725 (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
27
#include <math.h>
#include <stddef.h>
#include "ts.h"

bool ts_test_price_rate_of_change( void )
{
    fp_t const x[] = { 100, 110, 120, 130, 140, 150, 160, 170, 180, 190 };

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

    /* k=3 */
    /* PROC[3] = (130-100)/100*100 = 30 */
    /* PROC[4] = (140-110)/110*100 = 27.2727 */
    /* PROC[5] = (150-120)/120*100 = 25 */
    /* PROC[6] = (160-130)/130*100 = 23.0769 */
    /* PROC[7] = (170-140)/140*100 = 21.4286 */
    /* PROC[8] = (180-150)/150*100 = 20 */
    /* PROC[9] = (190-160)/160*100 = 18.75 */

    fp_t e[] = { 30.0, 27.272727272727273, 25.0, 23.076923076923077, 21.428571428571427, 20.0, 18.75 };

    fp_t const * const exp[1] = { e };

    uint_t c_val = 3;

    return ts_test(ts_price_rate_of_change, ts_price_rate_of_change_offset, inp, exp, sizeof( x ) / sizeof( *x ), (ts_constant_t *)&c_val, &ts_price_rate_of_change_p);
}