#include #include #include "ts.h" bool ts_test_rsi( void ) { /* k=3, changes: +1, +1, +1, 0, -1, -1, -1, 0, +1 */ fp_t const x[] = { 10, 11, 12, 13, 13, 12, 11, 10, 10, 11 }; fp_t const * const inp[1] = { x }; /* i=3: sum_gain=3, sum_loss=0, avg_gain=1, avg_loss=0 => RSI=100 */ /* i=4: change=0, avg_gain=(1*2+0)/3=2/3, avg_loss=0 => RSI=100 */ /* i=5: change=-1, avg_gain=(2/3*2+0)/3=4/9, avg_loss=(0*2+1)/3=1/3 */ /* RS = (4/9)/(1/3) = 4/3, RSI = 100 - 100/(1+4/3) = 100 - 300/7 = 57.142857 */ /* i=6: change=-1, avg_gain=(4/9*2+0)/3=8/27, avg_loss=(1/3*2+1)/3=5/9 */ /* RS = (8/27)/(5/9) = 8/15, RSI = 100 - 100/(1+8/15) = 100 - 1500/23 = 34.782609 */ /* i=7: change=-1, avg_gain=(8/27*2+0)/3=16/81, avg_loss=(5/9*2+1)/3=19/27 */ /* RS = (16/81)/(19/27) = 16/57, RSI = 100 - 100/(1+16/57) = 100 - 5700/73 = 21.917808 */ /* i=8: change=0, avg_gain=(16/81*2+0)/3=32/243, avg_loss=(19/27*2+0)/3=38/81 */ /* RS = (32/243)/(38/81) = 16/57, RSI = 21.917808 */ /* i=9: change=+1, avg_gain=(32/243*2+1)/3=307/729, avg_loss=(38/81*2+0)/3=76/243 */ /* RS = (307/729)/(76/243) = 307/228, RSI = 100 - 100/(1+307/228) = 100 - 22800/535 = 57.383178 */ fp_t const e[] = { 100, 100, 57.142857, 34.782609, 21.917808, 21.917808, 57.383178 }; fp_t const * const exp[1] = { e }; uint_t k = 3; return ts_test(ts_rsi, ts_rsi_offset, inp, exp, sizeof( x ) / sizeof( *x ), (ts_constant_t *)&k, &ts_rsi_p); }