The BurStFin R package

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

This entry was posted in Quant finance, R language and tagged , , , . Bookmark the permalink.

9 Responses to The BurStFin R package

  1. Pingback: Alpha alignment | Portfolio Probe | Generate random portfolios. Fund management software by Burns Statistics

  2. Pingback: Popular posts 2012 March | Portfolio Probe | Generate random portfolios. Fund management software by Burns Statistics

  3. Pingback: What does ‘passive investing’ really mean? | Portfolio Probe | Generate random portfolios. Fund management software by Burns Statistics

  4. Pingback: Correlations and postive-definiteness | Portfolio Probe | Generate random portfolios. Fund management software by Burns Statistics

  5. Pingback: Popular posts 2012 June | Portfolio Probe | Generate random portfolios. Fund management software by Burns Statistics

  6. Pingback: Popular posts 2012 April | Portfolio Probe | Generate random portfolios. Fund management software by Burns Statistics

  7. Pingback: How to add a benchmark to a variance matrix | Portfolio Probe | Generate random portfolios. Fund management software by Burns Statistics

  8. My partner and I absolutely love your blog and find many of your post’s to be just what I’m looking for.
    can you offer guest writers to write content to suit your needs?

    I wouldn’t mind publishing a post or elaborating on most of
    the subjects you write regarding here. Again, awesome site!

    Also visit my blog … tv buying guide

  9. Sherlyn says:

    I do not know if it’s just me or if perhaps everybody else encountering problems with your website.
    It appears like some of the text on your content are running off the screen. Can someone else please comment and let me know
    if this is happening to them too? This could be
    a issue with my web browser because I’ve had this happen before.
    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *