[R-SIG-Finance] Creating variable based on lags

Am Gut agquantr at gmail.com
Wed Feb 15 21:11:09 CET 2017


Good Afternoon Everyone,

I have a series of returns are was hoping that someone could help me create
a variable based on a pre-specified set of lagged observations. For
example, I would want to sum up the last 25 returns to make a new return
column. I would also like to weight the returns by a factor of 0.25^i with
i being the lag number. I am intuitively thinking a for loop but can not
rationalize internally how to write this. I am trying to make a variable
like below:

newreturn = return(-1)*0.25^1 + return(-2)*0.25^2 + .... return(-25)*0.25^25

And obviously I would like to apply this to all new observations past the
25th observatios to the end of my dataset. I hope this is clear as I know
the solution must be relatively simple. I hope to hear from you guys.

Thanks,

Am Gut

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list