Create lead and lag variable in DataFrame

Yep, you could do something like:

using ShiftedArrays
v = lead(price) .- 2 .* price .+ lag(price)

which avoids unnecessary allocations. I think it works best on Julia 0.7 due to recent improvements on missing data handling by @nalimilan, but if you don’t think you’ll encounter performance issues it should be usable already.

To integrate this functionality in DataFrames, I guess the easiest is to add ShiftedArrays as a DataFrames dependency (ShiftedArrays is a small pure Julia package) and reexport lead and lag.