summaryrefslogtreecommitdiffstats
path: root/test/volume_delta.c
blob: 42a4c873dc51d88ee0e81284053e25a0f5db7536 (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
28
29
30
31
32
33
34
35
36
37
38
39
#include <stddef.h>
#include "ts.h"

bool ts_test_volume_delta( void )
{
    fp_t const o[] = { 10, 11, 12, 13, 14 };
    fp_t const h[] = { 12, 13, 14, 15, 16 };
    fp_t const l[] = { 8,  9,  10,  11,  12 };
    fp_t const c[] = { 11, 12, 13, 14,  15 };
    fp_t const v[] = { 100, 200, 300, 400, 500 };

    fp_t const * const x[] = { o, h, l, c, v };

    fp_t e[5] = { 0 };
    for( uint_t i = 0; i < 5; ++i )
    {
        fp_t hl = h[i] - l[i];
        if( hl == 0 )
        {
            e[i] = 0;
        }
        else if( c[i] > o[i] )
        {
            fp_t buy_vol = v[i] * ( c[i] - l[i] ) / hl;
            fp_t sell_vol = v[i] - buy_vol;
            e[i] = buy_vol - sell_vol;
        }
        else if( c[i] < o[i] )
        {
            fp_t sell_vol = v[i] * ( h[i] - c[i] ) / hl;
            fp_t buy_vol = v[i] - sell_vol;
            e[i] = buy_vol - sell_vol;
        }
    }

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

    return ts_test(ts_volume_delta, ts_volume_delta_offset, x, e_arr, 5, (ts_constant_t *)NULL, &ts_volume_delta_p);
}