[R-SIG-Finance] Performance Analytics table.AnnualizedReturns
Joshua Ulrich
josh.m.ulrich at gmail.com
Sat Sep 8 15:39:15 CEST 2012
A much simpler solution is to use period.apply. Note that
table.AnnualizedReturns returns a multi-row data.frame. period.apply
works best if the function returns a vector, so make a helper function
to do that and everything works.
# A function that wraps table.AnnualizedReturns
# and returns a vector. You might want something
# more elaborate if 'x' has multiple columns and/or
# if you want better column names.
t.table.AnnRet <- function(x) # one 'x' column
drop(t(table.AnnualizedReturns(x)))
#t.table.AnnRet <- function(x) # multiple 'x' columns
# unlist(table.AnnualizedReturns(x))
# call period.apply via apply.monthly
apply.yearly(managers[,2], t.table.AnnRet)
Best,
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
On Fri, Sep 7, 2012 at 3:35 AM, varcovar <varcovar at live.com> wrote:
> Hi Nick,
>
> I don't think there's any table for that specific need. However, here's how
> I would do it:
>
> library(PerformanceAnalytics)
> data(managers)
> R <- managers[, 2]
> years <- as.character(unique(lubridate:::year(index(R))))
> # Return a list whose elements are years and contain table
> ll <- plyr:::llply(years, function(x) {
> ret <- table.AnnualizedReturns(R[x])
> colnames(ret) <- x
> ret
> })
> # Return a table
> df <- unlist(ll)
> dim(df) <- c(3, length(years))
> colnames(df) <- years
> rownames(df) <- c("Annualized Return", "Annualized Volatility", "Sharpe
> Ratio")
>
> Cheers!
>
> Markus D.
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Performance-Analytics-table-AnnualizedReturns-tp4642468p4642485.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
More information about the R-SIG-Finance
mailing list