[R-SIG-Finance] assetsStat function Question

Brian G. Peterson brian at braverock.com
Thu Feb 15 01:44:53 CET 2007


On Wednesday 14 February 2007 17:37, Joe Byers wrote:
> I was looking at the assetsStat function as an example for my
> investments class for calculating portfolio statistics. The
> documentation said it was developed for monthly data and rescaling was
> a problem.  I reviewed the code to determine the rescaling factors I
> would need for daily or weekly data when I noticed the following two
> lines of code (bold face in the function attached at the bottom).
> * *       result[3, i] = annualizedAverage = mean(r) * sqrt(12)
>         result[4, i] = annualizedVolatility = sqrt(var(r))
> the AnnualizedAverage in multiplied by the sqrt(12) should this be just
> 12? and the following line of code have the standard deviation
> multiplied by the sqrt(12) or sqrt(var(r)*12)?

Joe, 

In the performance analytics functions that we had previously posted to 
this list, we use scale as a parameter to the annualized functions.  

So annualized return becomes:

prod(1 + R)^(scale/length(R)) - 1)

and Annualizeed Volatility is:

sqrt(scale)*sqrt(var(R))

scale = number of periods in a year (daily scale = 252, monthly scale = 
12 ,quarterly scale = 4)

Hope it helps.

We're working on packing all our previously released functions now, but 
writing .Rd files, standardizing parameter names and ordering, and 
collecting sample data, examples, and tests is taking time.

Regards,

  - Brian

> function (x)
> {
>     statistics = 14
>     if (is.null(dim(x))) {
>         n = 1
>         x = matrix(x, length(x))
>         result = matrix(rep(0, times = statistics), ncol = 1)
>     }
>     else {
>         n = dim(x)[2]
>         result = matrix(rep(0, times = statistics * n), ncol = n)
>     }
>     stat.names = c("Records", "paMean", "paAve", "paVola", "paSkew",
>         "paKurt", "maxDD", "TUW", "mMaxLoss", "mVaR", "mModVaR",
>         "mSharpe", "mModSharpe", "skPrice")
>     dimnames(result) = list(stat.names, dimnames(x)[[2]])
>     for (i in 1:n) {
>         r = x[, i]
>         result[1, i] = length(r)
>         result[2, i] = annualizedMean = (1 + mean(r))^12 - 1
> *        result[3, i] = annualizedAverage = mean(r) * sqrt(12)
>         result[4, i] = annualizedVolatility = sqrt(var(r))
> *        result[5, i] = annualizedSkewness = skewness(r)
>         result[6, i] = annualizedKurtosis = kurtosis(r)
>         result[7, i] = maxDrawdown = max(cummax(cumsum(r)) -
>             cumsum(r))
>         result[8, i] = timeUnderWater =
> max(diff(which(diff(cummax(cumsum(r))) !=
>             0)))
>         result[9, i] = maxMonthlyLoss = min(r)
>         zc = 2.33
>         result[10, i] = monthlyVaR = annualizedMean - zc *
> annualizedVolatility
>         p = 0.99
>         s = annualizedSkewness
>         k = annualizedKurtosis
>         zcf = zc + (zc * zc - 1) * s/6 + zc * (zc * zc - 3) *
>             k/24 + zc * (2 * zc * zc - 5) * s * s/36
>         result[11, i] = monthlyModVaR = annualizedMean - zcf *
>             annualizedVolatility
>         result[12, i] = monthlySharpeRatio =
> annualizedMean/annualizedVolatility
>         result[13, i] = monthlyModSharpeRatio =
> annualizedMean/monthlyModVaR result[14, i] = skewnesskurtosisPrice =
> annualizedMean * (monthlyModVaR/monthlyVaR - 1)
>     }
>     ans = as.data.frame(round(result, digits = 3))
>     ans
> }
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance

-- 
773-459-4973 mobile
http://braverock.com/brian/resume-quant.pdf



More information about the R-SIG-Finance mailing list