Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Version 1.01 of BurStFin is now on CRAN.
It is written entirely in R, and meant to be compatible with S+.
Functionality
The package is aimed at quantitative finance, but the variance estimation functions could be of use in other applications as well.
Also of general interest is threeDarr which creates a three-dimensional array out of matrices.
Variance estimation
The most important functions in the package are:
- var.shrink.eqcor to estimate a variance matrix using Ledoit-Wolf shrinkage towards equal correlation.
- factor.model.stat to create a statistical factor model of a variance matrix
Both of these functions can estimate variances when there are more variables (assets in finance) than observations. Both of them also allow missing values in the input.
The tawny package has a function for Ledoit-Wolf shrinkage but it does not allow missing values. Also in tawny
is a function to estimate variance based on random matrix theory.
Variance manipulation
- var.add.benchmark takes a variance matrix plus a named vector of weights and returns a variance matrix with the additional asset which is the linear combination of the existing assets given by the weight vector.
- var.relative.benchmark takes a variance matrix and returns a variance matrix of one less asset that is the variance relative to the dropped asset.
Both of these functions allow the variance to be a three-dimensional array representing multiple variance matrices.
Other
- threeDarr takes one or more matrices and creates a three-dimensional array out of them.
- alpha.proxy shows the effect that volatility and correlation have on the utility of an investor in a certain setting.
Changes
threeDarr is new to the package. It was written to streamline some tasks with Portfolio Probe, but is of general use.
By default there is now a warning in both var.shrink.eqcor and factor.model.stat if the input x is all non-negative. This asks the question: Were prices accidentally given rather than returns?
There is now a sum.to.one
argument to var.add.benchmark
which can be set to FALSE
if the “benchmark” is something with weights that do not sum to one. The use case that prompted this was a vector of portfolio weights minus benchmark weights.
Research projects
The estimation of variance matrices in finance is (perhaps amazingly) not especially well researched. The functionality in this package suggests several questions that would be nice to have answered:
- When is Ledoit-Wolf shrinkage better than a factor model (or anything else). This is explored a little in some blog posts.
- What is the best way to handle missing values? This occurs, for example, when stocks did not exist for the entire historical period. Is it different for different estimation techniques? The application does matter — what you should shrink toward is different with or without a benchmark, for instance.
- What is the best time weighting to use? Is it different for different estimation techniques? Is it different for different applications?
Getting it
R: 2.13 and 2.14 on Windows
It is on CRAN, so you can just do:
install.packages("BurStFin")
This will also be the way to get it for new versions of R and/or BurStFin.
R: older versions on Windows
The 2.14 build is spread around the Burns Statistics repository. So you can do:
install.packages("BurStFin", repos="http://www.burns-stat.com/R")
The help doesn’t work for older versions (because of changes in the help system), but the code is fine.
R: on other platforms
CRAN looks to have builds for 2.14 on Linux, MacOS and Solaris. And of course it has the source.
S+
You can browse to http://www.burns-stat.com/Splus/BurStFin where you will find a dot-q file of the code that can be sourced, and a pdf of the help files.
Subscribe to the Portfolio Probe blog by Email
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.