TommyF
TommyF

Reputation: 7150

R xts time series compare to previous observation

I've imported some intraday financial time series data (OHLC) into an xts object. I now want to analyse how often the gap between the previous days close and next days open was filled during this day (and further down what influences the size of the gap, day of week etc. had on the stats).

I've resampled the data via to.daily() into a daily series, but how can I now filter for days where

day[i-1]$Close >= day[i]$Low & day[i-1]$Close <= day[i]$High

and ideally add day[i-1]$Close as an additional column for reference to the resulting subset?

Upvotes: 0

Views: 261

Answers (1)

TommyF
TommyF

Reputation: 7150

I've found a solution via

merge(d1, lag(d1$Close))

Now you have the previous days close as an additional column and can now filter as usual within one row.

Upvotes: 0

Related Questions