Hello everyone,
I am a novice in R, so wasn't sure where to post this exactly but I still wanted to pose this question so one of you might have an answer. Here is what I am trying to do:
- I have the stock price data for any ticker, say for example, AAPL for the past 10 years, daily data with these columns - date, open, high, low, close, volume.
- I want to include a column to this dataset, which calculates the %Off High = (close/Max(high) - 1)*100
The catch here is the high is reset every time as you go row by row. To explain, in the first row, the calculation is straight forward, when I go to the second row, i.e. the next day, the high will be the max high of those 2 days in the calculation, and if I go to the 10th day for the calculation, the high will be the max of those 10 days.
In the end, I'd like to chart this daily %offHigh column data.
Anything you can do to help will be appreciated.
Thanks in advance.