R/StdDev.R
StdDev.Rdcalculates Standard Deviation for univariate and multivariate series, also calculates component contribution to standard deviation of a portfolio
a vector, matrix, data frame, timeSeries or zoo object of asset returns
any other passthru parameters
method for data cleaning through Return.clean.
Current options are "none", "boudt", "geltner", or "locScaleRob".
one of "single","component" defining whether to do univariate/multivariate or component calc, see Details.
portfolio weighting vector, default NULL, see Details
If univariate, mu is the mean of the series. Otherwise mu is the vector of means of the return series , default NULL, , see Details
If univariate, sigma is the variance of the series. Otherwise sigma is the covariance matrix of the return series , default NULL, see Details
an optional character string giving a method for computing
covariances in the presence of missing values. This must be (an
abbreviation of) one of the strings "everything", "all.obs",
"complete.obs", "na.or.complete", or
"pairwise.complete.obs".
a character string indicating which correlation coefficient
(or covariance) is to be computed. One of "pearson" (default),
"kendall", or "spearman", can be abbreviated.
TRUE/FALSE whether to ouput the standard errors of the estimates of the risk measures, default FALSE.
Control parameters for the computation of standard errors. Should be done using the RPESE.control function.
TODO add more details
This wrapper function provides fast matrix calculations for univariate, multivariate, and component contributions to Standard Deviation.
It is likely that the only one that requires much description is the component decomposition. This provides a weighted decomposition of the contribution each portfolio element makes to the univariate standard deviation of the whole portfolio.
Formally, this is the partial derivative of each univariate standard deviation with respect to the weights.
As with VaR, this contribution is presented in two forms, both
a scalar form that adds up to the univariate standard deviation of the
portfolio, and a percentage contribution, which adds up to 100
as with any contribution calculation, contribution can be negative. This
indicates that the asset in question is a diversified to the overall
standard deviation of the portfolio, and increasing its weight in relation
to the rest of the portfolio would decrease the overall portfolio standard
deviation.
Return.clean sd
# \donttest{
data(edhec)
# first do normal StdDev calc
StdDev(edhec)
#> Convertible Arbitrage CTA Global Distressed Securities Emerging Markets
#> StdDev 0.01676221 0.02278814 0.01814467 0.03270967
#> Equity Market Neutral Event Driven Fixed Income Arbitrage Global Macro
#> StdDev 0.008208647 0.01907188 0.01145756 0.01462496
#> Long/Short Equity Merger Arbitrage Relative Value Short Selling
#> StdDev 0.02090324 0.01147821 0.01186841 0.04550226
#> Funds of Funds
#> StdDev 0.01608486
# or the equivalent
StdDev(edhec, portfolio_method="single")
#> Convertible Arbitrage CTA Global Distressed Securities Emerging Markets
#> StdDev 0.01676221 0.02278814 0.01814467 0.03270967
#> Equity Market Neutral Event Driven Fixed Income Arbitrage Global Macro
#> StdDev 0.008208647 0.01907188 0.01145756 0.01462496
#> Long/Short Equity Merger Arbitrage Relative Value Short Selling
#> StdDev 0.02090324 0.01147821 0.01186841 0.04550226
#> Funds of Funds
#> StdDev 0.01608486
# now with outliers squished
StdDev(edhec, clean="boudt")
#> Convertible Arbitrage CTA Global Distressed Securities Emerging Markets
#> StdDev 0.01399677 0.02278814 0.01649289 0.03081375
#> Equity Market Neutral Event Driven Fixed Income Arbitrage Global Macro
#> StdDev 0.007394652 0.01751999 0.009510082 0.01431055
#> Long/Short Equity Merger Arbitrage Relative Value Short Selling
#> StdDev 0.0205263 0.01037732 0.01059619 0.0435232
#> Funds of Funds
#> StdDev 0.01589405
# add Component StdDev for the equal weighted portfolio
StdDev(edhec, clean="boudt", portfolio_method="component")
#> no weights passed in, assuming equal weighted portfolio
#> $StdDev
#> [1] 0.01016549
#>
#> $contribution
#> Convertible Arbitrage CTA Global Distressed Securities
#> 0.0008134515 0.0006489133 0.0010437732
#> Emerging Markets Equity Market Neutral Event Driven
#> 0.0019206079 0.0004275764 0.0011767665
#> Fixed Income Arbitrage Global Macro Long/Short Equity
#> 0.0005332522 0.0009011841 0.0012966454
#> Merger Arbitrage Relative Value Short Selling
#> 0.0005773683 0.0007041049 -0.0009687674
#> Funds of Funds
#> 0.0010906127
#>
#> $pct_contrib_StdDev
#> Convertible Arbitrage CTA Global Distressed Securities
#> 0.08002089 0.06383493 0.10267811
#> Emerging Markets Equity Market Neutral Event Driven
#> 0.18893414 0.04206157 0.11576093
#> Fixed Income Arbitrage Global Macro Long/Short Equity
#> 0.05245712 0.08865133 0.12755366
#> Merger Arbitrage Relative Value Short Selling
#> 0.05679691 0.06926425 -0.09529964
#> Funds of Funds
#> 0.10728581
#>
# } # end CRAN check