Econometric Tools for Performance and Risk Analysis

Collection of econometric functions for performance and risk analysis. This package aims to aid practitioners and researchers in utilizing the latest research in analysis of non-normal return streams. In general, it is most tested on return (rather than price) data on a regular scale, but most functions will work with irregular return data as well, and increasing numbers of functions will work with P&L or price data where possible.


PerformanceAnalytics provides an R package of econometric functions for performance and risk analysis of financial instruments or portfolios. This package aims to aid practitioners and researchers in using the latest research for analysis of both normally and non-normally distributed return streams.

We created this package to include functionality that has been appearing in the academic literature on performance analysis and risk over the past several years, but had no functional equivalent in R. In doing so, we also found it valuable to have wrappers for some functionality with good defaults and naming consistent with common usage in the finance literature.

In general, this package requires return (rather than price) data. Almost all of the functions will work with any periodicity, from annual, monthly, daily, to even minutes and seconds, either regular or irregular.

The package documentation includes sections on

  • Time Series Data
  • Performance Analysis
  • Style Analysis
  • Risk Analysis
  • Value at Risk - VaR
  • Moments and Co-moments
  • Robust Data Cleaning
  • Summary Tabular Data
  • Charts and Graphs
  • Wrapper and Utility Functions

It also includes some thoughts on work yet to be done, acknowledgments, and pointers to other literature and resources in R useful for performance and risk analysis,

Some sample data is provided in the managers dataset. It is an xts object that contains columns of monthly returns for six hypothetical asset managers (HAM1 through HAM6), the EDHEC Long-Short Equity hedge fund index, the S&P 500 total returns, and total return series for the US Treasury 10-year bond and 3-month bill. Monthly returns for all series end in December 2006 and begin at different periods starting from January 1996. That data set is used extensively in our examples and should serve as a model for formatting your data.

News

PerformanceAnalytics 1.5 Release Notes

The major functional change in v1.5 is in the higher moment code. Dries Cornilly of Belgium contributed sparse matrix code in GSoC 2017 to make calcualtion of higher moments and comonments much faster and more robust.

Additionally, PerformanceAnalytics has been updated to use the new plot.xts, which should signficiantly decrease the amount of maintenance required, and increase the flexibility in plotting. Thanks to Eric Hung for that GSoC work.

PerformanceAnalytics moved to github in 2016 after the release of v1.4 https://github.com/braverock/PerformanceAnalytics

Most of the commits leading up to release are the result of continued tightening and drift in CRAN standards, most should not have user-visible results.

... and the usual minor things that get changed and updated in the general course of maintenance.

PerformanceAnalytics 1.4 Release Notes

We've completely re-written Return.portfolio to make more of the internals available for those who have the need to disassemble the various components of the portfolio return. Return.portfolio and Return.rebalancing are now the same function, with Return.portfolio being preferred for new code.

This release also adds some functionality from Bacon, and makes visible some functions that were previously internal to the package.

We've moved to using roxygen2 to generate the NAMESPACE file, which required touching basically every single generated .Rd file.

We're also altering our version numbering system. We'll be using a "major.cran-release.r-forge-rev" form to make it easier for us to track where reported issues may have been introduced. Major releases will continue to indicate that significant changes to the interfaces of the functions were made. This is our 4th CRAN release after 1.0, so the minor number moves to 4. The trailing number will reflect the revision number from R-Forge's svn associated with the tagged CRAN (or subsequent) release.

Most of the commits leading up to release are the result of continued tightening and drift in CRAN standards, most should not have user-visible results.

... and the usual minor things that get changed and updated in the general course of maintenance.

PerformanceAnalytics 1.1 Release Notes

Another release almost exclusively based on R core changes ahead of R 3.0.0.

Most of the commits leading up to release are the result of continued tightening and drift in CRAN standards, most should not have user-visible results.

... and the usual minor things that get changed and updated in the general course of maintenance.

PerformanceAnalytics 1.0.4.3 Release Notes (sent to CRAN 2012-03-29)

This release is aimed almost exclusively at support for multiple changes made to deal with R core changes, especially in the areas of multi-column support for sd() and mean(). User functionality should be unchanged.

... and the usual minor things that get changed and updated in the general course of maintenance.

PerformanceAnalytics roxygen note (2011-10-02): We're converting the documentation to use roxygen2. If you find any errors or omissions from previous documentation, please notify us.
We will shift to roxygen documentation with package v1.1

PerformanceAnalytics 1.0.3.1 Release Notes

A change to the behavior of as.xts removed functionality relied on by PerformanceAnalytics in checkData. Thanks to debugging help from Jeff Ryan and a one-line patch, everything should work as expected back through current and older xts versions.

... and the usual minor things that get changed and updated in the general course of maintenance.

PerformanceAnalytics 1.0.3 Release Notes (sent to CRAN 2010-08-04)

This is an incremental bugfix and improvement release on the v1.0.x cycle.

We would like to acknowledge feedback and suggestions from Giuseppe Milicia and Murali Menon which have resulted in changes or improvements to several functions in this release, mostly to eliminate problems with edge cases or specific failure modes.

Style functions have been removed in this release and moved to the new project FactorAnalytics with Eric Zivot on R-Forge.

... and the usual minor things that get changed and updated in the general course of maintenance.

PerformanceAnalytics 1.0.2 Release Notes (released to CRAN 2010-04-08)

This release is an incremental improvement on v1.0.x

We've continued to make functions more friendly for use in parallel execution and optimization environments.

Several bugfixes have been applied to edge case problems, details are in the full ChangeLog provided with the package.

We've added several new ways of calling functions that can take moments rather than returns to allow for more robust or other improved methods of calculating moments.

Added patches to graphics provided by Dominik Locher.

... and the usual minor things that get changed and updated in the general course of maintenance.

PerformanceAnalytics 1.0.1 Release Notes (tagged 2010-01-07, not released to CRAN)

This release is predominantly a minor bugfix release.

We've reduced the number of warning() calls throughout the code to better allow for execution in a highly parallel environment.

We've fixed bugs related to assuming compounding/geometric returns in all functions that could be affected by such assumptions.

Bugs related to handling matrices pointed out by Dr. Stefan Albrecht have been removed.

... and the usual minor things that get changed and updated in the general course of maintenance.

PerformanceAnalytics 1.0.0 Release Notes (released to CRAN 2009-10-27)

This release marks a major milestone for PerformanceAnalytics. After several years and acquiring users worldwide, we feel things are stable enough to mark this release 1.0.0. Hopefully this will decrease the number of changes made to the interfaces and functionality of the package in the future, and let us work on other things.

Probably the most new functionality in this release has gone into VaR, ES and modified VaR and ES. Thanks to some excellent code and research contributions from Kris Boudt of K.U. Leuven, we've added substantially to the capabilities in this release. The new 'VaR' and 'ES' functions allow a wide variety of methods for calculation, and even methods for calculating risk contribution given portfolio weights. This is great stuff, and we're deeply greatful for Kris' contribution.

During the past year, we've modified almost every function in the package. There were two things we wanted to accomplish: move to xts for time series functions internally, and improve the speed and convenience of the functions.

The move to xts has improved the package immensely. Not only have the time axes of the graphics improved, but calculations and charts now handle different data periodicities automatically. Calculations are noticably faster, too.

Users of fPortfolio and other Rmetrics packages can use timeSeries objects with PA functions seamlessly. Thanks to xts' reclass function, if you input a timeSeries object into a PA function that calculates a time series result (such as Drawdowns), that result is delivered as a timeSeries classed object.

All of the functions in PA now support multi-column returns objects. Drop a data set in, and the calculations are done for each column. For example:

data(managers) SharpeRatio.annualized(managers[,1:8]) HAM1 HAM2 HAM3 HAM4 HAM5 HAM6 1.6033616 1.3240442 1.1488361 0.6169326 0.1933374 1.8380958 EDHEC.LS.EQ SP500.TR 1.6414220 0.6448502

In any re-write like this, there's good news and bad news. The bad news is that there have been changes to parameter names along the way. The most substantial of these is anywhere we used 'rf' for the risk free rate, we now use Rf. We've made the changes to be more consistent and make the code easier to maintain, and we appreciate your patience.

PerformanceAnalytics v0.9.7 Release Notes (released to CRAN 2008-10-12)

New Functionality:

This release adds 39 new public functions, an example dataset, and utilizes R's namespace capability. We have also decreased the number of "Requires" packages to just "zoo", moving the rest to "Suggests" and loading them only when needed, with a warning or error (as appropriate) if they are not available. This should lower both loading time and the memory footprint of using PerformanceAnalytics.

Risk functionality

    We have extended the risk metrics provided by
    Performanceanalytics to include multivariate portfolio measures
    of Gaussian and Cornish fisher VaR and Expected Shortfall.

    Functions:
    * GES.MM
    * GVaR.MM 
    * mES.MM
    * mVaR.MM 

Modified Sharpe Ratios

    Earlier versions of PerformanceAnalytics contained the modified
    Sharpe Ration based on the Cornish fisher expansion.  we have
    added additional modified Sharpe ratios to calculate portfolio
    ratios for both Gaussian and modified Cornish Fisher Var and
    Expected Shortfall of the multivariate portfolio distribution.
    Functions:
    * SR.GES.MM
    * SR.GVaR.MM
    * SR.mES.MM
    * SR.mVaR.MM
    * SR.StdDev.MM

    TODO: need to wrap the SharpeRatio function to take a "method"
    argument and return one or all.

Style Analysis

    We are happy to announce that style analysis, long a goal of this
    package, has made significant progress in this release, with the
    addition of four new functions.

    These functions calculate style weights using an asset class
    style model as described in detail in Sharpe (1992).  The use of
    quadratic programming to determine a fund's exposures to the
    changes in returns of major asset classes is usually referred to
    as "style analysis".

    Functions: 
    * chart.RollingStyle
           calculates and displays those weights in
           rolling windows through time.
    * chart.Style
           calculates and displays style weights calculated 
           over a single period.
    * style.fit
           manages the calculation of the factor weights by method
    * style.QPfit
           calculates the specific constraint case that requires 
           quadratic programming

Charts
    We've added three new graph functions in this release:

    chart.VaRSensitivity
        Creates a chart of Value-at-Risk estimates by confidence interval
        for multiple methods. Possibly useful for comparing a calculated
        VaR method to the historical VaR.

    chart.SnailTrail
        A scatter chart that shows how rolling calculations of annualized
        return and annualized standard deviation have proceeded through
        time.  The color of lines and dots on the chart diminishes with
        respect to time. May be helpful for showing the trend of the
        return/risk characteristics of the fund over time.

    chart.StackedBar
        This creates a stacked column chart with time on the horizontal
        axis and values in categories.  This kind of chart is commonly
        used for showing portfolio 'weights' through time, although the
        function will plot any values by category.  This is a primitive
        function and is expected to improve.

Moments of a distribution

    We have added several functions to calculate standardized moments
    and multivariate moments of an asset or multivariate portfolio
    distribution.  When working with multivariate series, the joint
    distribution of the returns is to be preferred over the simple
    univariate distribution of the resulting return vector of a
    portfolio.  Once the multivariate moments are available, it is
    possible to compute the comoments, comoment matrices, and beta or
    systematic comoments.

    skewness
    kurtosis
    skewness.MM
    kurtosis.MM
        We've ported and reimplemented skewness and kurtosis from
        Rmetrics to allow for additional data classes as well as
        multivariate series.

    StdDev.MM
    multivariate_mean
    Return.centered
    M3.MM
    M4.MM
        We've additionally implemented the multivariate moment
        calculations for the first two portfolio moments (mean and
        standard deviation) as well as the third and forth mathematical
        moments.

    CoVariance
    CoKurtosis
    CoSkewness
        Calculates the covariance, coskewness. or cokurtosis of one asset
        with relation to another (scalar measure) utilizing the
        standardized central mathematical moments of the distribution.

    CoKurtosisMatrix
    CoSkewnessMatrix
        Calculates the N x N2 co-moment matrix of assets to one another,
        can be utilized in a portfolio context.  This is a complete
        reimplementation of the prior functions in PerformanceAnalytics
        to calculate moments, and has been validated by our research work
        as superior to the prior implementation.

    centeredmoment
    centeredcomoment
        Used internally by PerformanceAnalytics to calculate centered
        moments for a multivariate distribution as well as the
        standardized moments of a portfolio distribution.  They are
        exposed here for users who wish to use them directly

    BetaCoVariance
    BetaCoSkewness
    BetaCoKurtosis
        Calculates the systematic or beta comoment of two assets or an
        asset versus a portfolio. used to assess diversification
        potential in a portfolio, or in multivariate multimoment
        portfolio optimization.

Significant Changes to existing functions:

chart.BarVaR
    * Incorporates 'Return.clean' methods for using cleaning methods
      when charting forecasted VaR values.  
    * Handles multiple columns OR multiple VaR calculation methods
    * Can show cleaned returns overlaid on original data
    * Added horizontal line to show exceedences to most recent risk
      estimate

Co-moments and Beta/Systematic Co-moments have been completely
reimplemented, and are discussed above.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("PerformanceAnalytics")

1.5.2 by Brian G. Peterson, a year ago


https://github.com/braverock/PerformanceAnalytics


Browse source code at https://github.com/cran/PerformanceAnalytics


Authors: Brian G. Peterson [cre, aut, cph] , Peter Carl [aut, cph] , Kris Boudt [ctb, cph] , Ross Bennett [ctb] , Joshua Ulrich [ctb] , Eric Zivot [ctb] , Dries Cornilly [ctb] , Eric Hung [ctb] , Matthieu Lestel [ctb] , Kyle Balkissoon [ctb] , Diethelm Wuertz [ctb]


Documentation:   PDF Manual  


Task views: Empirical Finance


GPL-2 | GPL-3 license


Imports methods, quadprog, zoo

Depends on xts

Suggests dygraphs, Hmisc, MASS, quantmod, gamlss, gamlss.dist, robustbase, quantreg, gplots, testthat


Imported by RobStatTM, SMNCensReg, Semblance, portfolioBacktest, scRNAtools, tawny, tbl2xts.

Depended on by PortfolioAnalytics, tidyquant.

Suggested by Dowd, cvar, pbo, portsort, timeSeries.


See at CRAN