If I have some OHLC data, with some NA rows, is there already a function in one of the R packages that will interpolate data?
na.locf
has two cons:
- It is flat, then a sudden jump
- Used naively, it will repeat the whole of the last bar, with its high/lows
UPDATE: na.approx
is superior to na.locf
in the first respect, thanks Dirk, but I'm still searching for an existing function that is bar-aware. I.e. that will interpolate from the close of previous bar to the open of the next non-NA bar, and will create flat bars. Bonus points if it sets volume to zero! (So, I suspect the answer to my question is going to be "No", and I'll roll-my-own... but I'll wait a bit longer.)
ASIDE: na.approx vs. na.spline
Executive summary: na.spline
is imaginative, use with care!
Here is some FX data (close prices only) with the original data in blue, and the na.approx
joins shown in green:
Then here is the same data, but using na.spline
:
Of particular concern is that na.spline has decided to create a new high!
zoo::na.spline
- dickoa