quantmod - R yearly returns from dataframe with date and close -


i have data.frame df date df$date , close df$close column. trying yearly returns having problems

i tried

library(quantmod) yr <- data.frame( periodreturn(df, period='yearly', subset='2008::')) 

and having date rownames, cannot work. thank help.

your code works if convert xts. if you're having difficulty converting data.frame xts, provide more info data requested in comments of question.

getsymbols("spy", src='yahoo', return.class='data.frame') #[1] "spy" class(spy) #[1] "data.frame" as.data.frame(periodreturn(xts(spy[["spy.close"]], as.date(rownames(spy))),                             'yearly', subset="2008/"))            yearly.returns 2008-12-31   -0.382805554 2009-12-31    0.234929078 2010-12-31    0.128409907 2011-12-30   -0.001988072 2012-06-04    0.020717131 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -