I want to find the maximum compound interest rate in a candlestick serie.
The difficulty here is to find the best next “HIGH” value in a serie which will not bypass a possible intermediate additional interest in between.
For example, four OHLCs (time, open, high, low, close) with such values to test.
Useless values have been set to zero to ease the reading.
(time, open, high, low, close) [ 3, 0, 2, 0, 0 ] [ 2, 0, 0, 1.8, 0 ] [ 1, 0, 1.1, 0, 0 ] [ 0, 0, 0, 1, 0 ]
If I do a simple iteration on every ohlc from oldest to latest to find it’s next higher “HIGH” value in the OHLC serie :
ohlcs.stream().filter(nextOhlc ->
nextOhlc.getTime() > currentOhlc.getTime()
&& nextOhlc.getHigh().compareTo(currentOhlc.getLow()) > 0
).findFirst()
It will compute interest of ohlc[0].low
value with ohlc[1].high
value and ohlc[2].low
value with ohlc[3].high
, giving a compound rate of ~1.22.
Whereas the computation should choose to compute ohlc[0].low
with ohlc[3].high
, giving a compound rate of 2.
Should I compute every possibilities of the serie to find the best one (something like n^
n
possiblities with n
OHLCs) ?
There must be a simpler way to find to maximum compound interest rate over a candlestick serie.
Thanks for helping.