I need to get a 3-year rolling return working (3-year return for each id, for each year).
I have tried to use the PerformanceAnalytics
package but I keep getting an error that my data is not a time series.
When I use the function it says TRUE so I am completely stuck as to how to get the 3-year rolling return to work. So I just need someone to provide me with the R code that will produce the 3-year returns.
Here's a sample dataset
ppd_id FY TF_1YR
1 2001 -0.0636
1 2002 -0.0929
1 2003 0.1648
1 2004 0.1006
1 2005 0.1098
1 2006 0.0837
1 2007 0.1792
1 2008 -0.1521
1 2009 -0.1003
1 2010 0.0847
1 2011 0.0221
1 2012 0.1801
1 2013 0.146
1 2014 0.1202
1 2015 0.0105
1 2016 0.1022
1 2017 0.1286
1 2018 0.0929
Here's my code
library(smooth)
library(readr)
pensionreturns <- read_csv("pensionreturns.csv")
sma(pensionreturns, h=