[R] A portfolio return function?

Joshua Ulrich josh.m.ulrich at gmail.com
Sat Feb 14 05:11:27 CET 2015


Hi Ernie,

You seem confused.  sqrt(t(w) %*% V %*% w) calculates portfolio
volatility, not returns.  You can calculate portfolio volatility with
PerformanceAnalytics::StdDev.

require(PerformanceAnalytics)
data(edhec)

set.seed(21)
w <- runif(ncol(edhec))
w <- w/sum(w)
sqrt(t(w) %*% cov(edhec) %*% w)
StdDev(edhec, weights=w)

You can use PerformanceAnalytics to calculate the total portfolio
return a couple different ways.

w %*% t(Return.cumulative(edhec))
Return.cumulative(Return.portfolio(edhec, w))

Also, R-SIG-Finance is a better place to ask finance-specific
questions.  You'll likely get faster and more complete responses.

Best,
Josh


On Wed, Feb 11, 2015 at 10:25 AM, Ernest Stokely <wizardchef at gmail.com> wrote:
>
> For finance applications, I'm surprised that I am unable to find a function to compute the portfolio return (sqrt(t(w) %*% V %*% w)) where w are portfolio weights and V is the cov(returns). The Performance Analytics portfolio return function seems to compute something else.
> Ernie
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com



More information about the R-help mailing list