I am currently using R to do some research and I was wondering if anybody had any smart ideas or any prepackaged functions on how to create the following variable:
I have a univariate price series of say daily closing prices of a financial asset, that goes back say 10 years. (its an xts object)
I have chosen my x to be 2%
For each day of my price data. I would like to know the minimum number of days back in time you need to go in order to have created a (potentially absolute) return (assuming you had the foresight to trade back then) greater than x%. The variable will give me back the number of days/months/years needed to generate a return of that x%. NAs are returned at the early stages if needing to go back beyond the start of the data to generate a return greater than x%.
I can think of some manual and clunky ways of doing this, but it uses loads of loops to check through loads of dates/prices in order to return the correct value for each day, and then the process repeats itself for the next day...its quite problematic on 10 years of data or on intra-day data, so up-votes will be given for faster solutions....