Say I have ohlcv data on the 15min timescale, but I’m interested in obtaining an indicator defined e.g.,
/ simple moving average
sma:{[n;close] mavg[n; close]};
on a daily timeframe? Of course, I could obtain a daily aggregation of bars, calculate the indicators and lj
on dates to get the indicator on the lower timeframe.
However, all but the last values for the sma101D
indicator below are premature (i.e., have a look-ahead bias). They need to be calcuated afresh. How can i do this efficiently in kdb+
for an arbitrary technical indicator ti[params...;o;h;l;c;v]
given the availability of open, high, low, close, volume data on the lower (15m) timeframe?
Complicating matters a bit is that one has odd days in which the trading session is shorter than usual having therefore a smaller number of bars.
ticker date sourcetime open close high low volume exchange sma101D
--------------------------------------------------------------------------------------------------
IBM 2024.06.20 2024.06.20D08:45:00.000000000 980 980 981 979.55 119869 12 0.588969 / not ok
IBM 2024.06.20 2024.06.20D09:00:00.000000000 980 979.95 980.4 978.4 109497 12 0.588969 / not ok
IBM 2024.06.20 2024.06.20D09:15:00.000000000 979.55 978.85 979.95 978.2 142514 12 0.588969 / not ok
IBM 2024.06.20 2024.06.20D09:30:00.000000000 978.85 978.65 979.8 977.5 521472 12 0.588969 / not ok
IBM 2024.06.20 2024.06.20D09:45:00.000000000 978.75 979.1 979.9 977 619798 12 0.588969 / OK