So if I have a data-frame like this,
Index Date Open High Low Close
1 2017-04-25 2378.50 2389.25 2377.50 2385.00
2 2017-04-26 2384.75 2394.75 2382.00 2382.75
3 2017-04-27 2386.50 2388.75 2378.75 2386.25
4 2017-04-28 2388.00 2388.25 2378.25 2380.50
5 2017-05-01 2386.00 2390.75 2380.75 2387.00
6 2017-05-02 2387.50 2388.75 2381.75 2386.00
How can I calculate Open[2]-Close[1] and do this for every row, i.e. Open[i]-Close[i-1]?
Index Date Open High Low Close DIFF(O-C)
1 2017-04-25 2378.50 2389.25 2377.50 2385.00
2 2017-04-26 2384.75 2394.75 2382.00 2382.75 -0.25
3 2017-04-27 2386.50 2388.75 2378.75 2386.25 3.75
..................
I would like a column like above.
I'm not sure if my google-fu is weak or what, but couldn't find an answer to this. Do I need to use a loop for this kind of analysis?