├── .Rbuildignore ├── ChangeLog ├── ChangeLog.1.0.0 ├── DESCRIPTION ├── NAMESPACE ├── NEWS ├── R ├── ActivePremium.R ├── AdjustedSharpeRatio.R ├── AppraisalRatio.R ├── BernadoLedoitratio.R ├── BurkeRatio.R ├── CAPM.alpha.R ├── CAPM.beta.R ├── CAPM.dynamic.R ├── CAPM.epsilon.R ├── CAPM.jensenAlpha.R ├── CAPM.utils.R ├── CalmarRatio.R ├── CoMoments.R ├── DRatio.R ├── DownsideDeviation.R ├── DownsideFrequency.R ├── DrawdownPeak.R ├── Drawdowns.R ├── ES.R ├── FamaBeta.R ├── Frequency.R ├── HerfindahlIndex.R ├── HurstIndex.R ├── InformationRatio.R ├── Kappa.R ├── KellyRatio.R ├── M2Sortino.R ├── MSquared.R ├── MSquaredExcess.R ├── MarketTiming.R ├── MartinRatio.R ├── MeanAbsoluteDeviation.R ├── Modigliani.R ├── MultivariateMoments.R ├── NetSelectivity.R ├── Omega.R ├── OmegaExcessReturn.R ├── OmegaSharpeRatio.R ├── PainIndex.R ├── PainRatio.R ├── PortfolioRisk.R ├── ProspectRatio.R ├── Return.Geltner.R ├── Return.annualized.R ├── Return.annualized.excess.R ├── Return.calculate.R ├── Return.clean.R ├── Return.cumulative.R ├── Return.excess.R ├── Return.portfolio.R ├── Return.read.R ├── Return.relative.R ├── Selectivity.R ├── SemiDeviation.R ├── SharpeRatio.R ├── SharpeRatio.annualized.R ├── SkewnessKurtosisRatio.R ├── SmoothingIndex.R ├── SortinoRatio.R ├── SpecificRisk.R ├── StdDev.R ├── StdDev.annualized.R ├── SystematicRisk.R ├── TotalRisk.R ├── TrackingError.R ├── TreynorRatio.R ├── UlcerIndex.R ├── UpDownRatios.R ├── UpsideFrequency.R ├── UpsidePotentialRatio.R ├── UpsideRisk.R ├── VaR.Marginal.R ├── VaR.R ├── VolatilitySkewness.R ├── apply.fromstart.R ├── apply.rolling.R ├── chart.ACF.R ├── chart.ACFplus.R ├── chart.Bar.R ├── chart.BarVaR.R ├── chart.Boxplot.R ├── chart.CaptureRatios.R ├── chart.Correlation.R ├── chart.CumReturns.R ├── chart.Drawdown.R ├── chart.ECDF.R ├── chart.Events.R ├── chart.Histogram.R ├── chart.QQPlot.R ├── chart.Regression.R ├── chart.RelativePerformance.R ├── chart.RiskReturnScatter.R ├── chart.RollingCorrelation.R ├── chart.RollingMean.R ├── chart.RollingPerformance.R ├── chart.RollingQuantileRegression.R ├── chart.RollingRegression.R ├── chart.Scatter.R ├── chart.SnailTrail.R ├── chart.StackedBar.R ├── chart.TimeSeries.R ├── chart.VaRSensitivity.R ├── charts.Bar.R ├── charts.BarVaR.R ├── charts.PerformanceSummary.R ├── charts.RollingPerformance.R ├── charts.RollingRegression.R ├── charts.TimeSeries.R ├── checkData.R ├── decomposeMVaR.R ├── expectedShortFallFunctions.r ├── findDrawdowns.R ├── kurtosis.R ├── legend.R ├── lpm.R ├── maxDrawdown.R ├── mean.utils.R ├── na.skip.R ├── rCornishFisher.r ├── replaceTabs.R ├── skewness.R ├── sortDrawdowns.R ├── table.AnnualizedReturns.R ├── table.Arbitrary.R ├── table.Autocorrelation.R ├── table.CAPM.R ├── table.CalendarReturns.R ├── table.CaptureRatios.R ├── table.Correlation.R ├── table.Distributions.R ├── table.DownsideRisk.R ├── table.DownsideRiskRatio.R ├── table.Drawdowns.R ├── table.DrawdownsRatio.R ├── table.HigherMoments.R ├── table.InformationRatio.R ├── table.MonthlyReturns.R ├── table.RollingPeriods.R ├── table.SpecificRisk.R ├── table.UpDownRatios.R ├── table.Variability.R ├── textplot.R ├── valueAtRiskFunctions.r ├── zerofill.R └── zzz.R ├── codeblock.txt ├── data ├── edhec.csv ├── edhec.rda ├── managers.csv ├── managers.rda ├── portfolio_bacon.csv ├── portfolio_bacon.rda ├── prices.rda └── weights.rda ├── generatechangelog.sh ├── man ├── ActivePremium.Rd ├── AdjustedSharpeRatio.Rd ├── AppraisalRatio.Rd ├── AverageDrawdown.Rd ├── BernardoLedoitRatio.Rd ├── BetaCoMoments.Rd ├── BurkeRatio.Rd ├── CAPM.RiskPremium.Rd ├── CAPM.alpha.Rd ├── CAPM.beta.Rd ├── CAPM.dynamic.Rd ├── CAPM.epsilon.Rd ├── CAPM.jensenAlpha.Rd ├── CDD.Rd ├── CalmarRatio.Rd ├── CoMoments.Rd ├── DRatio.Rd ├── DownsideDeviation.Rd ├── DownsideFrequency.Rd ├── DrawdownDeviation.Rd ├── DrawdownPeak.Rd ├── ES.Rd ├── FamaBeta.Rd ├── Frequency.Rd ├── HurstIndex.Rd ├── InformationRatio.Rd ├── Kappa.Rd ├── KellyRatio.Rd ├── M2Sortino.Rd ├── MSquared.Rd ├── MSquaredExcess.Rd ├── MarketTiming.Rd ├── MartinRatio.Rd ├── MeanAbsoluteDeviation.Rd ├── Modigliani.Rd ├── NetSelectivity.Rd ├── Omega.Rd ├── OmegaExcessReturn.Rd ├── OmegaSharpeRatio.Rd ├── PainIndex.Rd ├── PainRatio.Rd ├── PerformanceAnalytics-package.Rd ├── ProspectRatio.Rd ├── Return.Geltner.Rd ├── Return.annualized.Rd ├── Return.annualized.excess.Rd ├── Return.calculate.Rd ├── Return.clean.Rd ├── Return.cumulative.Rd ├── Return.excess.Rd ├── Return.portfolio.Rd ├── Return.read.Rd ├── Return.relative.Rd ├── Selectivity.Rd ├── SharpeRatio.Rd ├── SharpeRatio.annualized.Rd ├── SkewnessKurtosisRatio.Rd ├── SmoothingIndex.Rd ├── SortinoRatio.Rd ├── SpecificRisk.Rd ├── StdDev.Rd ├── StdDev.annualized.Rd ├── SystematicRisk.Rd ├── TotalRisk.Rd ├── TrackingError.Rd ├── TreynorRatio.Rd ├── UlcerIndex.Rd ├── UpDownRatios.Rd ├── UpsideFrequency.Rd ├── UpsidePotentialRatio.Rd ├── UpsideRisk.Rd ├── VaR.Rd ├── VolatilitySkewness.Rd ├── apply.fromstart.Rd ├── apply.rolling.Rd ├── centeredmoments.Rd ├── chart.ACF.Rd ├── chart.Bar.Rd ├── chart.BarVaR.Rd ├── chart.Boxplot.Rd ├── chart.CaptureRatios.Rd ├── chart.Correlation.Rd ├── chart.CumReturns.Rd ├── chart.Drawdown.Rd ├── chart.ECDF.Rd ├── chart.Events.Rd ├── chart.Histogram.Rd ├── chart.QQPlot.Rd ├── chart.Regression.Rd ├── chart.RelativePerformance.Rd ├── chart.RiskReturnScatter.Rd ├── chart.RollingCorrelation.Rd ├── chart.RollingMean.Rd ├── chart.RollingPerformance.Rd ├── chart.RollingRegression.Rd ├── chart.Scatter.Rd ├── chart.SnailTrail.Rd ├── chart.StackedBar.Rd ├── chart.TimeSeries.Rd ├── chart.VaRSensitivity.Rd ├── charts.PerformanceSummary.Rd ├── charts.RollingPerformance.Rd ├── checkData.Rd ├── clean.boudt.Rd ├── edhec.Rd ├── findDrawdowns.Rd ├── kurtosis.Rd ├── legend.Rd ├── lpm.Rd ├── managers.Rd ├── maxDrawdown.Rd ├── mean.geometric.Rd ├── portfolio_bacon.Rd ├── prices.Rd ├── skewness.Rd ├── sortDrawdowns.Rd ├── table.AnnualizedReturns.Rd ├── table.Arbitrary.Rd ├── table.Autocorrelation.Rd ├── table.CAPM.Rd ├── table.CalendarReturns.Rd ├── table.CaptureRatios.Rd ├── table.Correlation.Rd ├── table.Distributions.Rd ├── table.DownsideRisk.Rd ├── table.DownsideRiskRatio.Rd ├── table.Drawdowns.Rd ├── table.DrawdownsRatio.Rd ├── table.HigherMoments.Rd ├── table.InformationRatio.Rd ├── table.MonthlyReturns.Rd ├── table.RollingPeriods.Rd ├── table.SpecificRisk.Rd ├── table.Variability.Rd ├── textplot.Rd ├── weights.Rd └── zerofill.Rd ├── sandbox ├── Benford.R ├── PAenhance │ ├── R │ │ ├── chart.Boxplot.R │ │ └── chart.QQplot.R │ ├── inst │ │ ├── PA-KirkLi.Rnw │ │ └── PA-KirkLi.pdf │ └── man │ │ ├── chart.Boxplot.Rd │ │ └── chart.QQPlot.Rd ├── Return.wealthindex.R ├── Shubhankit │ ├── noniid.sm │ │ ├── .Rbuildignore │ │ ├── DESCRIPTION │ │ ├── NAMESPACE │ │ ├── R │ │ │ ├── ACStdDev.annualized.R │ │ │ ├── CDrawdown.R │ │ │ ├── CalmarRatio.Norm.R │ │ │ ├── EmaxDDGBM.R │ │ │ ├── GLMSmoothIndex.R │ │ │ ├── LoSharpe.R │ │ │ ├── QP.Norm.R │ │ │ ├── Return.GLM.R │ │ │ ├── Return.Okunev.R │ │ │ ├── SterlingRatio.Norm.R │ │ │ ├── UnsmoothReturn.R │ │ │ ├── chart.AcarSim.R │ │ │ ├── chart.Autocorrelation.R │ │ │ ├── glmi.R │ │ │ ├── lmi.R │ │ │ ├── na.skip.R │ │ │ ├── noniid.sm-internal.R │ │ │ ├── se.LoSharpe.R │ │ │ ├── table.ComparitiveReturn.GLM.R │ │ │ ├── table.EMaxDDGBM.R │ │ │ ├── table.Sharpe.R │ │ │ ├── table.UnsmoothReturn.R │ │ │ └── table.normDD.R │ │ ├── man │ │ │ ├── ACStdDev.annualized.Rd │ │ │ ├── AcarSim.Rd │ │ │ ├── CalmarRatio.Norm.Rd │ │ │ ├── Cdrawdown.Rd │ │ │ ├── EMaxDDGBM.Rd │ │ │ ├── GLMSmoothIndex.Rd │ │ │ ├── LoSharpe.Rd │ │ │ ├── QP.Norm.Rd │ │ │ ├── Return.GLM.Rd │ │ │ ├── Return.Okunev.Rd │ │ │ ├── SterlingRatio.Norm.Rd │ │ │ ├── UnSmoothReturn.Rd │ │ │ ├── chart.AcarSim.Rd │ │ │ ├── chart.Autocorrelation.Rd │ │ │ ├── glmi.Rd │ │ │ ├── lmi.Rd │ │ │ ├── se.LoSharpe.Rd │ │ │ ├── table.ComparitiveReturn.GLM.Rd │ │ │ ├── table.EMaxDDGBM.Rd │ │ │ ├── table.Sharpe.Rd │ │ │ ├── table.UnsmoothReturn.Rd │ │ │ └── table.normDD.Rd │ │ ├── noniid.sm.Rproj │ │ ├── tests │ │ │ └── Examples │ │ │ │ ├── noniid.sm-Ex.R │ │ │ │ ├── noniid.sm-Ex.Rout │ │ │ │ └── noniid.sm-Ex.pdf │ │ └── vignettes │ │ │ ├── Non-iid-ACFSTDEV.pdf │ │ │ ├── Non-iid-ACFSTDEV.rnw │ │ │ ├── Non-iid-ConditionalDrawdown.Rnw │ │ │ ├── Non-iid-ConditionalDrawdown.pdf │ │ │ ├── Non-iid-EmaxDDGBM.Rnw │ │ │ ├── Non-iid-EmaxDDGBM.pdf │ │ │ ├── Non-iid-GLMReturn.Rnw │ │ │ ├── Non-iid-GLMReturn.pdf │ │ │ ├── Non-iid-GLMSmoothIndex.Rnw │ │ │ ├── Non-iid-GLMSmoothIndex.pdf │ │ │ ├── Non-iid-LoSharpeRatio.Rnw │ │ │ ├── Non-iid-LoSharpeRatio.pdf │ │ │ ├── Non-iid-Managers.Rnw │ │ │ ├── Non-iid-Managers.pdf │ │ │ ├── Non-iid-NormCalmar-Sterling.pdf │ │ │ ├── Non-iid-NormCalmar-Sterling.rnw │ │ │ ├── Non-iid-OWReturn.Rnw │ │ │ ├── Non-iid-OWReturn.pdf │ │ │ ├── Non-iid-OkunevWhite.Rnw │ │ │ ├── Non-iid-OkunevWhite.pdf │ │ │ ├── Non-iid-ShaneAcarMaxLoss.Rnw │ │ │ ├── Non-iid-ShaneAcarMaxLoss.pdf │ │ │ ├── Non-iid-UnSmoothReturnAnalysis.Rnw │ │ │ └── Non-iid-UnSmoothReturnAnalysis.pdf │ ├── noniid.sm_0.1.zip │ └── sandbox │ │ ├── Week6-7 │ │ ├── Code │ │ │ ├── Covariance Matrix Integrated Regression Function │ │ │ │ ├── glmi.R │ │ │ │ ├── lmi.R │ │ │ │ └── nlsi.R │ │ │ ├── Data │ │ │ │ ├── Investment.csv │ │ │ │ ├── PublicSchools.csv │ │ │ │ ├── RealInt.csv │ │ │ │ └── ps.csv │ │ │ ├── Equivalent Matlab Code │ │ │ │ ├── NWmissings.m │ │ │ │ ├── effort.dat │ │ │ │ ├── nwse.m │ │ │ │ ├── regstats2.m │ │ │ │ └── sim_NWmissings.m │ │ │ └── Tests │ │ │ │ ├── Cross Sectional Data.R │ │ │ │ ├── HAC Data.R │ │ │ │ ├── Tests.R │ │ │ │ └── Time Series Data.R │ │ ├── Literature │ │ │ ├── Thumbs.db │ │ │ ├── Zelisis.pdf │ │ │ └── sandwich-OOP.pdf │ │ ├── Vignette │ │ │ ├── HACintegrated-hac-kweights.pdf │ │ │ ├── HACintegrated-hac-plot.pdf │ │ │ ├── HACintegrated-hc-plot.pdf │ │ │ ├── HACintegrated.Rnw │ │ │ ├── HACintegrated.log │ │ │ ├── HACintegrated.tex │ │ │ ├── Test_Report.Rnw │ │ │ └── Test_Report.pdf │ │ └── lmi.R │ │ └── vignettes │ │ ├── ACFSTDEV.rnw │ │ ├── AcarSim.R │ │ ├── Cheklov.CDDOpt.Rnw │ │ ├── Commodity.Rnw │ │ ├── CommodityReport.Rnw │ │ ├── Commodity_ResearchReport.Rnw │ │ ├── ConditionalDrawdown.Rnw │ │ ├── GLMReturn.Rnw │ │ ├── GLMSmoothIndex.Rnw │ │ ├── LoSharpe.Rnw │ │ ├── Managers.Rnw │ │ ├── Managers.pdf │ │ ├── MaximumLoss.Rnw │ │ ├── NormCalmar.rnw │ │ ├── OkunevWhite.Rnw │ │ └── ShaneAcarMaxLoss.Rnw ├── fPerformance │ ├── DESCRIPTION │ ├── R │ │ ├── perf-Data.R │ │ ├── perf-DownsideRisk.R │ │ ├── perf-Drawdown.R │ │ ├── perf-RegressionAnalysis.R │ │ ├── perf-RelativeRisk.R │ │ ├── perf-ReturnDisributions.R │ │ ├── perf-Returns.R │ │ ├── perf-Risk.R │ │ ├── perf-RiskAdjusted.R │ │ ├── perf-Tables.R │ │ └── perf-ValueAtRisk.R │ └── man │ │ ├── perfAdjustedMeasures.Rd │ │ ├── perfDistributionMeasures.Rd │ │ ├── perfDownsideMeasures.Rd │ │ ├── perfDrawdownMeasures.Rd │ │ ├── perfRegressionMeasures.Rd │ │ ├── perfRelativeMeasures.Rd │ │ ├── perfVaRMeasures.Rd │ │ ├── returns.Rd │ │ └── tables.Rd ├── pulkit │ ├── .Rbuildignore │ ├── DESCRIPTION │ ├── NAMESPACE │ ├── R │ │ ├── BenchmarkPlots.R │ │ ├── BenchmarkSR.R │ │ ├── CDaRMultipath.R │ │ ├── CdaR.R │ │ ├── DrawdownBeta.R │ │ ├── DrawdownBetaMulti.R │ │ ├── Drawdownalpha.R │ │ ├── EDDCOPS.R │ │ ├── Edd.R │ │ ├── ExtremeDrawdown.R │ │ ├── GoldenSection.R │ │ ├── MaxDD.R │ │ ├── MinTRL.R │ │ ├── MonteSimulTriplePenance.R │ │ ├── PSRopt.R │ │ ├── Penance.R │ │ ├── ProbSharpeRatio.R │ │ ├── REDDCOPS.R │ │ ├── REM.R │ │ ├── SRIndifferenceCurve.R │ │ ├── TriplePenance.R │ │ ├── TuW.R │ │ ├── capm_aorda.R │ │ ├── chart.Penance.R │ │ ├── chart.REDD.R │ │ ├── chart.SharpeEfficient.R │ │ ├── gpdmle.R │ │ ├── na.skip.R │ │ ├── psr_python.R │ │ ├── redd.R │ │ ├── ret.R │ │ ├── table.PSR.R │ │ └── table.Penance.R │ ├── data │ │ ├── capm_aorda.csv │ │ ├── psr_python.csv │ │ └── ret.csv │ ├── inst │ │ └── doc │ │ │ ├── ProbSharpe.Rnw │ │ │ └── ProbSharpe.pdf │ ├── man │ │ ├── AlphaDrawdown.Rd │ │ ├── BenchmarkSR.Rd │ │ ├── BetaDrawdown.Rd │ │ ├── CDaR.Rd │ │ ├── CdarMultiPath.Rd │ │ ├── DrawdownGPD.Rd │ │ ├── EDDCOPS.Rd │ │ ├── EconomicDrawdown.Rd │ │ ├── MaxDD.Rd │ │ ├── MinTrackRecord.Rd │ │ ├── MonteSimulTriplePenance.Rd │ │ ├── MultiBetaDrawdown.Rd │ │ ├── Penance.Rd │ │ ├── ProbSharpeRatio.Rd │ │ ├── PsrPortfolio.Rd │ │ ├── REDDCOPS.Rd │ │ ├── TuW.Rd │ │ ├── capm_aorda.Rd │ │ ├── chart.BenchmarkSR.Rd │ │ ├── chart.Penance.Rd │ │ ├── chart.REDD.Rd │ │ ├── chart.SRIndifference.Rd │ │ ├── golden_section.Rd │ │ ├── psr_python.Rd │ │ ├── ret.Rd │ │ ├── rollDrawdown.Rd │ │ ├── rollEconomicMax.Rd │ │ ├── table.PSR.Rd │ │ └── table.Penance.Rd │ ├── src │ │ ├── gpd.c │ │ └── moment.c │ ├── week1 │ │ ├── code │ │ │ ├── PSR.py │ │ │ └── PSROpt.py │ │ ├── tests │ │ │ └── SEF.tests.R │ │ └── vignette │ │ │ └── ProbSharpe.pdf │ ├── week2 │ │ └── tests │ │ │ └── test_SharpeIndifference.R │ ├── week3_4 │ │ ├── code │ │ │ ├── DD2.py │ │ │ ├── DD3.py │ │ │ └── run.py │ │ ├── tests │ │ │ └── tests.TriplePenance.R │ │ └── vignette │ │ │ └── TriplePenance.pdf │ ├── week5 │ │ ├── REDDCOPS.pdf │ │ └── returns.csv │ └── week7 │ │ ├── ExtremeDrawdown.R │ │ └── gpdmle.R ├── refactored.Portfolio.rebalancing.R └── test_Return.rebalancing.R ├── tests └── Examples │ └── PerformanceAnalytics-Ex.Rout.save └── vignettes ├── PA-Bacon.Rnw ├── PA-Bacon.pdf ├── PA-charts.Rnw ├── PA-charts.pdf ├── PerformanceAnalyticsChartsPresentation-Meielisalp-2007.Rnw ├── PerformanceAnalyticsChartsPresentation-Meielisalp-2007.pdf ├── PerformanceAnalyticsGraphicalExamples.pdf ├── PerformanceAnalyticsPresentation-UseR-2007.Rnw ├── PerformanceAnalyticsPresentation-UseR-2007.pdf ├── Rlogo.jpg ├── textplotPresentation-CRUG-2011.Rnw └── textplotPresentation-CRUG-2011.pdf /.Rbuildignore: -------------------------------------------------------------------------------- 1 | sandbox 2 | generatechangelog.sh 3 | ChangeLog.1.0.0 4 | ^.*\.Rproj$ 5 | ^\.Rproj\.user$ 6 | codeblock.txt 7 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: PerformanceAnalytics 2 | Type: Package 3 | Title: Econometric tools for performance and risk analysis. 4 | Version: 1.1.6 5 | Date: $Date$ 6 | Author: Peter Carl, Brian G. Peterson 7 | Maintainer: Brian G. Peterson 8 | Description: Collection of econometric functions for 9 | performance and risk analysis. This package aims to aid 10 | practitioners and researchers in utilizing the latest 11 | research in analysis of non-normal return streams. In 12 | general, it is most tested on return (rather than 13 | price) data on a regular scale, but most functions will 14 | work with irregular return data as well, and increasing 15 | numbers of functions will work with P&L or price data 16 | where possible. 17 | Depends: 18 | R (>= 3.0.0), 19 | zoo, 20 | xts (>= 0.8-9) 21 | Suggests: 22 | Hmisc, 23 | MASS, 24 | quantmod, 25 | quadprog, 26 | gamlss, 27 | robustbase, 28 | quantreg, 29 | gplots, 30 | ff 31 | License: GPL 32 | URL: http://r-forge.r-project.org/projects/returnanalytics/ 33 | Copyright: (c) 2004-2014 34 | Contributors: Kris Boudt, Diethelm Wuertz, Eric Zivot, Matthieu Lestel 35 | Thanks: A special thanks for additional contributions or patches from 36 | Stefan Albrecht, Khahn Nygyen, Jeff Ryan, 37 | Josh Ulrich, Sankalp Upadhyay, Tobias Verbeke, 38 | H. Felix Wittmann, Ram Ahluwalia, R. Douglas Martin 39 | -------------------------------------------------------------------------------- /R/Drawdowns.R: -------------------------------------------------------------------------------- 1 | Drawdowns <- 2 | function (R, geometric = TRUE, ...) 3 | { # @author Peter Carl 4 | 5 | # DESCRIPTION: 6 | # Calculate the drawdown levels in a timeseries 7 | 8 | # FUNCTION: 9 | 10 | x = checkData(R) 11 | 12 | # Get dimensions and labels 13 | columns = ncol(x) 14 | columnnames = colnames(x) 15 | 16 | colDrawdown <- function(x, geometric) { 17 | if(geometric) 18 | Return.cumulative = cumprod(1+x) 19 | else 20 | Return.cumulative = 1+cumsum(x) 21 | maxCumulativeReturn = cummax(c(1,Return.cumulative))[-1] 22 | column.drawdown = Return.cumulative/maxCumulativeReturn - 1 23 | } 24 | 25 | for(column in 1:columns) { 26 | column.drawdown <- na.skip(x[,column],FUN=colDrawdown, geometric = geometric) 27 | 28 | if(column == 1) 29 | drawdown = column.drawdown 30 | else 31 | drawdown = merge(drawdown,column.drawdown) 32 | } 33 | 34 | colnames(drawdown) = columnnames 35 | drawdown = reclass(drawdown, x) 36 | return(drawdown) 37 | } 38 | 39 | ############################################################################### 40 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 41 | # 42 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 43 | # 44 | # This R package is distributed under the terms of the GNU Public License (GPL) 45 | # for full details see the file COPYING 46 | # 47 | # $Id$ 48 | # 49 | ############################################################################### 50 | -------------------------------------------------------------------------------- /R/HerfindahlIndex.R: -------------------------------------------------------------------------------- 1 | HerfindahlIndex <- 2 | function (Ra, ...) 3 | { # @author Brian G. Peterson 4 | 5 | # Description: 6 | 7 | # Ra return vector 8 | 9 | # Function: 10 | 11 | if (is.vector(Ra)) { 12 | # clean the data and get rid of NAs 13 | Ra = checkData (Ra,na.rm=TRUE, method="vector", ...=...) 14 | # compute the simple acf 15 | Racf=acf(Ra,plot=FALSE)[[1]] 16 | # get the subset of positive acf values 17 | pos_acf=subset(Racf,Racf>=0)[-1] 18 | # scale the positive acf to get percent contribution to total positive acf 19 | scaled_acf=pos_acf/sum(pos_acf) 20 | # Herfindal Index is the sum of the squared percentage contributions 21 | return(sum(scaled_acf^2)) 22 | } else { 23 | apply(Ra, 2, HerfindahlIndex, ...=...) 24 | } 25 | 26 | } 27 | 28 | ############################################################################### 29 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 30 | # 31 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 32 | # 33 | # This R package is distributed under the terms of the GNU Public License (GPL) 34 | # for full details see the file COPYING 35 | # 36 | # $Id: HerfindahlIndex.R,v 1.3 2007/09/01 04:05:28 brian Exp $ 37 | # 38 | ############################################################################### -------------------------------------------------------------------------------- /R/Selectivity.R: -------------------------------------------------------------------------------- 1 | #' Selectivity of the return distribution 2 | #' 3 | #' Selectivity is the same as Jensen's alpha 4 | #' 5 | #' \deqn{Selectivity = r_p - r_f - \beta_p * (b - r_f)}{Selectivity = r_p - r_f - beta_p * (b - r_f)} 6 | #' 7 | #' where \eqn{r_f} is the risk free rate, \eqn{\beta_r} is the regression beta, 8 | #' \eqn{r_p} is the portfolio return and b is the benchmark return 9 | #' 10 | #' @aliases Selectivity 11 | #' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of 12 | #' asset returns 13 | #' @param Rb return vector of the benchmark asset 14 | #' @param Rf risk free rate, in same period as your returns 15 | #' @param \dots any other passthru parameters 16 | #' @author Matthieu Lestel 17 | #' @references Carl Bacon, \emph{Practical portfolio performance measurement 18 | #' and attribution}, second edition 2008 p.78 19 | #' 20 | #' @keywords ts multivariate distribution models 21 | #' @examples 22 | #' 23 | #' data(portfolio_bacon) 24 | #' print(Selectivity(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.0141 25 | #' 26 | #' data(managers) 27 | #' print(Selectivity(managers['1996',1], managers['1996',8])) 28 | #' print(Selectivity(managers['1996',1:5], managers['1996',8])) 29 | #' 30 | #' @export 31 | 32 | Selectivity <- 33 | function (Ra, Rb, Rf = 0, ...) 34 | { 35 | Period = Frequency(Ra) 36 | CAPM.jensenAlpha(Ra,Rb,Rf,Period) 37 | } 38 | 39 | 40 | ############################################################################### 41 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 42 | # 43 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 44 | # 45 | # This R package is distributed under the terms of the GNU Public License (GPL) 46 | # for full details see the file COPYING 47 | # 48 | # $Id$ 49 | # 50 | ############################################################################### 51 | -------------------------------------------------------------------------------- /R/SemiDeviation.R: -------------------------------------------------------------------------------- 1 | #' @rdname DownsideDeviation 2 | #' @export 3 | SemiDeviation <- 4 | function (R) 5 | { # @author Peter Carl 6 | 7 | # DESCRIPTION: 8 | # This function is just a wrapper of DownsideDeviation with 9 | # MAR = mean(x) 10 | # see below 11 | 12 | # FUNCTION: 13 | 14 | if (is.vector(R)) { 15 | R = na.omit(R) 16 | return(DownsideDeviation(R, MAR=mean(R), method="full")) 17 | } 18 | else { 19 | R = checkData(R, method = "matrix") 20 | result = apply(R, 2, SemiDeviation) 21 | result = matrix(result, nrow=1) 22 | colnames(result) = colnames(R) 23 | rownames(result) = "Semi-Deviation" 24 | return(result) 25 | } 26 | } 27 | 28 | #' @rdname DownsideDeviation 29 | #' @export 30 | SemiVariance <- 31 | function (R) 32 | { 33 | if (is.vector(R)) { 34 | R = na.omit(R) 35 | return(DownsideDeviation(R, MAR=mean(R), method="subset")) 36 | } 37 | else { 38 | R = checkData(R, method = "matrix") 39 | result = apply(R, 2, SemiVariance) 40 | dim(result) = c(1,NCOL(R)) 41 | colnames(result) = colnames(R) 42 | rownames(result) = "Semi-Variance" 43 | return(result) 44 | } 45 | } 46 | 47 | ############################################################################### 48 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 49 | # 50 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 51 | # 52 | # This R package is distributed under the terms of the GNU Public License (GPL) 53 | # for full details see the file COPYING 54 | # 55 | # $Id$ 56 | # 57 | ############################################################################### -------------------------------------------------------------------------------- /R/na.skip.R: -------------------------------------------------------------------------------- 1 | na.skip <- function (x, FUN=NULL, ...) # maybe add a trim capability? 2 | { # @author Brian Peterson 3 | 4 | # DESCRIPTION: 5 | 6 | # Time series data often contains NA's, either due to missing days, 7 | # noncontiguous series, or merging multiple series, 8 | # 9 | # Some Calulcations, such as return calculations, require data that 10 | # looks like a vector, and needs the output of na.omit 11 | # 12 | # It is often convenient to apply these vector-like functions, but 13 | # you still need to keep track of the structure of the oridginal data. 14 | 15 | # Inputs 16 | # x the time series to apply FUN too 17 | # FUN function to apply 18 | # ... any additonal parameters to FUN 19 | 20 | # Outputs: 21 | # An xts time series that has the same index and NA's as the data 22 | # passed in, after applying FUN 23 | 24 | nx <- na.omit(x) 25 | fx <- FUN(nx, ... = ...) 26 | if (is.vector(fx)) { 27 | result <- .xts(fx, .index(x), .indexCLASS = indexClass(x)) 28 | } 29 | else { 30 | result <- merge(fx, .xts(, .index(x))) 31 | } 32 | return(result) 33 | } 34 | 35 | ############################################################################### 36 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 37 | # 38 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 39 | # 40 | # This R package is distributed under the terms of the GNU Public License (GPL) 41 | # for full details see the file COPYING 42 | # 43 | # $Id$ 44 | # 45 | ############################################################################### -------------------------------------------------------------------------------- /R/rCornishFisher.r: -------------------------------------------------------------------------------- 1 | ## rCornishFisher.r 2 | ## 3 | ## author: Eric Zivot 4 | ## created: May 28, 2008 5 | ## updated: May 28, 2009 6 | ## 7 | ## purpose: simulate observations based on Cornish-Fisher quantile expansion 8 | ## 9 | ## 10 | rCornishFisher <- function(n, sigma, skew, ekurt, seed=NULL) { 11 | ## inputs: 12 | ## n scalar, number of simulated values 13 | ## sigma scalar, standard deviation 14 | ## skew scalar, skewness 15 | ## ekurt scalar, excess kurtosis 16 | ## outputs: 17 | ## n simulated values from Cornish-Fisher distribution 18 | if (!is.null(seed)) set.seed(seed) 19 | zc = rnorm(n) 20 | z.cf = zc + (((zc^2 - 1) * skew)/6) + (((zc^3 - 3 * zc) * 21 | ekurt)/24) - ((((2 * zc^3) - 5 * zc) * skew^2)/36) 22 | ans = sigma*z.cf 23 | ans 24 | } 25 | 26 | ############################################################################### 27 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 28 | # 29 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 30 | # 31 | # This R package is distributed under the terms of the GNU Public License (GPL) 32 | # for full details see the file COPYING 33 | # 34 | # $Id$ 35 | # 36 | ############################################################################### -------------------------------------------------------------------------------- /R/replaceTabs.R: -------------------------------------------------------------------------------- 1 | ## Function to replace all tabs in a string with an appropriate number of spaces. 2 | 3 | #' @rdname textplot 4 | replaceTabs.inner <- function( text, width=8 ) 5 | { 6 | # handle a single character string 7 | spaces <- " " 8 | 9 | if(nchar(text)<1) return(text) 10 | 11 | text.split <- strsplit(text,"\t")[[1]] 12 | if(length(text.split)==1) 13 | return(text) 14 | else 15 | { 16 | nSpaceAdd <- 8 - nchar(text.split) %% 8 17 | nSpaceAdd[length(nSpaceAdd)] <- 0 18 | nSpaceAdd[nSpaceAdd==8] <- 0 19 | 20 | retval <- "" 21 | for(i in 1:length(text.split)) 22 | { 23 | tmp.text <- chartr("\t"," ", text.split[i]) # one space here 24 | retval <- paste(retval, tmp.text, substr(spaces,0,nSpaceAdd[i]-1 ), sep='' ) # rest here 25 | } 26 | return(retval) 27 | } 28 | } 29 | 30 | #' @rdname textplot 31 | replaceTabs <- function(text, width=8) 32 | { 33 | text <- as.character(text) 34 | retval <- sapply(text, replaceTabs.inner) 35 | names(retval) <- names(text) 36 | retval 37 | } 38 | 39 | ############################################################################### 40 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 41 | # 42 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 43 | # 44 | # This R package is distributed under the terms of the GNU Public License (GPL) 45 | # for full details see the file COPYING 46 | # 47 | # $Id$ 48 | # 49 | ############################################################################### -------------------------------------------------------------------------------- /R/zerofill.R: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # R (http://r-project.org/) Numeric Methods for Optimization of Portfolios 3 | # 4 | # Copyright (c) 2004-2014 Kris Boudt, Peter Carl and Brian G. Peterson 5 | # 6 | # This R package is distributed under the terms of the GNU Public License (GPL) 7 | # for full details see the file COPYING 8 | # 9 | # $Id$ 10 | # 11 | ############################################################################### 12 | 13 | 14 | 15 | 16 | 17 | #' zerofill 18 | #' 19 | #' Fill NA's with zeros in a time series to allow analysis when the matrix must 20 | #' be complete. 21 | #' 22 | #' Note that this function has risks, use carefully. Complete data is 23 | #' preferred. Barring that, filling a small percentage of results in a the 24 | #' middle of a large set are unlikely to cause problems. Barring that, realize 25 | #' that this will skew your results. 26 | #' 27 | #' @param x time series to zero fill 28 | #' @export 29 | zerofill <- function (x) { 30 | mat<-checkData(x,"matrix") 31 | for(column in 1:ncol(mat)){ 32 | for (row in 1:nrow(mat)){ 33 | if(is.na(mat[row,column])) mat[row,column] <- 0 34 | } 35 | } 36 | x<-reclass(mat,x) 37 | return(x) 38 | } 39 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | .onLoad <- function(lib, pkg) 2 | { 3 | # Startup Mesage and Desription: 4 | MSG <- if(getRversion() >= "2.5") packageStartupMessage else message 5 | dsc <- packageDescription(pkg) 6 | if(interactive() || getOption("verbose")) { 7 | # not in test scripts 8 | MSG(paste("\nPackage ", pkg, " (",dsc$Version,") loaded.\n", 9 | dsc$Title, "\n", dsc$Copyright, " ", dsc$Author, ". License: ", dsc$License, "\n", dsc$URL, 10 | "\n", sep="")) 11 | } 12 | } 13 | 14 | even <- function (x) x%%2==0 15 | 16 | odd <- function (x) x%%2==1 17 | 18 | sd.xts <- xts:::sd.xts 19 | 20 | #' @importFrom utils packageDescription 21 | #' @importFrom stats sd 22 | #' @importFrom zoo rollapply 23 | #' @import xts 24 | NULL 25 | 26 | ############################################################################### 27 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 28 | # 29 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 30 | # 31 | # This R package is distributed under the terms of the GNU Public License (GPL) 32 | # for full details see the file COPYING 33 | # 34 | # $Id$ 35 | # 36 | ############################################################################### 37 | -------------------------------------------------------------------------------- /codeblock.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | ############################################################################### 4 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 5 | # 6 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 7 | # 8 | # This R package is distributed under the terms of the GNU Public License (GPL) 9 | # for full details see the file COPYING 10 | # 11 | # $Id$ 12 | # 13 | ############################################################################### 14 | -------------------------------------------------------------------------------- /data/edhec.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/data/edhec.rda -------------------------------------------------------------------------------- /data/managers.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/data/managers.rda -------------------------------------------------------------------------------- /data/portfolio_bacon.csv: -------------------------------------------------------------------------------- 1 | ,portfolio monthly return (%), benchmark return (%) 2 | 2000-01-31,0.003,0.002 3 | 2000-02-28,0.026,0.025 4 | 2000-03-31,0.011,0.018 5 | 2000-04-30,-0.010,-0.011 6 | 2000-05-31,0.015,0.014 7 | 2000-06-30,0.025,0.018 8 | 2000-07-31,0.016,0.014 9 | 2000-08-31,0.067,0.065 10 | 2000-09-30,-0.014,-0.015 11 | 2000-10-31,0.040,0.042 12 | 2000-11-30,-0.005,-0.006 13 | 2000-12-31,0.081,0.083 14 | 2001-01-31,0.040,0.039 15 | 2001-02-28,-0.037,-0.038 16 | 2001-03-31,-0.061,-0.062 17 | 2001-04-30,0.017,0.015 18 | 2001-05-31,-0.049,-0.048 19 | 2001-06-30,-0.022,0.021 20 | 2001-07-31,0.070,0.060 21 | 2001-08-31,0.058,0.056 22 | 2001-09-30,-0.065,-0.067 23 | 2001-10-31,0.024,0.019 24 | 2001-11-30,-0.005,-0.003 25 | 2001-12-31,-0.009,0 -------------------------------------------------------------------------------- /data/portfolio_bacon.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/data/portfolio_bacon.rda -------------------------------------------------------------------------------- /data/prices.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/data/prices.rda -------------------------------------------------------------------------------- /data/weights.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/data/weights.rda -------------------------------------------------------------------------------- /generatechangelog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #cvs2cl -T -P -S --no-wrap 4 | svn2cl --group-by-day -a 5 | svn2cl --group-by-day -a 6 | #cat ChangeLog.1.0.0 >> ChangeLog 7 | -------------------------------------------------------------------------------- /man/ActivePremium.Rd: -------------------------------------------------------------------------------- 1 | \name{ActiveReturn} 2 | \alias{ActivePremium} 3 | \alias{ActiveReturn} 4 | \title{Active Premium or Active Return} 5 | \usage{ 6 | ActiveReturn(Ra, Rb, scale = NA) 7 | } 8 | \arguments{ 9 | \item{Ra}{return vector of the portfolio} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{scale}{number of periods in a year (daily scale = 14 | 252, monthly scale = 12, quarterly scale = 4)} 15 | } 16 | \description{ 17 | The return on an investment's annualized return minus the 18 | benchmark's annualized return. 19 | } 20 | \details{ 21 | Active Premium = Investment's annualized return - 22 | Benchmark's annualized return 23 | 24 | Also commonly referred to as 'active return'. 25 | } 26 | \examples{ 27 | data(managers) 28 | ActivePremium(managers[, "HAM1", drop=FALSE], managers[, "SP500 TR", drop=FALSE]) 29 | ActivePremium(managers[,1,drop=FALSE], managers[,8,drop=FALSE]) 30 | ActivePremium(managers[,1:6], managers[,8,drop=FALSE]) 31 | ActivePremium(managers[,1:6], managers[,8:7,drop=FALSE]) 32 | } 33 | \author{ 34 | Peter Carl 35 | } 36 | \references{ 37 | Sharpe, W.F. The Sharpe Ratio,\emph{Journal of Portfolio 38 | Management},Fall 1994, 49-58. 39 | } 40 | \seealso{ 41 | \code{\link{InformationRatio}} \code{\link{TrackingError}} 42 | \code{\link{Return.annualized}} 43 | } 44 | \keyword{distribution} 45 | \keyword{models} 46 | \keyword{multivariate} 47 | \keyword{ts} 48 | 49 | -------------------------------------------------------------------------------- /man/AdjustedSharpeRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{AdjustedSharpeRatio} 2 | \alias{AdjustedSharpeRatio} 3 | \title{Adjusted Sharpe ratio of the return distribution} 4 | \usage{ 5 | AdjustedSharpeRatio(R, Rf = 0, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rf}{the risk free rate} 12 | 13 | \item{\dots}{any other passthru parameters} 14 | } 15 | \description{ 16 | Adjusted Sharpe ratio was introduced by Pezier and White 17 | (2006) to adjusts for skewness and kurtosis by 18 | incorporating a penalty factor for negative skewness and 19 | excess kurtosis. 20 | } 21 | \details{ 22 | \deqn{Adjusted Sharpe Ratio = SR * [1 + (\frac{S}{6}) * SR 23 | - (\frac{K - 3}{24}) * SR^2]}{Adjusted Sharpe ratio = SR x 24 | [1 + (S/6) x SR - ((K-3) / 24) x SR^2]} 25 | 26 | where \eqn{SR} is the sharpe ratio with data annualized, 27 | \eqn{S} is the skewness and \eqn{K} is the kurtosis 28 | } 29 | \examples{ 30 | data(portfolio_bacon) 31 | print(AdjustedSharpeRatio(portfolio_bacon[,1])) #expected 0.81 32 | 33 | data(managers) 34 | print(AdjustedSharpeRatio(managers['1996'])) 35 | print(AdjustedSharpeRatio(managers['1996',1])) 36 | } 37 | \author{ 38 | Matthieu Lestel 39 | } 40 | \references{ 41 | Carl Bacon, \emph{Practical portfolio performance 42 | measurement and attribution}, second edition 2008 p.99 43 | } 44 | \keyword{distribution} 45 | \keyword{models} 46 | \keyword{multivariate} 47 | \keyword{ts} 48 | 49 | -------------------------------------------------------------------------------- /man/AverageDrawdown.Rd: -------------------------------------------------------------------------------- 1 | \name{AverageDrawdown} 2 | \alias{AverageDrawdown} 3 | \alias{AverageRecovery} 4 | \title{Calculates the average of the observed drawdowns.} 5 | \usage{ 6 | AverageDrawdown(R, ...) 7 | 8 | AverageRecovery(R, ...) 9 | } 10 | \arguments{ 11 | \item{R}{an xts, vector, matrix, data frame, timeSeries 12 | or zoo object of asset returns} 13 | 14 | \item{\dots}{any other passthru parameters} 15 | } 16 | \description{ 17 | ADD = abs(sum[j=1,2,...,d](D_j/d)) where D'_j = jth 18 | drawdown over entire period d = total number of drawdowns 19 | in the entire period 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/BernardoLedoitRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{BernardoLedoitRatio} 2 | \alias{BernardoLedoitRatio} 3 | \title{Bernardo and Ledoit ratio of the return distribution} 4 | \usage{ 5 | BernardoLedoitRatio(R, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{\dots}{any other passthru parameters} 12 | } 13 | \description{ 14 | To calculate Bernardo and Ledoit ratio we take the sum of 15 | the subset of returns that are above 0 and we divide it by 16 | the opposite of the sum of the subset of returns that are 17 | below 0 18 | } 19 | \details{ 20 | \deqn{BernardoLedoitRatio(R) = 21 | \frac{\frac{1}{n}\sum^{n}_{t=1}{max(R_{t},0)}}{\frac{1}{n}\sum^{n}_{t=1}{max(-R_{t},0)}}}{BernardoLedoitRatio(R) 22 | = 1/n*sum(t=1..n)(max(R(t),0)) / 23 | 1/n*sum(t=1..n)(max(-R(t),0))} 24 | 25 | where \eqn{n} is the number of observations of the entire 26 | series 27 | } 28 | \examples{ 29 | data(portfolio_bacon) 30 | print(BernardoLedoitRatio(portfolio_bacon[,1])) #expected 1.78 31 | 32 | data(managers) 33 | print(BernardoLedoitRatio(managers['1996'])) 34 | print(BernardoLedoitRatio(managers['1996',1])) #expected 4.598 35 | } 36 | \author{ 37 | Matthieu Lestel 38 | } 39 | \references{ 40 | Carl Bacon, \emph{Practical portfolio performance 41 | measurement and attribution}, second edition 2008 p.95 42 | } 43 | \keyword{distribution} 44 | \keyword{models} 45 | \keyword{multivariate} 46 | \keyword{ts} 47 | 48 | -------------------------------------------------------------------------------- /man/BurkeRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{BurkeRatio} 2 | \alias{BurkeRatio} 3 | \title{Burke ratio of the return distribution} 4 | \usage{ 5 | BurkeRatio(R, Rf = 0, modified = FALSE, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rf}{the risk free rate} 12 | 13 | \item{modified}{a boolean to decide which ratio to 14 | calculate between Burke ratio and modified Burke ratio.} 15 | 16 | \item{\dots}{any other passthru parameters} 17 | } 18 | \description{ 19 | To calculate Burke ratio we take the difference between the 20 | portfolio return and the risk free rate and we divide it by 21 | the square root of the sum of the square of the drawdowns. 22 | To calculate the modified Burke ratio we just multiply the 23 | Burke ratio by the square root of the number of datas. 24 | } 25 | \details{ 26 | \deqn{Burke Ratio = \frac{r_P - 27 | r_F}{\sqrt{\sum^{d}_{t=1}{D_t}^2}}}{Burke Ratio = (Rp - Rf) 28 | / (sqrt(sum(t=1..n)(Dt^2)))} 29 | 30 | \deqn{Modified Burke Ratio = \frac{r_P - 31 | r_F}{\sqrt{\sum^{d}_{t=1}\frac{{D_t}^2}{n}}}}{Modified 32 | Burke Ratio = (Rp - Rf) / (sqrt(sum(t=1..n)(Dt^2 / n)))} 33 | 34 | where \eqn{n} is the number of observations of the entire 35 | series, \eqn{d} is number of drawdowns, \eqn{r_P} is the 36 | portfolio return, \eqn{r_F} is the risk free rate and 37 | \eqn{D_t} the \eqn{t^{th}} drawdown. 38 | } 39 | \examples{ 40 | data(portfolio_bacon) 41 | print(BurkeRatio(portfolio_bacon[,1])) #expected 0.74 42 | print(BurkeRatio(portfolio_bacon[,1], modified = TRUE)) #expected 3.65 43 | 44 | data(managers) 45 | print(BurkeRatio(managers['1996'])) 46 | print(BurkeRatio(managers['1996',1])) 47 | print(BurkeRatio(managers['1996'], modified = TRUE)) 48 | print(BurkeRatio(managers['1996',1], modified = TRUE)) 49 | } 50 | \author{ 51 | Matthieu Lestel 52 | } 53 | \references{ 54 | Carl Bacon, \emph{Practical portfolio performance 55 | measurement and attribution}, second edition 2008 p.90-91 56 | } 57 | \keyword{distribution} 58 | \keyword{models} 59 | \keyword{multivariate} 60 | \keyword{ts} 61 | 62 | -------------------------------------------------------------------------------- /man/CAPM.epsilon.Rd: -------------------------------------------------------------------------------- 1 | \name{CAPM.epsilon} 2 | \alias{CAPM.epsilon} 3 | \alias{SFM.epsilon} 4 | \title{Regression epsilon of the return distribution} 5 | \usage{ 6 | CAPM.epsilon(Ra, Rb, Rf = 0, ...) 7 | } 8 | \arguments{ 9 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{Rb}{return vector of the benchmark asset} 13 | 14 | \item{Rf}{risk free rate, in same period as your returns} 15 | 16 | \item{\dots}{any other passthru parameters} 17 | } 18 | \description{ 19 | The regression epsilon is an error term measuring the 20 | vertical distance between the return predicted by the 21 | equation and the real result. 22 | } 23 | \details{ 24 | \deqn{\epsilon_r = r_p - \alpha_r - \beta_r * b}{epsilon_r 25 | = r_p - alpha_r - beta_r * b} 26 | 27 | where \eqn{\alpha_r} is the regression alpha, \eqn{\beta_r} 28 | is the regression beta, \eqn{r_p} is the portfolio return 29 | and b is the benchmark return 30 | } 31 | \examples{ 32 | data(portfolio_bacon) 33 | print(SFM.epsilon(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.013 34 | 35 | data(managers) 36 | print(SFM.epsilon(managers['1996',1], managers['1996',8])) 37 | print(SFM.epsilon(managers['1996',1:5], managers['1996',8])) 38 | } 39 | \author{ 40 | Matthieu Lestel 41 | } 42 | \references{ 43 | Carl Bacon, \emph{Practical portfolio performance 44 | measurement and attribution}, second edition 2008 p.71 45 | } 46 | \keyword{distribution} 47 | \keyword{models} 48 | \keyword{multivariate} 49 | \keyword{ts} 50 | 51 | -------------------------------------------------------------------------------- /man/CAPM.jensenAlpha.Rd: -------------------------------------------------------------------------------- 1 | \name{CAPM.jensenAlpha} 2 | \alias{CAPM.jensenAlpha} 3 | \alias{SFM.jensenAlpha} 4 | \title{Jensen's alpha of the return distribution} 5 | \usage{ 6 | CAPM.jensenAlpha(Ra, Rb, Rf = 0, ...) 7 | } 8 | \arguments{ 9 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{Rb}{return vector of the benchmark asset} 13 | 14 | \item{Rf}{risk free rate, in same period as your returns} 15 | 16 | \item{\dots}{any other passthru parameters} 17 | } 18 | \description{ 19 | The Jensen's alpha is the intercept of the regression 20 | equation in the Capital Asset Pricing Model and is in 21 | effect the exess return adjusted for systematic risk. 22 | } 23 | \details{ 24 | \deqn{\alpha = r_p - r_f - \beta_p * (b - r_f)}{alpha = r_p 25 | - r_f - beta_p * (b - r_f)} 26 | 27 | where \eqn{r_f} is the risk free rate, \eqn{\beta_r} is the 28 | regression beta, \eqn{r_p} is the portfolio return and b is 29 | the benchmark return 30 | } 31 | \examples{ 32 | data(portfolio_bacon) 33 | print(SFM.jensenAlpha(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.014 34 | 35 | data(managers) 36 | print(SFM.jensenAlpha(managers['1996',1], managers['1996',8])) 37 | print(SFM.jensenAlpha(managers['1996',1:5], managers['1996',8])) 38 | } 39 | \author{ 40 | Matthieu Lestel 41 | } 42 | \references{ 43 | Carl Bacon, \emph{Practical portfolio performance 44 | measurement and attribution}, second edition 2008 p.72 45 | } 46 | \keyword{distribution} 47 | \keyword{models} 48 | \keyword{multivariate} 49 | \keyword{ts} 50 | 51 | -------------------------------------------------------------------------------- /man/CDD.Rd: -------------------------------------------------------------------------------- 1 | \name{CDD} 2 | \alias{CDD} 3 | \alias{CDaR} 4 | \title{Calculate Uryasev's proposed Conditional Drawdown at Risk (CDD or CDaR) 5 | measure} 6 | \usage{ 7 | CDD(R, weights = NULL, geometric = TRUE, invert = TRUE, p = 0.95, ...) 8 | } 9 | \arguments{ 10 | \item{R}{an xts, vector, matrix, data frame, timeSeries 11 | or zoo object of asset returns} 12 | 13 | \item{weights}{portfolio weighting vector, default NULL, 14 | see Details} 15 | 16 | \item{geometric}{utilize geometric chaining (TRUE) or 17 | simple/arithmetic chaining (FALSE) to aggregate returns, 18 | default TRUE} 19 | 20 | \item{invert}{TRUE/FALSE whether to invert the drawdown 21 | measure. see Details.} 22 | 23 | \item{p}{confidence level for calculation, default 24 | p=0.95} 25 | 26 | \item{\dots}{any other passthru parameters} 27 | } 28 | \description{ 29 | For some confidence level \eqn{p}, the conditional drawdown 30 | is the the mean of the worst \eqn{p\%} drawdowns. 31 | } 32 | \examples{ 33 | data(edhec) 34 | t(round(CDD(edhec),4)) 35 | } 36 | \author{ 37 | Brian G. Peterson 38 | } 39 | \references{ 40 | Chekhlov, A., Uryasev, S., and M. Zabarankin. Portfolio 41 | Optimization With Drawdown Constraints. B. Scherer (Ed.) 42 | Asset and Liability Management Tools, Risk Books, London, 43 | 2003 http://www.ise.ufl.edu/uryasev/drawdown.pdf 44 | } 45 | \seealso{ 46 | \code{\link{ES}} \code{\link{maxDrawdown}} 47 | } 48 | \keyword{distribution} 49 | \keyword{models} 50 | \keyword{multivariate} 51 | \keyword{ts} 52 | 53 | -------------------------------------------------------------------------------- /man/DRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{DRatio} 2 | \alias{DRatio} 3 | \title{d ratio of the return distribution} 4 | \usage{ 5 | DRatio(R, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{\dots}{any other passthru parameters} 12 | } 13 | \description{ 14 | The d ratio is similar to the Bernado Ledoit ratio but 15 | inverted and taking into account the frequency of positive 16 | and negative returns. 17 | } 18 | \details{ 19 | It has values between zero and infinity. It can be used to 20 | rank the performance of portfolios. The lower the d ratio 21 | the better the performance, a value of zero indicating 22 | there are no returns less than zero and a value of infinity 23 | indicating there are no returns greater than zero. 24 | 25 | \deqn{DRatio(R) = 26 | \frac{n_{d}*\sum^{n}_{t=1}{max(-R_{t},0)}}{n_{u}*\sum^{n}_{t=1} 27 | {max(R_{t},0)}}}{DRatio(R) = nd*sum (t=1..n)(max(-R(t),0)) 28 | / nu*sum(t=1..n)(max(R(t),0))} 29 | 30 | where \eqn{n} is the number of observations of the entire 31 | series, \eqn{n_{d}} is the number of observations less than 32 | zero, \eqn{n_{u}} is the number of observations greater 33 | than zero 34 | } 35 | \examples{ 36 | data(portfolio_bacon) 37 | print(DRatio(portfolio_bacon[,1])) #expected 0.401 38 | 39 | data(managers) 40 | print(DRatio(managers['1996'])) 41 | print(DRatio(managers['1996',1])) #expected 0.0725 42 | } 43 | \author{ 44 | Matthieu Lestel 45 | } 46 | \references{ 47 | Carl Bacon, \emph{Practical portfolio performance 48 | measurement and attribution}, second edition 2008 p.95 49 | } 50 | \keyword{distribution} 51 | \keyword{models} 52 | \keyword{multivariate} 53 | \keyword{ts} 54 | 55 | -------------------------------------------------------------------------------- /man/DownsideFrequency.Rd: -------------------------------------------------------------------------------- 1 | \name{DownsideFrequency} 2 | \alias{DownsideFrequency} 3 | \title{downside frequency of the return distribution} 4 | \usage{ 5 | DownsideFrequency(R, MAR = 0, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{MAR}{Minimum Acceptable Return, in the same 12 | periodicity as your returns} 13 | 14 | \item{\dots}{any other passthru parameters} 15 | } 16 | \description{ 17 | To calculate Downside Frequency, we take the subset of 18 | returns that are less than the target (or Minimum 19 | Acceptable Returns (MAR)) returns and divide the length of 20 | this subset by the total number of returns. 21 | } 22 | \details{ 23 | \deqn{ DownsideFrequency(R , MAR) = 24 | \sum^{n}_{t=1}\frac{min[(R_{t} - MAR), 25 | 0]}{R_{t}*n}}{DownsideFrequency(R, MAR) = length(subset of 26 | returns below MAR) / length(total returns)} 27 | 28 | where \eqn{n} is the number of observations of the entire 29 | series 30 | } 31 | \examples{ 32 | data(portfolio_bacon) 33 | MAR = 0.005 34 | print(DownsideFrequency(portfolio_bacon[,1], MAR)) #expected 0.458 35 | 36 | data(managers) 37 | print(DownsideFrequency(managers['1996'])) 38 | print(DownsideFrequency(managers['1996',1])) #expected 0.25 39 | } 40 | \author{ 41 | Matthieu Lestel 42 | } 43 | \references{ 44 | Carl Bacon, \emph{Practical portfolio performance 45 | measurement and attribution}, second edition 2008 p.94 46 | } 47 | \keyword{distribution} 48 | \keyword{models} 49 | \keyword{multivariate} 50 | \keyword{ts} 51 | 52 | -------------------------------------------------------------------------------- /man/DrawdownDeviation.Rd: -------------------------------------------------------------------------------- 1 | \name{DrawdownDeviation} 2 | \alias{DrawdownDeviation} 3 | \title{Calculates a standard deviation-type statistic using individual drawdowns.} 4 | \usage{ 5 | DrawdownDeviation(R, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{\dots}{any other passthru parameters} 12 | } 13 | \description{ 14 | DD = sqrt(sum[j=1,2,...,d](D_j^2/n)) where D_j = jth 15 | drawdown over the entire period d = total number of 16 | drawdowns in entire period n = number of observations 17 | } 18 | 19 | -------------------------------------------------------------------------------- /man/DrawdownPeak.Rd: -------------------------------------------------------------------------------- 1 | \name{DrawdownPeak} 2 | \alias{DrawdownPeak} 3 | \title{Drawdawn peak of the return distribution} 4 | \usage{ 5 | DrawdownPeak(R, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{\dots}{any other passthru parameters} 12 | } 13 | \description{ 14 | Drawdawn peak is for each return its drawdown since the 15 | previous peak 16 | } 17 | \author{ 18 | Matthieu Lestel 19 | } 20 | \keyword{distribution} 21 | \keyword{models} 22 | \keyword{multivariate} 23 | \keyword{ts} 24 | 25 | -------------------------------------------------------------------------------- /man/FamaBeta.Rd: -------------------------------------------------------------------------------- 1 | \name{FamaBeta} 2 | \alias{FamaBeta} 3 | \title{Fama beta of the return distribution} 4 | \usage{ 5 | FamaBeta(Ra, Rb, ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{\dots}{any other passthru parameters} 14 | } 15 | \description{ 16 | Fama beta is a beta used to calculate the loss of 17 | diversification. It is made so that the systematic risk is 18 | equivalent to the total portfolio risk. 19 | } 20 | \details{ 21 | \deqn{\beta_F = \frac{\sigma_P}{\sigma_M}}{Fama beta = 22 | portfolio standard deviation / benchmark standard 23 | deviation} 24 | 25 | where \eqn{\sigma_P} is the portfolio standard deviation 26 | and \eqn{\sigma_M} is the market risk 27 | } 28 | \examples{ 29 | data(portfolio_bacon) 30 | print(FamaBeta(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 1.03 31 | 32 | data(managers) 33 | print(FamaBeta(managers['1996',1], managers['1996',8])) 34 | print(FamaBeta(managers['1996',1:5], managers['1996',8])) 35 | } 36 | \author{ 37 | Matthieu Lestel 38 | } 39 | \references{ 40 | Carl Bacon, \emph{Practical portfolio performance 41 | measurement and attribution}, second edition 2008 p.78 42 | } 43 | \keyword{distribution} 44 | \keyword{models} 45 | \keyword{multivariate} 46 | \keyword{ts} 47 | 48 | -------------------------------------------------------------------------------- /man/Frequency.Rd: -------------------------------------------------------------------------------- 1 | \name{Frequency} 2 | \alias{Frequency} 3 | \title{Frequency of the return distribution} 4 | \usage{ 5 | Frequency(R, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{\dots}{any other passthru parameters} 12 | } 13 | \description{ 14 | Gives the period of the return distribution (ie 12 if 15 | monthly return, 4 if quarterly return) 16 | } 17 | \examples{ 18 | data(portfolio_bacon) 19 | print(Frequency(portfolio_bacon[,1])) #expected 12 20 | data(managers) 21 | print(Frequency(managers['1996',1:5])) 22 | } 23 | \author{ 24 | Matthieu Lestel 25 | } 26 | \keyword{distribution} 27 | \keyword{models} 28 | \keyword{multivariate} 29 | \keyword{ts} 30 | 31 | -------------------------------------------------------------------------------- /man/InformationRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{InformationRatio} 2 | \alias{InformationRatio} 3 | \title{InformationRatio = ActivePremium/TrackingError} 4 | \usage{ 5 | InformationRatio(Ra, Rb, scale = NA) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{scale}{number of periods in a year (daily scale = 14 | 252, monthly scale = 12, quarterly scale = 4)} 15 | } 16 | \description{ 17 | The Active Premium divided by the Tracking Error. 18 | } 19 | \details{ 20 | InformationRatio = ActivePremium/TrackingError 21 | 22 | This relates the degree to which an investment has beaten 23 | the benchmark to the consistency with which the investment 24 | has beaten the benchmark. 25 | } 26 | \note{ 27 | William Sharpe now recommends \code{InformationRatio} 28 | preferentially to the original \code{\link{SharpeRatio}}. 29 | } 30 | \examples{ 31 | data(managers) 32 | InformationRatio(managers[,"HAM1",drop=FALSE], managers[, "SP500 TR", drop=FALSE]) 33 | InformationRatio(managers[,1:6], managers[,8,drop=FALSE]) 34 | InformationRatio(managers[,1:6], managers[,8:7]) 35 | } 36 | \author{ 37 | Peter Carl 38 | } 39 | \references{ 40 | Sharpe, W.F. The Sharpe Ratio,\emph{Journal of Portfolio 41 | Management},Fall 1994, 49-58. 42 | } 43 | \seealso{ 44 | \code{\link{TrackingError}} \cr \code{\link{ActivePremium}} 45 | \cr \code{\link{SharpeRatio}} 46 | } 47 | \keyword{distribution} 48 | \keyword{models} 49 | \keyword{multivariate} 50 | \keyword{ts} 51 | 52 | -------------------------------------------------------------------------------- /man/Kappa.Rd: -------------------------------------------------------------------------------- 1 | \name{Kappa} 2 | \alias{Kappa} 3 | \title{Kappa of the return distribution} 4 | \usage{ 5 | Kappa(R, MAR, l, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{MAR}{Minimum Acceptable Return, in the same 12 | periodicity as your returns} 13 | 14 | \item{l}{the coefficient of the Kappa} 15 | 16 | \item{\dots}{any other passthru parameters} 17 | } 18 | \description{ 19 | Introduced by Kaplan and Knowles (2004), Kappa is a 20 | generalized downside risk-adjusted performance measure. 21 | } 22 | \details{ 23 | To calculate it, we take the difference of the mean of the 24 | distribution to the target and we divide it by the l-root 25 | of the lth lower partial moment. To calculate the lth lower 26 | partial moment we take the subset of returns below the 27 | target and we sum the differences of the target to these 28 | returns. We then return return this sum divided by the 29 | length of the whole distribution. 30 | 31 | \deqn{Kappa(R, MAR, l) = 32 | \frac{r_{p}-MAR}{\sqrt[l]{\frac{1}{n}*\sum^n_{t=1} 33 | max(MAR-R_{t}, 0)^l}}}{Kappa(R, MAR, l) = (rp - 34 | MAR)/(\sqrt[l](1/n*sum(t=1..n) (max(MAR-r(t),0)^l)))} 35 | 36 | For l=1 kappa is the Sharpe-omega ratio and for l=2 kappa 37 | is the sortino ratio. 38 | 39 | Kappa should only be used to rank portfolios as it is 40 | difficult to interpret the absolute differences between 41 | kappas. The higher the kappa is, the better. 42 | } 43 | \examples{ 44 | l = 2 45 | 46 | data(portfolio_bacon) 47 | MAR = 0.005 48 | print(Kappa(portfolio_bacon[,1], MAR, l)) #expected 0.157 49 | 50 | data(managers) 51 | MAR = 0 52 | print(Kappa(managers['1996'], MAR, l)) 53 | print(Kappa(managers['1996',1], MAR, l)) #expected 1.493 54 | } 55 | \author{ 56 | Matthieu Lestel 57 | } 58 | \references{ 59 | Carl Bacon, \emph{Practical portfolio performance 60 | measurement and attribution}, second edition 2008 p.96 61 | } 62 | \keyword{distribution} 63 | \keyword{models} 64 | \keyword{multivariate} 65 | \keyword{ts} 66 | 67 | -------------------------------------------------------------------------------- /man/KellyRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{KellyRatio} 2 | \alias{KellyRatio} 3 | \title{calculate Kelly criterion ratio (leverage or bet size) for a strategy} 4 | \usage{ 5 | KellyRatio(R, Rf = 0, method = "half") 6 | } 7 | \arguments{ 8 | \item{R}{a vector of returns to perform a mean over} 9 | 10 | \item{Rf}{risk free rate, in same period as your returns} 11 | 12 | \item{method}{method=half will use the half-Kelly, this 13 | is the default} 14 | } 15 | \description{ 16 | Kelly criterion ratio (leverage or bet size) for a 17 | strategy. 18 | } 19 | \details{ 20 | The Kelly Criterion was identified by Bell Labs scientist 21 | John Kelly, and applied to blackjack and stock strategy 22 | sizing by Ed Thorpe. 23 | 24 | The Kelly ratio can be simply stated as: \dQuote{bet size 25 | is the ratio of edge over odds.} Mathematically, you are 26 | maximizing log-utility. As such, the Kelly criterion is 27 | equal to the expected excess return of the strategy divided 28 | by the expected variance of the excess return, or 29 | 30 | \deqn{leverage=\frac{(\overline{R}_{s}-R_{f})}{StdDev(R)^{2}}}{leverage 31 | = (mean(R)-Rf=0)/StdDev(R)^2} 32 | 33 | As a performance metric, the Kelly Ratio is calculated 34 | retrospectively on a particular investment as a measure of 35 | the edge that investment has over the risk free rate. It 36 | may be use as a stack ranking method to compare investments 37 | in a manner similar to the various ratios related to the 38 | Sharpe ratio. 39 | } 40 | \examples{ 41 | data(managers) 42 | KellyRatio(managers[,1,drop=FALSE], Rf=.04/12) 43 | KellyRatio(managers[,1,drop=FALSE], Rf=managers[,10,drop=FALSE]) 44 | KellyRatio(managers[,1:6], Rf=managers[,10,drop=FALSE]) 45 | } 46 | \author{ 47 | Brian G. Peterson 48 | } 49 | \references{ 50 | Thorp, Edward O. (1997; revised 1998). The Kelly Criterion 51 | in Blackjack, Sports Betting, and the Stock Market. 52 | \url{http://www.bjmath.com/bjmath/thorp/paper.htm} \cr 53 | \url{http://en.wikipedia.org/wiki/Kelly_criterion} 54 | } 55 | \keyword{distribution} 56 | \keyword{models} 57 | \keyword{multivariate} 58 | \keyword{ts} 59 | 60 | -------------------------------------------------------------------------------- /man/M2Sortino.Rd: -------------------------------------------------------------------------------- 1 | \name{M2Sortino} 2 | \alias{M2Sortino} 3 | \title{M squared for Sortino of the return distribution} 4 | \usage{ 5 | M2Sortino(Ra, Rb, MAR = 0, ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset return} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{MAR}{the minimum acceptable return} 14 | 15 | \item{\dots}{any other passthru parameters} 16 | } 17 | \description{ 18 | M squared for Sortino is a M^2 calculated for Downside risk 19 | instead of Total Risk 20 | } 21 | \details{ 22 | \deqn{M^2_S = r_P + Sortino ratio * (\sigma_{DM} - 23 | \sigma_D)}{M^2 (Sortino) = Rp + Sortino ratio * 24 | (DownsideRiskBenchmark - DownsideRiskPortfolio)} 25 | 26 | where \eqn{M^2_S} is MSquared for Sortino, \eqn{r_P} is the 27 | annualised portfolio return, \eqn{\sigma_{DM}} is the 28 | benchmark annualised downside risk and \eqn{D} is the 29 | portfolio annualised downside risk 30 | } 31 | \examples{ 32 | data(portfolio_bacon) 33 | MAR = 0.005 34 | print(M2Sortino(portfolio_bacon[,1], portfolio_bacon[,2], MAR)) #expected 0.1035 35 | 36 | data(managers) 37 | MAR = 0 38 | print(MSquaredExcess(managers['1996',1], managers['1996',8], MAR)) 39 | print(MSquaredExcess(managers['1996',1:5], managers['1996',8], MAR)) 40 | } 41 | \author{ 42 | Matthieu Lestel 43 | } 44 | \references{ 45 | Carl Bacon, \emph{Practical portfolio performance 46 | measurement and attribution}, second edition 2008 p.102-103 47 | } 48 | \keyword{distribution} 49 | \keyword{models} 50 | \keyword{multivariate} 51 | \keyword{ts} 52 | 53 | -------------------------------------------------------------------------------- /man/MSquared.Rd: -------------------------------------------------------------------------------- 1 | \name{MSquared} 2 | \alias{MSquared} 3 | \title{M squared of the return distribution} 4 | \usage{ 5 | MSquared(Ra, Rb, Rf = 0, ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset return} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{Rf}{risk free rate, in same period as your returns} 14 | 15 | \item{\dots}{any other passthru parameters} 16 | } 17 | \description{ 18 | M squared is a risk adjusted return useful to judge the 19 | size of relative performance between differents portfolios. 20 | With it you can compare portfolios with different levels of 21 | risk. 22 | } 23 | \details{ 24 | \deqn{M^2 = r_P + SR * (\sigma_M - \sigma_P) = (r_P - r_F) 25 | * \frac{\sigma_M}{\sigma_P} + r_F}{M squared = Rp + SR * 26 | (Market risk - Portfolio risk) = (Rp - Rf) * Market risk / 27 | Portfolio risk + Rf} 28 | 29 | where \eqn{r_P} is the portfolio return annualized, 30 | \eqn{\sigma_M} is the market risk and \eqn{\sigma_P} is the 31 | portfolio risk 32 | } 33 | \examples{ 34 | data(portfolio_bacon) 35 | print(MSquared(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.10062 36 | 37 | data(managers) 38 | print(MSquared(managers['1996',1], managers['1996',8])) 39 | print(MSquared(managers['1996',1:5], managers['1996',8])) 40 | } 41 | \author{ 42 | Matthieu Lestel 43 | } 44 | \references{ 45 | Carl Bacon, \emph{Practical portfolio performance 46 | measurement and attribution}, second edition 2008 p.67-68 47 | } 48 | \keyword{distribution} 49 | \keyword{models} 50 | \keyword{multivariate} 51 | \keyword{ts} 52 | 53 | -------------------------------------------------------------------------------- /man/MSquaredExcess.Rd: -------------------------------------------------------------------------------- 1 | \name{MSquaredExcess} 2 | \alias{MSquaredExcess} 3 | \title{M squared excess of the return distribution} 4 | \usage{ 5 | MSquaredExcess(Ra, Rb, Rf = 0, Method = c("geometric", "arithmetic"), ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset return} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{Rf}{risk free rate, in same period as your returns} 14 | 15 | \item{Method}{one of "geometric" or "arithmetic" 16 | indicating the method to use to calculate MSquareExcess} 17 | 18 | \item{\dots}{any other passthru parameters} 19 | } 20 | \description{ 21 | M squared excess is the quantity above the standard M. 22 | There is a geometric excess return which is better for 23 | Bacon and an arithmetic excess return 24 | } 25 | \details{ 26 | \deqn{M^2 excess (geometric) = \frac{1 + M^2}{1 + b} - 27 | 1}{MSquared excess (geometric) = (1+M^2)/(1+b) - 1} 28 | \deqn{M^2 excess (arithmetic) = M^2 - b}{MSquared excess 29 | (arithmetic) = M^2 - b} 30 | 31 | where \eqn{M^2} is MSquared and \eqn{b} is the benchmark 32 | annualised return. 33 | } 34 | \examples{ 35 | data(portfolio_bacon) 36 | MSquaredExcess(portfolio_bacon[,1], portfolio_bacon[,2]) #expected -0.00998 37 | 38 | MSquaredExcess(portfolio_bacon[,1], portfolio_bacon[,2], Method="arithmetic") #expected -0.011 39 | 40 | data(managers) 41 | MSquaredExcess(managers['1996',1], managers['1996',8]) 42 | MSquaredExcess(managers['1996',1:5], managers['1996',8]) 43 | } 44 | \author{ 45 | Matthieu Lestel 46 | } 47 | \references{ 48 | Carl Bacon, \emph{Practical portfolio performance 49 | measurement and attribution}, second edition 2008 p.68 50 | } 51 | \keyword{distribution} 52 | \keyword{models} 53 | \keyword{multivariate} 54 | \keyword{ts} 55 | 56 | -------------------------------------------------------------------------------- /man/MartinRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{MartinRatio} 2 | \alias{MartinRatio} 3 | \title{Martin ratio of the return distribution} 4 | \usage{ 5 | MartinRatio(R, Rf = 0, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rf}{risk free rate, in same period as your returns} 12 | 13 | \item{\dots}{any other passthru parameters} 14 | } 15 | \description{ 16 | To calculate Martin ratio we divide the difference of the 17 | portfolio return and the risk free rate by the Ulcer index 18 | } 19 | \details{ 20 | \deqn{Martin ratio = \frac{r_P - r_F}{\sqrt{\sum^{n}_{i=1} 21 | \frac{{D'_i}^2}{n}}}}{Martin ratio = (rp - rf) / Ulcer 22 | index} 23 | 24 | where \eqn{r_P} is the annualized portfolio return, 25 | \eqn{r_F} is the risk free rate, \eqn{n} is the number of 26 | observations of the entire series, \eqn{D'_i} is the 27 | drawdown since previous peak in period i 28 | } 29 | \examples{ 30 | data(portfolio_bacon) 31 | print(MartinRatio(portfolio_bacon[,1])) #expected 1.70 32 | 33 | data(managers) 34 | print(MartinRatio(managers['1996'])) 35 | print(MartinRatio(managers['1996',1])) 36 | } 37 | \author{ 38 | Matthieu Lestel 39 | } 40 | \references{ 41 | Carl Bacon, \emph{Practical portfolio performance 42 | measurement and attribution}, second edition 2008 p.91 43 | } 44 | \keyword{distribution} 45 | \keyword{models} 46 | \keyword{multivariate} 47 | \keyword{ts} 48 | 49 | -------------------------------------------------------------------------------- /man/MeanAbsoluteDeviation.Rd: -------------------------------------------------------------------------------- 1 | \name{MeanAbsoluteDeviation} 2 | \alias{MeanAbsoluteDeviation} 3 | \title{Mean absolute deviation of the return distribution} 4 | \usage{ 5 | MeanAbsoluteDeviation(R, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{\dots}{any other passthru parameters} 12 | } 13 | \description{ 14 | To calculate Mean absolute deviation we take the sum of the 15 | absolute value of the difference between the returns and 16 | the mean of the returns and we divide it by the number of 17 | returns. 18 | } 19 | \details{ 20 | \deqn{MeanAbsoluteDeviation = \frac{\sum^{n}_{i=1}\mid r_i 21 | - \overline{r}\mid}{n}}{MeanAbsoluteDeviation = 22 | sum(|r-mean(r)|)/n } 23 | 24 | where \eqn{n} is the number of observations of the entire 25 | series, \eqn{r_i} is the return in month i and 26 | \eqn{\overline{r}} is the mean return 27 | } 28 | \examples{ 29 | data(portfolio_bacon) 30 | print(MeanAbsoluteDeviation(portfolio_bacon[,1])) #expected 0.0310 31 | 32 | data(managers) 33 | print(MeanAbsoluteDeviation(managers['1996'])) 34 | print(MeanAbsoluteDeviation(managers['1996',1])) 35 | } 36 | \author{ 37 | Matthieu Lestel 38 | } 39 | \references{ 40 | Carl Bacon, \emph{Practical portfolio performance 41 | measurement and attribution}, second edition 2008 p.62 42 | } 43 | \keyword{distribution} 44 | \keyword{models} 45 | \keyword{multivariate} 46 | \keyword{ts} 47 | 48 | -------------------------------------------------------------------------------- /man/Modigliani.Rd: -------------------------------------------------------------------------------- 1 | \name{Modigliani} 2 | \alias{Modigliani} 3 | \title{Modigliani-Modigliani measure} 4 | \usage{ 5 | Modigliani(Ra, Rb, Rf = 0, ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{Rf}{risk free rate, in same period as your returns} 14 | 15 | \item{\dots}{any other passthrough parameters} 16 | } 17 | \description{ 18 | The Modigliani-Modigliani measure is the portfolio return 19 | adjusted upward or downward to match the benchmark's 20 | standard deviation. This puts the portfolio return and the 21 | benchmark return on 'equal footing' from a standard 22 | deviation perspective. \deqn{MM_{p}=\frac{E[R_{p} - 23 | R_{f}]}{\sigma_{p}}=SR_{p} * \sigma_{b} + E[R_{f}]}{MMp = 24 | SRp * sigmab + E[Rf]} where \eqn{SR_{p}}{SRp} - Sharpe 25 | ratio, \eqn{\sigma_{b}}{sigmab} - benchmark standard 26 | deviation 27 | } 28 | \details{ 29 | This is also analogous to some approaches to 'risk parity' 30 | portfolios, which use (presumably costless) leverage to 31 | increase the portfolio standard deviation to some target. 32 | } 33 | \examples{ 34 | data(managers) 35 | Modigliani(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12) 36 | Modigliani(managers[,1:6], managers[,8,drop=FALSE], managers[,8,drop=FALSE]) 37 | Modigliani(managers[,1:6], managers[,8:7], managers[,8,drop=FALSE]) 38 | } 39 | \author{ 40 | Andrii Babii, Brian G. Peterson 41 | } 42 | \references{ 43 | J. Christopherson, D. Carino, W. Ferson. \emph{Portfolio 44 | Performance Measurement and Benchmarking}. 2009. 45 | McGraw-Hill, p. 97-99. \cr Franco Modigliani and Leah 46 | Modigliani, "Risk-Adjusted Performance: How to Measure It 47 | and Why," \emph{Journal of Portfolio Management}, vol.23, 48 | no., Winter 1997, pp.45-54 \cr 49 | } 50 | \seealso{ 51 | \code{\link{SharpeRatio}}, \code{\link{TreynorRatio}} 52 | } 53 | 54 | -------------------------------------------------------------------------------- /man/NetSelectivity.Rd: -------------------------------------------------------------------------------- 1 | \name{NetSelectivity} 2 | \alias{NetSelectivity} 3 | \title{Net selectivity of the return distribution} 4 | \usage{ 5 | NetSelectivity(Ra, Rb, Rf = 0, ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{Rf}{risk free rate, in same period as your returns} 14 | 15 | \item{\dots}{any other passthru parameters} 16 | } 17 | \description{ 18 | Net selectivity is the remaining selectivity after 19 | deducting the amount of return require to justify not being 20 | fully diversified 21 | } 22 | \details{ 23 | If net selectivity is negative the portfolio manager has 24 | not justified the loss of diversification 25 | 26 | \deqn{Net selectivity = \alpha - d}{Net selectivity = 27 | Selectity - diversification} 28 | 29 | where \eqn{\alpha} is the selectivity and \eqn{d} is the 30 | diversification 31 | } 32 | \examples{ 33 | data(portfolio_bacon) 34 | print(NetSelectivity(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.017 35 | 36 | data(managers) 37 | print(NetSelectivity(managers['1996',1], managers['1996',8])) 38 | print(NetSelectivity(managers['1996',1:5], managers['1996',8])) 39 | } 40 | \author{ 41 | Matthieu Lestel 42 | } 43 | \references{ 44 | Carl Bacon, \emph{Practical portfolio performance 45 | measurement and attribution}, second edition 2008 p.78 46 | } 47 | \keyword{distribution} 48 | \keyword{models} 49 | \keyword{multivariate} 50 | \keyword{ts} 51 | 52 | -------------------------------------------------------------------------------- /man/OmegaExcessReturn.Rd: -------------------------------------------------------------------------------- 1 | \name{OmegaExcessReturn} 2 | \alias{OmegaExcessReturn} 3 | \alias{OmegaExessReturn} 4 | \title{Omega excess return of the return distribution} 5 | \usage{ 6 | OmegaExcessReturn(Ra, Rb, MAR = 0, ...) 7 | } 8 | \arguments{ 9 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{Rb}{return vector of the benchmark asset} 13 | 14 | \item{MAR}{the minimum acceptable return} 15 | 16 | \item{\dots}{any other passthru parameters} 17 | } 18 | \description{ 19 | Omega excess return is another form of downside 20 | risk-adjusted return. It is calculated by multiplying the 21 | downside variance of the style benchmark by 3 times the 22 | style beta. 23 | } 24 | \details{ 25 | \deqn{\omega = r_P - 3*\beta_S*\sigma_{MD}^2}{ 26 | OmegaExcessReturn = Portfolio return - 3*style beta*style 27 | benchmark variance squared} 28 | 29 | where \eqn{\omega} is omega excess return, \eqn{\beta_S} is 30 | style beta, \eqn{\sigma_D} is the portfolio annualised 31 | downside risk and \eqn{\sigma_{MD}} is the benchmark 32 | annualised downside risk. 33 | } 34 | \examples{ 35 | data(portfolio_bacon) 36 | MAR = 0.005 37 | print(OmegaExcessReturn(portfolio_bacon[,1], portfolio_bacon[,2], MAR)) #expected 0.0805 38 | 39 | data(managers) 40 | MAR = 0 41 | print(OmegaExcessReturn(managers['1996',1], managers['1996',8], MAR)) 42 | print(OmegaExcessReturn(managers['1996',1:5], managers['1996',8], MAR)) 43 | } 44 | \author{ 45 | Matthieu Lestel 46 | } 47 | \references{ 48 | Carl Bacon, \emph{Practical portfolio performance 49 | measurement and attribution}, second edition 2008 p.103 50 | } 51 | \keyword{distribution} 52 | \keyword{models} 53 | \keyword{multivariate} 54 | \keyword{ts} 55 | 56 | -------------------------------------------------------------------------------- /man/OmegaSharpeRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{OmegaSharpeRatio} 2 | \alias{OmegaSharpeRatio} 3 | \title{Omega-Sharpe ratio of the return distribution} 4 | \usage{ 5 | OmegaSharpeRatio(R, MAR = 0, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{MAR}{Minimum Acceptable Return, in the same 12 | periodicity as your returns} 13 | 14 | \item{\dots}{any other passthru parameters} 15 | } 16 | \description{ 17 | The Omega-Sharpe ratio is a conversion of the omega ratio 18 | to a ranking statistic in familiar form to the Sharpe 19 | ratio. 20 | } 21 | \details{ 22 | To calculate the Omega-Sharpe ration we subtract the target 23 | (or Minimum Acceptable Returns (MAR)) return from the 24 | portfolio return and we divide it by the opposite of the 25 | Downside Deviation. 26 | 27 | \deqn{OmegaSharpeRatio(R,MAR) = \frac{r_p - 28 | r_t}{\sum^n_{t=1}\frac{max(r_t - r_i, 29 | 0)}{n}}}{OmegaSharpeRatio(R,MAR) = (Rp - Rt) / 30 | -DownsidePotential(R,MAR)} 31 | 32 | where \eqn{n} is the number of observations of the entire 33 | series 34 | } 35 | \examples{ 36 | data(portfolio_bacon) 37 | MAR = 0.005 38 | print(OmegaSharpeRatio(portfolio_bacon[,1], MAR)) #expected 0.29 39 | 40 | MAR = 0 41 | data(managers) 42 | print(OmegaSharpeRatio(managers['1996'], MAR)) 43 | print(OmegaSharpeRatio(managers['1996',1], MAR)) #expected 3.60 44 | } 45 | \author{ 46 | Matthieu Lestel 47 | } 48 | \references{ 49 | Carl Bacon, \emph{Practical portfolio performance 50 | measurement and attribution}, second edition 2008, p.95 51 | } 52 | \keyword{distribution} 53 | \keyword{models} 54 | \keyword{multivariate} 55 | \keyword{ts} 56 | 57 | -------------------------------------------------------------------------------- /man/PainIndex.Rd: -------------------------------------------------------------------------------- 1 | \name{PainIndex} 2 | \alias{PainIndex} 3 | \title{Pain index of the return distribution} 4 | \usage{ 5 | PainIndex(R, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{\dots}{any other passthru parameters} 12 | } 13 | \description{ 14 | The pain index is the mean value of the drawdowns over the 15 | entire analysis period. The measure is similar to the Ulcer 16 | index except that the drawdowns are not squared. Also, 17 | it's different than the average drawdown, in that the 18 | numerator is the total number of observations rather than 19 | the number of drawdowns. 20 | } 21 | \details{ 22 | Visually, the pain index is the area of the region that is 23 | enclosed by the horizontal line at zero percent and the 24 | drawdown line in the Drawdown chart. 25 | 26 | \deqn{Pain index = \sum^{n}_{i=1} \frac{\mid D'_i 27 | \mid}{n}}{Pain index = sum(|D'i|/n)} 28 | 29 | where \eqn{n} is the number of observations of the entire 30 | series, \eqn{D'_i} is the drawdown since previous peak in 31 | period i 32 | } 33 | \examples{ 34 | data(portfolio_bacon) 35 | print(PainIndex(portfolio_bacon[,1])) #expected 0.04 36 | 37 | data(managers) 38 | print(PainIndex(100*managers['1996'])) 39 | print(PainIndex(100*managers['1996',1])) 40 | } 41 | \author{ 42 | Matthieu Lestel 43 | } 44 | \references{ 45 | Carl Bacon, \emph{Practical portfolio performance 46 | measurement and attribution}, second edition 2008 p.89, 47 | Becker, Thomas (2006) Zephyr Associates 48 | } 49 | \keyword{distribution} 50 | \keyword{models} 51 | \keyword{multivariate} 52 | \keyword{ts} 53 | 54 | -------------------------------------------------------------------------------- /man/PainRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{PainRatio} 2 | \alias{PainRatio} 3 | \title{Pain ratio of the return distribution} 4 | \usage{ 5 | PainRatio(R, Rf = 0, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rf}{risk free rate, in same period as your returns} 12 | 13 | \item{\dots}{any other passthru parameters} 14 | } 15 | \description{ 16 | To calculate Pain ratio we divide the difference of the 17 | portfolio return and the risk free rate by the Pain index 18 | } 19 | \details{ 20 | \deqn{Pain ratio = \frac{r_P - r_F}{\sum^{n}_{i=1} 21 | \frac{\mid D'_i \mid}{n}}}{Pain ratio = (rp - rf) / Pain 22 | index} 23 | 24 | where \eqn{r_P} is the annualized portfolio return, 25 | \eqn{r_F} is the risk free rate, \eqn{n} is the number of 26 | observations of the entire series, \eqn{D'_i} is the 27 | drawdown since previous peak in period i 28 | } 29 | \examples{ 30 | data(portfolio_bacon) 31 | print(PainRatio(portfolio_bacon[,1])) #expected 2.66 32 | 33 | data(managers) 34 | print(PainRatio(managers['1996'])) 35 | print(PainRatio(managers['1996',1])) 36 | } 37 | \author{ 38 | Matthieu Lestel 39 | } 40 | \references{ 41 | Carl Bacon, \emph{Practical portfolio performance 42 | measurement and attribution}, second edition 2008 p.91 43 | } 44 | \keyword{distribution} 45 | \keyword{models} 46 | \keyword{multivariate} 47 | \keyword{ts} 48 | 49 | -------------------------------------------------------------------------------- /man/ProspectRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{ProspectRatio} 2 | \alias{ProspectRatio} 3 | \title{Prospect ratio of the return distribution} 4 | \usage{ 5 | ProspectRatio(R, MAR, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{MAR}{the minimum acceptable return} 12 | 13 | \item{\dots}{any other passthru parameters} 14 | } 15 | \description{ 16 | Prospect ratio is a ratio used to penalise loss since most 17 | people feel loss greater than gain 18 | } 19 | \details{ 20 | \deqn{ProspectRatio(R) = 21 | \frac{\frac{1}{n}*\sum^{n}_{i=1}(Max(r_i,0)+2.25*Min(r_i,0) 22 | - MAR)}{\sigma_D}}{ProspectRatio(R) = (1/n * sum(Max(ri,0) 23 | + 2.25 * Min(ri,0)) - MAR) / DownsideRisk} 24 | 25 | where \eqn{n} is the number of observations of the entire 26 | series, MAR is the minimum acceptable return and 27 | \eqn{\sigma_D} is the downside risk 28 | } 29 | \examples{ 30 | data(portfolio_bacon) 31 | MAR = 0.05 32 | print(ProspectRatio(portfolio_bacon[,1], MAR)) #expected -0.134 33 | 34 | data(managers) 35 | MAR = 0 36 | print(ProspectRatio(managers['1996'], MAR)) 37 | print(ProspectRatio(managers['1996',1], MAR)) 38 | } 39 | \author{ 40 | Matthieu Lestel 41 | } 42 | \references{ 43 | Carl Bacon, \emph{Practical portfolio performance 44 | measurement and attribution}, second edition 2008 p.100 45 | } 46 | \keyword{distribution} 47 | \keyword{models} 48 | \keyword{multivariate} 49 | \keyword{ts} 50 | 51 | -------------------------------------------------------------------------------- /man/Return.annualized.Rd: -------------------------------------------------------------------------------- 1 | \name{Return.annualized} 2 | \alias{Return.annualized} 3 | \title{calculate an annualized return for comparing instruments with different 4 | length history} 5 | \usage{ 6 | Return.annualized(R, scale = NA, geometric = TRUE) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{scale}{number of periods in a year (daily scale = 13 | 252, monthly scale = 12, quarterly scale = 4)} 14 | 15 | \item{geometric}{utilize geometric chaining (TRUE) or 16 | simple/arithmetic chaining (FALSE) to aggregate returns, 17 | default TRUE} 18 | } 19 | \description{ 20 | An average annualized return is convenient for comparing 21 | returns. 22 | } 23 | \details{ 24 | Annualized returns are useful for comparing two assets. To 25 | do so, you must scale your observations to an annual scale 26 | by raising the compound return to the number of periods in 27 | a year, and taking the root to the number of total 28 | observations: 29 | \deqn{prod(1+R_{a})^{\frac{scale}{n}}-1=\sqrt[n]{prod(1+R_{a})^{scale}}-1}{prod(1 30 | + Ra)^(scale/n) - 1} 31 | 32 | where scale is the number of periods in a year, and n is 33 | the total number of periods for which you have 34 | observations. 35 | 36 | For simple returns (geometric=FALSE), the formula is: 37 | 38 | \deqn{\overline{R_{a}} \cdot scale}{mean(R)*scale} 39 | } 40 | \examples{ 41 | data(managers) 42 | Return.annualized(managers[,1,drop=FALSE]) 43 | Return.annualized(managers[,1:8]) 44 | Return.annualized(managers[,1:8],geometric=FALSE) 45 | } 46 | \author{ 47 | Peter Carl 48 | } 49 | \references{ 50 | Bacon, Carl. \emph{Practical Portfolio Performance 51 | Measurement and Attribution}. Wiley. 2004. p. 6 52 | } 53 | \seealso{ 54 | \code{\link{Return.cumulative}}, 55 | } 56 | \keyword{distribution} 57 | \keyword{models} 58 | \keyword{multivariate} 59 | \keyword{ts} 60 | 61 | -------------------------------------------------------------------------------- /man/Return.cumulative.Rd: -------------------------------------------------------------------------------- 1 | \name{Return.cumulative} 2 | \alias{Return.cumulative} 3 | \title{calculate a compounded (geometric) cumulative return} 4 | \usage{ 5 | Return.cumulative(R, geometric = TRUE) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{geometric}{utilize geometric chaining (TRUE) or 12 | simple/arithmetic chaining (FALSE) to aggregate returns, 13 | default TRUE} 14 | } 15 | \description{ 16 | This is a useful function for calculating cumulative return 17 | over a period of time, say a calendar year. Can produce 18 | simple or geometric return. 19 | } 20 | \details{ 21 | product of all the individual period returns 22 | 23 | \deqn{(1+r_{1})(1+r_{2})(1+r_{3})\ldots(1+r_{n})-1=prod(1+R)-1}{prod(1+R)-1} 24 | } 25 | \examples{ 26 | data(managers) 27 | Return.cumulative(managers[,1,drop=FALSE]) 28 | Return.cumulative(managers[,1:8]) 29 | Return.cumulative(managers[,1:8],geometric=FALSE) 30 | } 31 | \author{ 32 | Peter Carl 33 | } 34 | \references{ 35 | Bacon, Carl. \emph{Practical Portfolio Performance 36 | Measurement and Attribution}. Wiley. 2004. p. 6 37 | } 38 | \seealso{ 39 | \code{\link{Return.annualized}} 40 | } 41 | \keyword{distribution} 42 | \keyword{models} 43 | \keyword{multivariate} 44 | \keyword{ts} 45 | 46 | -------------------------------------------------------------------------------- /man/Return.excess.Rd: -------------------------------------------------------------------------------- 1 | \name{Return.excess} 2 | \alias{Return.excess} 3 | \title{Calculates the returns of an asset in excess of the given risk free rate} 4 | \usage{ 5 | Return.excess(R, Rf = 0) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rf}{risk free rate, in same period as your returns, 12 | or as a single digit average} 13 | } 14 | \description{ 15 | Calculates the returns of an asset in excess of the given 16 | "risk free rate" for the period. 17 | } 18 | \details{ 19 | Ideally, your risk free rate will be for each period you 20 | have returns observations, but a single average return for 21 | the period will work too. 22 | 23 | Mean of the period return minus the period risk free rate 24 | 25 | \deqn{\overline{(R_{a}-R_{f})}}{mean(Ra-Rf=0)} 26 | 27 | OR 28 | 29 | mean of the period returns minus a single numeric risk free 30 | rate 31 | 32 | \deqn{\overline{R_{a}}-R_{f}}{mean(R)-rf} 33 | 34 | Note that while we have, in keeping with common academic 35 | usage, assumed that the second parameter will be a risk 36 | free rate, you may also use any other timeseries as the 37 | second argument. A common alteration would be to use a 38 | benchmark to produce excess returns over a specific 39 | benchmark, as demonstrated in the examples below. 40 | } 41 | \examples{ 42 | data(managers) 43 | head(Return.excess(managers[,1,drop=FALSE], managers[,10,drop=FALSE])) 44 | head(Return.excess(managers[,1,drop=FALSE], .04/12)) 45 | head(Return.excess(managers[,1:6], managers[,10,drop=FALSE])) 46 | head(Return.excess(managers[,1,drop=FALSE], managers[,8,drop=FALSE])) 47 | } 48 | \author{ 49 | Peter Carl 50 | } 51 | \references{ 52 | Bacon, Carl. \emph{Practical Portfolio Performance 53 | Measurement and Attribution}. Wiley. 2004. p. 47-52 54 | } 55 | \keyword{distribution} 56 | \keyword{models} 57 | \keyword{multivariate} 58 | \keyword{ts} 59 | 60 | -------------------------------------------------------------------------------- /man/Return.relative.Rd: -------------------------------------------------------------------------------- 1 | \name{Return.relative} 2 | \alias{Return.relative} 3 | \title{calculate the relative return of one asset to another} 4 | \usage{ 5 | Return.relative(Ra, Rb, ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return object for the benchmark asset} 12 | 13 | \item{\dots}{ignored} 14 | } 15 | \value{ 16 | xts or other time series of relative return 17 | } 18 | \description{ 19 | Calculates the ratio of the cumulative performance for two 20 | assets through time. 21 | } 22 | \examples{ 23 | data(managers) 24 | head(Return.relative(managers[,1:3], managers[,8,drop=FALSE]),n=20) 25 | } 26 | \author{ 27 | Peter Carl 28 | } 29 | \seealso{ 30 | \code{\link{chart.RelativePerformance}} 31 | } 32 | \keyword{ts} 33 | 34 | -------------------------------------------------------------------------------- /man/Selectivity.Rd: -------------------------------------------------------------------------------- 1 | \name{Selectivity} 2 | \alias{Selectivity} 3 | \title{Selectivity of the return distribution} 4 | \usage{ 5 | Selectivity(Ra, Rb, Rf = 0, ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{Rf}{risk free rate, in same period as your returns} 14 | 15 | \item{\dots}{any other passthru parameters} 16 | } 17 | \description{ 18 | Selectivity is the same as Jensen's alpha 19 | } 20 | \details{ 21 | \deqn{Selectivity = r_p - r_f - \beta_p * (b - 22 | r_f)}{Selectivity = r_p - r_f - beta_p * (b - r_f)} 23 | 24 | where \eqn{r_f} is the risk free rate, \eqn{\beta_r} is the 25 | regression beta, \eqn{r_p} is the portfolio return and b is 26 | the benchmark return 27 | } 28 | \examples{ 29 | data(portfolio_bacon) 30 | print(Selectivity(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.0141 31 | 32 | data(managers) 33 | print(Selectivity(managers['1996',1], managers['1996',8])) 34 | print(Selectivity(managers['1996',1:5], managers['1996',8])) 35 | } 36 | \author{ 37 | Matthieu Lestel 38 | } 39 | \references{ 40 | Carl Bacon, \emph{Practical portfolio performance 41 | measurement and attribution}, second edition 2008 p.78 42 | } 43 | \keyword{distribution} 44 | \keyword{models} 45 | \keyword{multivariate} 46 | \keyword{ts} 47 | 48 | -------------------------------------------------------------------------------- /man/SkewnessKurtosisRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{SkewnessKurtosisRatio} 2 | \alias{Skewness-KurtosisRatio} 3 | \alias{SkewnessKurtosisRatio} 4 | \title{Skewness-Kurtosis ratio of the return distribution} 5 | \usage{ 6 | SkewnessKurtosisRatio(R, ...) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{\dots}{any other passthru parameters} 13 | } 14 | \description{ 15 | Skewness-Kurtosis ratio is the division of Skewness by 16 | Kurtosis. 17 | } 18 | \details{ 19 | It is used in conjunction with the Sharpe ratio to rank 20 | portfolios. The higher the rate the better. 21 | 22 | \deqn{ SkewnessKurtosisRatio(R , MAR) = 23 | \frac{S}{K}}{SkewnessKurtosisRatio(R, MAR) = S/K} 24 | 25 | where \eqn{S} is the skewness and \eqn{K} is the Kurtosis 26 | } 27 | \examples{ 28 | data(portfolio_bacon) 29 | print(SkewnessKurtosisRatio(portfolio_bacon[,1])) #expected -0.034 30 | 31 | data(managers) 32 | print(SkewnessKurtosisRatio(managers['1996'])) 33 | print(SkewnessKurtosisRatio(managers['1996',1])) 34 | } 35 | \author{ 36 | Matthieu Lestel 37 | } 38 | \references{ 39 | Carl Bacon, \emph{Practical portfolio performance 40 | measurement and attribution}, second edition 2008 p.100 41 | } 42 | \keyword{distribution} 43 | \keyword{models} 44 | \keyword{multivariate} 45 | \keyword{ts} 46 | 47 | -------------------------------------------------------------------------------- /man/SpecificRisk.Rd: -------------------------------------------------------------------------------- 1 | \name{SpecificRisk} 2 | \alias{SpecificRisk} 3 | \title{Specific risk of the return distribution} 4 | \usage{ 5 | SpecificRisk(Ra, Rb, Rf = 0, ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{Rf}{risk free rate, in same period as your returns} 14 | 15 | \item{\dots}{any other passthru parameters} 16 | } 17 | \description{ 18 | Specific risk is the standard deviation of the error term 19 | in the regression equation. 20 | } 21 | \examples{ 22 | data(portfolio_bacon) 23 | print(SpecificRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.0329 24 | 25 | data(managers) 26 | print(SpecificRisk(managers['1996',1], managers['1996',8])) 27 | print(SpecificRisk(managers['1996',1:5], managers['1996',8])) 28 | } 29 | \author{ 30 | Matthieu Lestel 31 | } 32 | \references{ 33 | Carl Bacon, \emph{Practical portfolio performance 34 | measurement and attribution}, second edition 2008 p.75 35 | } 36 | \keyword{distribution} 37 | \keyword{models} 38 | \keyword{multivariate} 39 | \keyword{ts} 40 | 41 | -------------------------------------------------------------------------------- /man/SystematicRisk.Rd: -------------------------------------------------------------------------------- 1 | \name{SystematicRisk} 2 | \alias{SystematicRisk} 3 | \title{Systematic risk of the return distribution} 4 | \usage{ 5 | SystematicRisk(Ra, Rb, Rf = 0, scale = NA, ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{Rf}{risk free rate, in same period as your returns} 14 | 15 | \item{scale}{number of periods in a year (daily scale = 16 | 252, monthly scale = 12, quarterly scale = 4)} 17 | 18 | \item{\dots}{any other passthru parameters} 19 | } 20 | \description{ 21 | Systematic risk as defined by Bacon(2008) is the product of 22 | beta by market risk. Be careful ! It's not the same 23 | definition as the one given by Michael Jensen. Market risk 24 | is the standard deviation of the benchmark. The systematic 25 | risk is annualized 26 | } 27 | \details{ 28 | \deqn{\sigma_s = \beta * \sigma_m}{systematic risk = beta * 29 | market risk} 30 | 31 | where \eqn{\sigma_s} is the systematic risk, \eqn{\beta} is 32 | the regression beta, and \eqn{\sigma_m} is the market risk 33 | } 34 | \examples{ 35 | data(portfolio_bacon) 36 | print(SystematicRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.013 37 | 38 | data(managers) 39 | print(SystematicRisk(managers['1996',1], managers['1996',8])) 40 | print(SystematicRisk(managers['1996',1:5], managers['1996',8])) 41 | } 42 | \author{ 43 | Matthieu Lestel 44 | } 45 | \references{ 46 | Carl Bacon, \emph{Practical portfolio performance 47 | measurement and attribution}, second edition 2008 p.75 48 | } 49 | \keyword{distribution} 50 | \keyword{models} 51 | \keyword{multivariate} 52 | \keyword{ts} 53 | 54 | -------------------------------------------------------------------------------- /man/TotalRisk.Rd: -------------------------------------------------------------------------------- 1 | \name{TotalRisk} 2 | \alias{TotalRisk} 3 | \title{Total risk of the return distribution} 4 | \usage{ 5 | TotalRisk(Ra, Rb, Rf = 0, ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{Rf}{risk free rate, in same period as your returns} 14 | 15 | \item{\dots}{any other passthru parameters} 16 | } 17 | \description{ 18 | The square of total risk is the sum of the square of 19 | systematic risk and the square of specific risk. Specific 20 | risk is the standard deviation of the error term in the 21 | regression equation. Both terms are annualized to calculate 22 | total risk. 23 | } 24 | \details{ 25 | \deqn{Total Risk = \sqrt{Systematic Risk^2 + Specific 26 | Risk^2}}{Total Risk^2 = Systematic Risk^2 + Specific 27 | Risk^2} 28 | } 29 | \examples{ 30 | data(portfolio_bacon) 31 | print(TotalRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.0134 32 | 33 | data(managers) 34 | print(TotalRisk(managers['1996',1], managers['1996',8])) 35 | print(TotalRisk(managers['1996',1:5], managers['1996',8])) 36 | } 37 | \author{ 38 | Matthieu Lestel 39 | } 40 | \references{ 41 | Carl Bacon, \emph{Practical portfolio performance 42 | measurement and attribution}, second edition 2008 p.75 43 | } 44 | \keyword{distribution} 45 | \keyword{models} 46 | \keyword{multivariate} 47 | \keyword{ts} 48 | 49 | -------------------------------------------------------------------------------- /man/TrackingError.Rd: -------------------------------------------------------------------------------- 1 | \name{TrackingError} 2 | \alias{TrackingError} 3 | \title{Calculate Tracking Error of returns against a benchmark} 4 | \usage{ 5 | TrackingError(Ra, Rb, scale = NA) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{scale}{number of periods in a year (daily scale = 14 | 252, monthly scale = 12, quarterly scale = 4)} 15 | } 16 | \description{ 17 | A measure of the unexplained portion of performance 18 | relative to a benchmark. 19 | } 20 | \details{ 21 | Tracking error is calculated by taking the square root of 22 | the average of the squared deviations between the 23 | investment's returns and the benchmark's returns, then 24 | multiplying the result by the square root of the scale of 25 | the returns. 26 | 27 | \deqn{ TrackingError = 28 | \sqrt{\sum\frac{(R_{a}-R_{b})^{2}}{len(R_{a})\sqrt{scale}}} 29 | }{ TrackingError = sqrt(sum(Ra - Rb)^2 / (length(R) - 1)) * 30 | sqrt(scale)} 31 | } 32 | \examples{ 33 | data(managers) 34 | TrackingError(managers[,1,drop=FALSE], managers[,8,drop=FALSE]) 35 | TrackingError(managers[,1:6], managers[,8,drop=FALSE]) 36 | TrackingError(managers[,1:6], managers[,8:7,drop=FALSE]) 37 | } 38 | \author{ 39 | Peter Carl 40 | } 41 | \references{ 42 | Sharpe, W.F. The Sharpe Ratio,\emph{Journal of Portfolio 43 | Management},Fall 1994, 49-58. 44 | } 45 | \seealso{ 46 | \code{\link{InformationRatio}} \code{\link{TrackingError}} 47 | } 48 | \keyword{distribution} 49 | \keyword{models} 50 | \keyword{multivariate} 51 | \keyword{ts} 52 | 53 | -------------------------------------------------------------------------------- /man/UlcerIndex.Rd: -------------------------------------------------------------------------------- 1 | \name{UlcerIndex} 2 | \alias{UlcerIndex} 3 | \title{calculate the Ulcer Index} 4 | \usage{ 5 | UlcerIndex(R, ...) 6 | } 7 | \arguments{ 8 | \item{R}{a vector, matrix, data frame, timeSeries or zoo 9 | object of asset returns} 10 | 11 | \item{\dots}{any other passthru parameters} 12 | } 13 | \description{ 14 | Developed by Peter G. Martin in 1987 (Martin and McCann, 15 | 1987) and named for the worry caused to the portfolio 16 | manager or investor. This is similar to drawdown deviation 17 | except that the impact of the duration of drawdowns is 18 | incorporated by selecting the negative return for each 19 | period below the previous peak or high water mark. The 20 | impact of long, deep drawdowns will have significant impact 21 | because the underperformance since the last peak is 22 | squared. 23 | } 24 | \details{ 25 | UI = sqrt(sum[i=1,2,...,n](D'_i^2/n)) where D'_i = drawdown 26 | since previous peak in period i 27 | 28 | DETAILS: This approach is sensitive to the frequency of the 29 | time periods involved and penalizes managers that take time 30 | to recover to previous highs. 31 | 32 | REFERENCES: Martin, P. and McCann, B. (1989) The investor's 33 | Guide to Fidelity Funds: Winning Strategies for Mutual Fund 34 | Investors. John Wiley & Sons, Inc. Peter Martin's web page 35 | on UI: http://www.tangotools.com/ui/ui.htm 36 | 37 | ## Test against spreadsheet at: 38 | http://www.tangotools.com/ui/UlcerIndex.xls 39 | } 40 | \author{ 41 | Matthieu Lestel 42 | } 43 | 44 | -------------------------------------------------------------------------------- /man/UpsideFrequency.Rd: -------------------------------------------------------------------------------- 1 | \name{UpsideFrequency} 2 | \alias{UpsideFrequency} 3 | \title{upside frequency of the return distribution} 4 | \usage{ 5 | UpsideFrequency(R, MAR = 0, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{MAR}{Minimum Acceptable Return, in the same 12 | periodicity as your returns} 13 | 14 | \item{\dots}{any other passthru parameters} 15 | } 16 | \description{ 17 | To calculate Upside Frequency, we take the subset of 18 | returns that are more than the target (or Minimum 19 | Acceptable Returns (MAR)) returns and divide the length of 20 | this subset by the total number of returns. 21 | } 22 | \details{ 23 | \deqn{ UpsideFrequency(R , MAR) = 24 | \sum^{n}_{t=1}\frac{max[(R_{t} - MAR), 25 | 0]}{R_{t}*n}}{UpsideFrequency(R, MAR) = length(subset of 26 | returns above MAR) / length(total returns)} 27 | 28 | where \eqn{n} is the number of observations of the entire 29 | series 30 | } 31 | \examples{ 32 | data(portfolio_bacon) 33 | MAR = 0.005 34 | print(UpsideFrequency(portfolio_bacon[,1], MAR)) #expected 0.542 35 | 36 | data(managers) 37 | print(UpsideFrequency(managers['1996'])) 38 | print(UpsideFrequency(managers['1996',1])) #expected 0.75 39 | } 40 | \author{ 41 | Matthieu Lestel 42 | } 43 | \references{ 44 | Carl Bacon, \emph{Practical portfolio performance 45 | measurement and attribution}, second edition 2008 p.94 46 | } 47 | \keyword{distribution} 48 | \keyword{models} 49 | \keyword{multivariate} 50 | \keyword{ts} 51 | 52 | -------------------------------------------------------------------------------- /man/VolatilitySkewness.Rd: -------------------------------------------------------------------------------- 1 | \name{VolatilitySkewness} 2 | \alias{VolatilitySkewness} 3 | \title{Volatility and variability of the return distribution} 4 | \usage{ 5 | VolatilitySkewness(R, MAR = 0, stat = c("volatility", "variability"), ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{MAR}{Minimum Acceptable Return, in the same 12 | periodicity as your returns} 13 | 14 | \item{stat}{one of "volatility", "variability" indicating 15 | whether to return the volatility skewness or the 16 | variability skweness} 17 | 18 | \item{\dots}{any other passthru parameters} 19 | } 20 | \description{ 21 | Volatility skewness is a similar measure to omega but using 22 | the second partial moment. It's the ratio of the upside 23 | variance compared to the downside variance. Variability 24 | skewness is the ratio of the upside risk compared to the 25 | downside risk. 26 | } 27 | \details{ 28 | \deqn{ VolatilitySkewness(R , MAR) = 29 | \frac{\sigma_U^2}{\sigma_D^2}}{VolatilitySkewness(R, MAR) = 30 | UpsideVariance / DownsideVariance} 31 | 32 | \deqn{ VariabilitySkewness(R , MAR) = 33 | \frac{\sigma_U}{\sigma_D}}{VariabilitySkewness(R, MAR) = 34 | UpsideRisk / DownsideRisk} 35 | 36 | where \eqn{\sigma_U} is the Upside risk and \eqn{\sigma_D} 37 | is the Downside Risk 38 | } 39 | \examples{ 40 | data(portfolio_bacon) 41 | MAR = 0.005 42 | print(VolatilitySkewness(portfolio_bacon[,1], MAR, stat="volatility")) #expected 1.32 43 | print(VolatilitySkewness(portfolio_bacon[,1], MAR, stat="variability")) #expected 1.15 44 | 45 | MAR = 0 46 | data(managers) 47 | # print(VolatilitySkewness(managers['1996'], MAR, stat="volatility")) 48 | print(VolatilitySkewness(managers['1996',1], MAR, stat="volatility")) 49 | } 50 | \author{ 51 | Matthieu Lestel 52 | } 53 | \references{ 54 | Carl Bacon, \emph{Practical portfolio performance 55 | measurement and attribution}, second edition 2008 p.97-98 56 | } 57 | \keyword{distribution} 58 | \keyword{models} 59 | \keyword{multivariate} 60 | \keyword{ts} 61 | 62 | -------------------------------------------------------------------------------- /man/apply.fromstart.Rd: -------------------------------------------------------------------------------- 1 | \name{apply.fromstart} 2 | \alias{apply.fromstart} 3 | \title{calculate a function over an expanding window always starting from the 4 | beginning of the series} 5 | \usage{ 6 | apply.fromstart(R, FUN = "mean", gap = 1, ...) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{FUN}{any function that can be evaluated using a 13 | single set of returns (e.g., rolling beta won't work, but 14 | \code{\link{Return.annualized}} will)} 15 | 16 | \item{gap}{the number of data points from the beginning 17 | of the series required to \dQuote{train} the calculation} 18 | 19 | \item{\dots}{any other passthru parameters} 20 | } 21 | \description{ 22 | A function to calculate a function over an expanding window 23 | from the start of the timeseries. This wrapper allows easy 24 | calculation of \dQuote{from inception} statistics. 25 | } 26 | \examples{ 27 | data(managers) 28 | apply.fromstart(managers[,1,drop=FALSE], FUN="mean", width=36) 29 | } 30 | \author{ 31 | Peter Carl 32 | } 33 | \seealso{ 34 | \code{\link[zoo]{rollapply}} 35 | } 36 | \keyword{distribution} 37 | \keyword{models} 38 | \keyword{multivariate} 39 | \keyword{ts} 40 | 41 | -------------------------------------------------------------------------------- /man/apply.rolling.Rd: -------------------------------------------------------------------------------- 1 | \name{apply.rolling} 2 | \alias{apply.rolling} 3 | \title{calculate a function over a rolling window} 4 | \usage{ 5 | apply.rolling(R, width, trim = TRUE, gap = 12, by = 1, FUN = "mean", 6 | ...) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{width}{number of periods to apply rolling function 13 | window over} 14 | 15 | \item{gap}{numeric number of periods from start of series 16 | to use to train risk calculation} 17 | 18 | \item{trim}{TRUE/FALSE, whether to keep alignment caused 19 | by NA's} 20 | 21 | \item{FUN}{any function that can be evaluated using a 22 | single set of returns (e.g., rolling beta won't work, but 23 | \code{\link{Return.annualized}} will)} 24 | 25 | \item{by}{calculate FUN for trailing width points at 26 | every by-th time point.} 27 | 28 | \item{\dots}{any other passthru parameters} 29 | } 30 | \value{ 31 | A timeseries in a zoo object of the calculation results 32 | } 33 | \description{ 34 | Creates a results timeseries of a function applied over a 35 | rolling window. 36 | } 37 | \details{ 38 | Wrapper function for \code{\link[zoo]{rollapply}} to hide 39 | some of the complexity of managing single-column zoo 40 | objects. 41 | } 42 | \examples{ 43 | data(managers) 44 | apply.rolling(managers[,1,drop=FALSE], FUN="mean", width=36) 45 | } 46 | \author{ 47 | Peter Carl 48 | } 49 | \seealso{ 50 | \code{\link{apply}} \cr \code{\link[zoo]{rollapply}} 51 | } 52 | \keyword{distribution} 53 | \keyword{models} 54 | \keyword{multivariate} 55 | \keyword{ts} 56 | 57 | -------------------------------------------------------------------------------- /man/chart.ACF.Rd: -------------------------------------------------------------------------------- 1 | \name{chart.ACF} 2 | \alias{chart.ACF} 3 | \alias{chart.ACFplus} 4 | \title{Create ACF chart or ACF with PACF two-panel chart} 5 | \usage{ 6 | chart.ACF(R, maxlag = NULL, elementcolor = "gray", main = NULL, ...) 7 | 8 | chart.ACFplus(R, maxlag = NULL, elementcolor = "gray", main = NULL, ...) 9 | } 10 | \arguments{ 11 | \item{R}{an xts, vector, matrix, data frame, timeSeries 12 | or zoo object of asset returns} 13 | 14 | \item{maxlag}{the number of lags to calculate for, 15 | optional} 16 | 17 | \item{elementcolor}{the color to use for chart elements, 18 | defaults to "gray"} 19 | 20 | \item{main}{title of the plot; uses the column name by 21 | default.} 22 | 23 | \item{\dots}{any other passthru parameters} 24 | } 25 | \description{ 26 | Creates an ACF chart or a two-panel plot with the ACF and 27 | PACF set to some specific defaults. 28 | } 29 | \note{ 30 | Inspired by the website: 31 | \url{http://www.stat.pitt.edu/stoffer/tsa2/Rcode/acf2.R} 32 | "...here's an R function that will plot the ACF and PACF of 33 | a time series at the same time on the SAME SCALE, and it 34 | leaves out the zero lag in the ACF: acf2.R. If your time 35 | series is in x and you want the ACF and PACF of x to lag 36 | 50, the call to the function is acf2(x,50). The number of 37 | lags is optional, so acf2(x) will use a default number of 38 | lags [sqrt(n) + 10, where n is the number of 39 | observations]." 40 | 41 | That description made a lot of sense, so it's implemented 42 | here for both the ACF alone and the ACF with the PACF. 43 | } 44 | \examples{ 45 | data(edhec) 46 | chart.ACFplus(edhec[,1,drop=FALSE]) 47 | } 48 | \author{ 49 | Peter Carl 50 | } 51 | \seealso{ 52 | \code{\link{plot}} 53 | } 54 | \keyword{distribution} 55 | \keyword{hplot} 56 | \keyword{models} 57 | \keyword{multivariate} 58 | \keyword{ts} 59 | 60 | -------------------------------------------------------------------------------- /man/chart.Bar.Rd: -------------------------------------------------------------------------------- 1 | \name{chart.Bar} 2 | \alias{chart.Bar} 3 | \alias{charts.Bar} 4 | \title{wrapper for barchart of returns} 5 | \usage{ 6 | chart.Bar(R, legend.loc = NULL, colorset = (1:12), ...) 7 | 8 | charts.Bar(R, main = "Returns", cex.legend = 0.8, cex.main = 1, ...) 9 | } 10 | \arguments{ 11 | \item{R}{an xts, vector, matrix, data frame, timeSeries 12 | or zoo object of asset returns} 13 | 14 | \item{legend.loc}{places a legend into one of nine 15 | locations on the chart: bottomright, bottom, bottomleft, 16 | left, topleft, top, topright, right, or center} 17 | 18 | \item{colorset}{color palette to use, set by default to 19 | rational choices} 20 | 21 | \item{cex.legend}{sets the legend text size, such as in 22 | \code{\link{chart.TimeSeries}}} 23 | 24 | \item{cex.main}{sets the title text size, such as in 25 | \code{\link{chart.TimeSeries}}} 26 | 27 | \item{main}{sets the title text, such as in 28 | \code{\link{chart.TimeSeries}}} 29 | 30 | \item{\dots}{any other passthru parameters, see 31 | \code{plot}} 32 | } 33 | \description{ 34 | A wrapper to create a chart of periodic returns in a bar 35 | chart. This is a difficult enough graph to read that it 36 | doesn't get much use. Still, it is useful for viewing a 37 | single set of data. 38 | } 39 | \details{ 40 | This is really a wrapper for chart.TimeSeries, so several 41 | other attributes can also be passed. 42 | 43 | Creates a plot of time on the x-axis and vertical lines for 44 | each period to indicate value on the y-axis. 45 | } 46 | \examples{ 47 | data(edhec) 48 | chart.Bar(edhec[,"Funds of Funds"], main="Monthly Returns") 49 | } 50 | \author{ 51 | Peter Carl 52 | } 53 | \seealso{ 54 | \code{\link{chart.TimeSeries}} \cr \code{\link{plot}} 55 | } 56 | \keyword{distribution} 57 | \keyword{hplot} 58 | \keyword{models} 59 | \keyword{multivariate} 60 | \keyword{ts} 61 | 62 | -------------------------------------------------------------------------------- /man/chart.Correlation.Rd: -------------------------------------------------------------------------------- 1 | \name{chart.Correlation} 2 | \alias{chart.Correlation} 3 | \title{correlation matrix chart} 4 | \usage{ 5 | chart.Correlation(R, histogram = TRUE, method = c("pearson", "kendall", 6 | "spearman"), ...) 7 | } 8 | \arguments{ 9 | \item{R}{data for the x axis, can take matrix,vector, or 10 | timeseries} 11 | 12 | \item{histogram}{TRUE/FALSE whether or not to display a 13 | histogram} 14 | 15 | \item{method}{a character string indicating which 16 | correlation coefficient (or covariance) is to be 17 | computed. One of "pearson" (default), "kendall", or 18 | "spearman", can be abbreviated.} 19 | 20 | \item{\dots}{any other passthru parameters into 21 | \code{\link{pairs}}} 22 | } 23 | \description{ 24 | Visualization of a Correlation Matrix. On top the 25 | (absolute) value of the correlation plus the result of the 26 | cor.test as stars. On bottom, the bivariate scatterplots, 27 | with a fitted line 28 | } 29 | \note{ 30 | based on plot at 31 | \url{http://addictedtor.free.fr/graphiques/sources/source_137.R} 32 | } 33 | \examples{ 34 | data(managers) 35 | chart.Correlation(managers[,1:8], histogram=TRUE, pch="+") 36 | } 37 | \author{ 38 | Peter Carl 39 | } 40 | \seealso{ 41 | \code{\link{table.Correlation}} 42 | } 43 | \keyword{distribution} 44 | \keyword{hplot} 45 | \keyword{models} 46 | \keyword{multivariate} 47 | \keyword{ts} 48 | 49 | -------------------------------------------------------------------------------- /man/chart.Drawdown.Rd: -------------------------------------------------------------------------------- 1 | \name{chart.Drawdown} 2 | \alias{chart.Drawdown} 3 | \title{Time series chart of drawdowns through time} 4 | \usage{ 5 | chart.Drawdown(R, geometric = TRUE, legend.loc = NULL, colorset = (1:12), 6 | ...) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{geometric}{utilize geometric chaining (TRUE) or 13 | simple/arithmetic chaining (FALSE) to aggregate returns, 14 | default TRUE} 15 | 16 | \item{colorset}{color palette to use, set by default to 17 | rational choices} 18 | 19 | \item{legend.loc}{places a legend into one of nine 20 | locations on the chart: bottomright, bottom, bottomleft, 21 | left, topleft, top, topright, right, or center.} 22 | 23 | \item{\dots}{any other passthru parameters} 24 | } 25 | \description{ 26 | A time series chart demonstrating drawdowns from peak 27 | equity attained through time, calculated from periodic 28 | returns. 29 | } 30 | \details{ 31 | Any time the cumulative returns dips below the maximum 32 | cumulative returns, it's a drawdown. Drawdowns are 33 | measured as a percentage of that maximum cumulative return, 34 | in effect, measured from peak equity. 35 | } 36 | \examples{ 37 | data(edhec) 38 | chart.Drawdown(edhec[,c(1,2)], 39 | main="Drawdown from Peak Equity Attained", 40 | legend.loc="bottomleft") 41 | } 42 | \author{ 43 | Peter Carl 44 | } 45 | \seealso{ 46 | \code{\link{plot}} \cr \code{\link{chart.TimeSeries}} \cr 47 | \code{\link{findDrawdowns}} \cr \code{\link{sortDrawdowns}} 48 | \cr \code{\link{maxDrawdown}} \cr 49 | \code{\link{table.Drawdowns}} \cr 50 | \code{\link{table.DownsideRisk}} 51 | } 52 | \keyword{ts} 53 | 54 | -------------------------------------------------------------------------------- /man/chart.RollingCorrelation.Rd: -------------------------------------------------------------------------------- 1 | \name{chart.RollingCorrelation} 2 | \alias{chart.RollingCorrelation} 3 | \title{chart rolling correlation fo multiple assets} 4 | \usage{ 5 | chart.RollingCorrelation(Ra, Rb, width = 12, xaxis = TRUE, 6 | legend.loc = NULL, colorset = (1:12), ..., fill = NA) 7 | } 8 | \arguments{ 9 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{Rb}{return vector of the benchmark asset} 13 | 14 | \item{width}{number of periods to apply rolling function 15 | window over} 16 | 17 | \item{xaxis}{if true, draws the x axis} 18 | 19 | \item{legend.loc}{places a legend into one of nine 20 | locations on the chart: bottomright, bottom, bottomleft, 21 | left, topleft, top, topright, right, or center.} 22 | 23 | \item{colorset}{color palette to use, set by default to 24 | rational choices} 25 | 26 | \item{\dots}{any other passthru parameters} 27 | 28 | \item{fill}{a three-component vector or list (recycled 29 | otherwise) providing filling values at the left/within/to 30 | the right of the data range. See the fill argument of 31 | \code{\link{na.fill}} for details.} 32 | } 33 | \description{ 34 | A wrapper to create a chart of rolling correlation metrics 35 | in a line chart 36 | } 37 | \details{ 38 | The previous parameter \code{na.pad} has been replaced with 39 | \code{fill}; use \code{fill = NA} instead of \code{na.pad = 40 | TRUE}, or \code{fill = NULL} instead of \code{na.pad = 41 | FALSE}. 42 | } 43 | \examples{ 44 | # First we get the data 45 | data(managers) 46 | chart.RollingCorrelation(managers[, 1:6, drop=FALSE], 47 | managers[, 8, drop=FALSE], 48 | colorset=rich8equal, legend.loc="bottomright", 49 | width=24, main = "Rolling 12-Month Correlation") 50 | } 51 | \author{ 52 | Peter Carl 53 | } 54 | \keyword{distribution} 55 | \keyword{hplot} 56 | \keyword{models} 57 | \keyword{multivariate} 58 | \keyword{ts} 59 | 60 | -------------------------------------------------------------------------------- /man/chart.RollingMean.Rd: -------------------------------------------------------------------------------- 1 | \name{chart.RollingMean} 2 | \alias{chart.RollingMean} 3 | \title{chart the rolling mean return} 4 | \usage{ 5 | chart.RollingMean(R, width = 12, xaxis = TRUE, ylim = NULL, lwd = c(2, 6 | 1, 1), ..., fill = NA) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{width}{number of periods to apply rolling function 13 | window over} 14 | 15 | \item{xaxis}{if true, draws the x axis} 16 | 17 | \item{ylim}{set the y-axis limit, same as in 18 | \code{\link{plot}}} 19 | 20 | \item{lwd}{set the line width, same as in 21 | \code{\link{plot}}. Specified in order of the main line 22 | and the two confidence bands.} 23 | 24 | \item{\dots}{any other passthru parameters} 25 | 26 | \item{fill}{a three-component vector or list (recycled 27 | otherwise) providing filling values at the left/within/to 28 | the right of the data range. See the fill argument of 29 | \code{\link{na.fill}} for details.} 30 | } 31 | \description{ 32 | A wrapper to create a rolling mean return chart with 95% 33 | confidence bands. 34 | } 35 | \details{ 36 | The previous parameter \code{na.pad} has been replaced with 37 | \code{fill}; use \code{fill = NA} instead of \code{na.pad = 38 | TRUE}, or \code{fill = NULL} instead of \code{na.pad = 39 | FALSE}. 40 | } 41 | \examples{ 42 | data(edhec) 43 | chart.RollingMean(edhec[, 9, drop = FALSE]) 44 | } 45 | \author{ 46 | Peter Carl 47 | } 48 | \keyword{distribution} 49 | \keyword{hplot} 50 | \keyword{models} 51 | \keyword{multivariate} 52 | \keyword{ts} 53 | 54 | -------------------------------------------------------------------------------- /man/charts.RollingPerformance.Rd: -------------------------------------------------------------------------------- 1 | \name{charts.RollingPerformance} 2 | \alias{charts.RollingPerformance} 3 | \title{rolling performance chart} 4 | \usage{ 5 | charts.RollingPerformance(R, width = 12, Rf = 0, main = NULL, 6 | event.labels = NULL, legend.loc = NULL, ...) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{width}{number of periods to apply rolling function 13 | over} 14 | 15 | \item{Rf}{risk free rate, in same period as your returns} 16 | 17 | \item{main}{set the chart title, same as in \code{plot}} 18 | 19 | \item{event.labels}{TRUE/FALSE whether or not to display 20 | lines and labels for historical market shock events} 21 | 22 | \item{legend.loc}{places a legend into one of nine 23 | locations on the chart: bottomright, bottom, bottomleft, 24 | left, topleft, top, topright, right, or center.} 25 | 26 | \item{\dots}{any other passthru parameters} 27 | } 28 | \description{ 29 | A wrapper to create a rolling annualized returns chart, 30 | rolling annualized standard deviation chart, and a rolling 31 | annualized sharpe ratio chart. 32 | } 33 | \examples{ 34 | data(managers) 35 | charts.RollingPerformance(managers[,1:8], 36 | Rf=managers[,10,drop=FALSE], 37 | colorset=tim8equal, 38 | main="Rolling 12-Month Performance", 39 | legend.loc="topleft") 40 | } 41 | \author{ 42 | Peter Carl 43 | } 44 | \seealso{ 45 | \code{\link{chart.RollingPerformance}} 46 | } 47 | \keyword{distribution} 48 | \keyword{hplot} 49 | \keyword{models} 50 | \keyword{multivariate} 51 | \keyword{ts} 52 | 53 | -------------------------------------------------------------------------------- /man/checkData.Rd: -------------------------------------------------------------------------------- 1 | \name{checkData} 2 | \alias{checkData} 3 | \title{check input data type and format and coerce to the desired output type} 4 | \usage{ 5 | checkData(x, method = c("xts", "zoo", "data.frame", "matrix", "vector"), 6 | na.rm = TRUE, quiet = TRUE, ...) 7 | } 8 | \arguments{ 9 | \item{x}{a vector, matrix, data.frame, xts, timeSeries or 10 | zoo object to be checked and coerced} 11 | 12 | \item{na.rm}{TRUE/FALSE Remove NA's from the data? used 13 | only with 'vector'} 14 | 15 | \item{quiet}{TRUE/FALSE if false, it will throw warnings 16 | when errors are noticed, default TRUE} 17 | 18 | \item{method}{type of coerced data object to return, one 19 | of c("xts", "zoo", "data.frame", "matrix", "vector"), 20 | default "xts"} 21 | 22 | \item{\dots}{any other passthru parameters} 23 | } 24 | \description{ 25 | This function was created to make the different kinds of 26 | data classes at least \emph{seem} more fungible. It allows 27 | the user to pass in a data object without being concerned 28 | that the function requires a matrix, data.frame, vector, 29 | xts, or timeSeries object. By using \code{checkData}, the 30 | function "knows" what data format it has to work with. 31 | } 32 | \examples{ 33 | data(edhec) 34 | x = checkData(edhec) 35 | class(x) 36 | head(x) 37 | tail(x) 38 | # Note that passing in a single column loses the row and column names 39 | x = checkData(edhec[,1]) 40 | class(x) 41 | head(x) 42 | # Include the "drop" attribute to keep row and column names 43 | x = checkData(edhec[,1,drop=FALSE]) 44 | class(x) 45 | head(x) 46 | x = checkData(edhec, method = "matrix") 47 | class(x) 48 | head(x) 49 | x = checkData(edhec[,1], method = "vector") 50 | class(x) 51 | head(x) 52 | } 53 | \author{ 54 | Peter Carl 55 | } 56 | \keyword{distribution} 57 | \keyword{models} 58 | \keyword{multivariate} 59 | \keyword{ts} 60 | 61 | -------------------------------------------------------------------------------- /man/findDrawdowns.Rd: -------------------------------------------------------------------------------- 1 | \name{findDrawdowns} 2 | \alias{Drawdowns} 3 | \alias{findDrawdowns} 4 | \title{Find the drawdowns and drawdown levels in a timeseries.} 5 | \usage{ 6 | findDrawdowns(R, geometric = TRUE, ...) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{geometric}{utilize geometric chaining (TRUE) or 13 | simple/arithmetic chaining (FALSE) to aggregate returns, 14 | default TRUE} 15 | 16 | \item{\dots}{any other passthru parameters} 17 | } 18 | \description{ 19 | \code{findDrawdowns} will find the starting period, the 20 | ending period, and the amount and length of the drawdown. 21 | } 22 | \details{ 23 | Often used with \code{\link{sortDrawdowns}} to get the 24 | largest drawdowns. 25 | 26 | \code{Drawdowns} will calculate the drawdown levels as 27 | percentages, for use in \code{\link{chart.Drawdown}}. 28 | 29 | Returns an unordered list: \cr \itemize{ \item return depth 30 | of drawdown \item from starting period \item to ending 31 | period \item length length in periods } 32 | } 33 | \examples{ 34 | data(edhec) 35 | findDrawdowns(edhec[,"Funds of Funds", drop=FALSE]) 36 | sortDrawdowns(findDrawdowns(edhec[,"Funds of Funds", drop=FALSE])) 37 | } 38 | \author{ 39 | Peter Carl 40 | 41 | \code{findDrawdowns} modified with permission from function 42 | by Sankalp Upadhyay 43 | } 44 | \references{ 45 | Bacon, C. \emph{Practical Portfolio Performance Measurement 46 | and Attribution}. Wiley. 2004. p. 88 \cr 47 | } 48 | \seealso{ 49 | \code{\link{sortDrawdowns}} \cr \code{\link{maxDrawdown}} 50 | \cr \code{\link{sortDrawdowns}} \cr 51 | \code{\link{table.Drawdowns}} \cr 52 | \code{\link{table.DownsideRisk}} \cr 53 | \code{\link{chart.Drawdown}} \cr 54 | } 55 | \keyword{distribution} 56 | \keyword{models} 57 | \keyword{multivariate} 58 | \keyword{ts} 59 | 60 | -------------------------------------------------------------------------------- /man/lpm.Rd: -------------------------------------------------------------------------------- 1 | \name{lpm} 2 | \alias{lpm} 3 | \title{calculate a lower partial moment for a time series} 4 | \usage{ 5 | lpm(R, n = 2, threshold = 0, about_mean = FALSE) 6 | } 7 | \arguments{ 8 | \item{R}{xts data} 9 | 10 | \item{n}{the n-th moment to return} 11 | 12 | \item{threshold}{threshold can be the mean or any point 13 | as desired} 14 | 15 | \item{about_mean}{TRUE/FALSE calculate LPM about the mean 16 | under the threshold or use the threshold to calculate the 17 | LPM around (if FALSE)} 18 | } 19 | \description{ 20 | Caclulate a Lower Partial Moment around the mean or a 21 | specified threshold. 22 | } 23 | \details{ 24 | Lower partial moments capture negative deviation from a 25 | reference point. That reference point may be the mean, or 26 | some specified threshold that has other meaning for the 27 | investor. 28 | } 29 | \author{ 30 | Kyle Balkissoon \email{kylebalkisoon@gmail.com} 31 | } 32 | \references{ 33 | Huffman S.P. & Moll C.R., "The impact of Asymmetry on 34 | Expected Stock Returns: An Investigation of Alternative 35 | Risk Measures", Algorithmic Finance 1, 2011 p. 79-93 36 | } 37 | 38 | -------------------------------------------------------------------------------- /man/managers.Rd: -------------------------------------------------------------------------------- 1 | \name{managers} 2 | \docType{data} 3 | \alias{managers} 4 | \title{Hypothetical Alternative Asset Manager and Benchmark Data} 5 | \description{ 6 | A xts object that contains columns of monthly returns for six hypothetical 7 | asset managers (HAM1 through HAM6), the EDHEC Long-Short Equity hedge 8 | fund index, the S\&P 500 total returns, and total return series for 9 | the US Treasury 10-year bond and 3-month bill. Monthly returns for 10 | all series end in December 2006 and begin at different periods starting 11 | from January 1996. 12 | 13 | Note that all the EDHEC indices are available in \code{\link{edhec}}. 14 | } 15 | \usage{managers} 16 | \details{ 17 | Please note that the `managers' data set included with PerformanceAnalytics will be periodically updated with new managers and information. If you intend to use this data set in automated tests, please be sure to subset your data like \code{managers[1:120,1:6]} to use the first ten years of observations on HAM1-HAM6. 18 | } 19 | \format{CSV conformed into an xts object with monthly observations} 20 | \examples{ 21 | data(managers) 22 | 23 | #preview the data 24 | head(managers) 25 | 26 | #summary period statistics 27 | summary(managers) 28 | 29 | #cumulative returns 30 | tail(cumprod(1+managers),1) 31 | } 32 | \keyword{datasets} 33 | \keyword{ ts } -------------------------------------------------------------------------------- /man/mean.geometric.Rd: -------------------------------------------------------------------------------- 1 | \name{mean.geometric} 2 | \alias{mean.LCL} 3 | \alias{mean.UCL} 4 | \alias{mean.geometric} 5 | \alias{mean.stderr} 6 | \alias{mean.utils} 7 | \title{calculate attributes relative to the mean of the observation series given, 8 | including geometric, stderr, LCL and UCL} 9 | \usage{ 10 | \method{mean}{geometric}(x, ...) 11 | 12 | \method{mean}{stderr}(x, ...) 13 | 14 | \method{mean}{LCL}(x, ci = 0.95, ...) 15 | 16 | \method{mean}{UCL}(x, ci = 0.95, ...) 17 | } 18 | \arguments{ 19 | \item{x}{a vector, matrix, data frame, or time series to 20 | calculate the modified mean statistic over} 21 | 22 | \item{ci}{the confidence interval to use} 23 | 24 | \item{\dots}{any other passthru parameters} 25 | } 26 | \description{ 27 | \tabular{ll}{ \code{\link{mean.geometric}} \tab geometric 28 | mean \cr \code{\link{mean.stderr}} \tab standard error of 29 | the mean (S.E. mean) \cr \code{\link{mean.LCL}} \tab lower 30 | confidence level (LCL) of the mean \cr 31 | \code{\link{mean.UCL}} \tab upper confidence level (UCL) of 32 | the mean \cr } 33 | } 34 | \examples{ 35 | data(edhec) 36 | mean.geometric(edhec[,"Funds of Funds"]) 37 | mean.stderr(edhec[,"Funds of Funds"]) 38 | mean.UCL(edhec[,"Funds of Funds"]) 39 | mean.LCL(edhec[,"Funds of Funds"]) 40 | } 41 | \author{ 42 | Peter Carl 43 | } 44 | \seealso{ 45 | \code{\link[stats]{sd}} \cr \code{\link[base]{mean}} 46 | } 47 | \keyword{distribution} 48 | \keyword{models} 49 | \keyword{multivariate} 50 | \keyword{ts} 51 | 52 | -------------------------------------------------------------------------------- /man/portfolio_bacon.Rd: -------------------------------------------------------------------------------- 1 | \name{portfolio_bacon} 2 | \docType{data} 3 | \alias{portfolio_bacon} 4 | \title{Bacon(2008) Data} 5 | \description{ 6 | A xts object that contains columns of monthly returns for an example of portfolio 7 | and its benchmark 8 | } 9 | \usage{portfolio_bacon} 10 | \format{CSV conformed into an xts object with monthly observations} 11 | \examples{ 12 | data(portfolio_bacon) 13 | 14 | #preview the data 15 | head(portfolio_bacon) 16 | 17 | #summary period statistics 18 | summary(portfolio_bacon) 19 | 20 | #cumulative returns 21 | tail(cumprod(1+portfolio_bacon),1) 22 | } 23 | \keyword{datasets} 24 | \keyword{ ts } -------------------------------------------------------------------------------- /man/prices.Rd: -------------------------------------------------------------------------------- 1 | \name{prices} 2 | \docType{data} 3 | \alias{prices} 4 | \title{Selected Price Series Example Data} 5 | \description{ 6 | A object returned by get.hist.quote of price data for use in the example for \code{\link{Return.calculate}} 7 | } 8 | \usage{prices} 9 | \format{\R variable 'prices'} 10 | \examples{ 11 | data(prices) 12 | 13 | #preview the data 14 | head(prices) 15 | 16 | } 17 | \keyword{datasets} 18 | \keyword{ ts } 19 | -------------------------------------------------------------------------------- /man/sortDrawdowns.Rd: -------------------------------------------------------------------------------- 1 | \name{sortDrawdowns} 2 | \alias{sortDrawdowns} 3 | \title{order list of drawdowns from worst to best} 4 | \usage{ 5 | sortDrawdowns(runs) 6 | } 7 | \arguments{ 8 | \item{runs}{pass in runs array from findDrawdowns to be 9 | sorted} 10 | } 11 | \description{ 12 | sortDrawdowns(findDrawdowns(R)) Gives the drawdowns in 13 | order of worst to best 14 | } 15 | \details{ 16 | Returns a sorted list: \itemize{ \item return depth of 17 | drawdown \item from starting period \item to ending period 18 | \item length length in periods } 19 | } 20 | \examples{ 21 | data(edhec) 22 | findDrawdowns(edhec[,"Funds of Funds", drop=FALSE]) 23 | sortDrawdowns(findDrawdowns(edhec[,"Funds of Funds", drop=FALSE])) 24 | } 25 | \author{ 26 | Peter Carl \cr modified with permission from prototype 27 | function by Sankalp Upadhyay 28 | } 29 | \references{ 30 | Bacon, C. \emph{Practical Portfolio Performance Measurement 31 | and Attribution}. Wiley. 2004. p. 88 \cr 32 | } 33 | \seealso{ 34 | \code{\link{DownsideDeviation}} \cr 35 | \code{\link{maxDrawdown}} \cr \code{\link{findDrawdowns}} 36 | \cr \code{\link{sortDrawdowns}} \cr 37 | \code{\link{chart.Drawdown}} \cr 38 | \code{\link{table.Drawdowns}} \cr 39 | \code{\link{table.DownsideRisk}} 40 | } 41 | \keyword{distribution} 42 | \keyword{models} 43 | \keyword{multivariate} 44 | \keyword{ts} 45 | 46 | -------------------------------------------------------------------------------- /man/table.AnnualizedReturns.Rd: -------------------------------------------------------------------------------- 1 | \name{table.AnnualizedReturns} 2 | \alias{table.AnnualizedReturns} 3 | \title{Annualized Returns Summary: Statistics and Stylized Facts} 4 | \usage{ 5 | table.AnnualizedReturns(R, scale = NA, Rf = 0, geometric = TRUE, 6 | digits = 4) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{geometric}{utilize geometric chaining (TRUE) or 13 | simple/arithmetic chaining (FALSE) to aggregate returns, 14 | default TRUE} 15 | 16 | \item{scale}{number of periods in a year (daily scale = 17 | 252, monthly scale = 12, quarterly scale = 4)} 18 | 19 | \item{Rf}{risk free rate, in same period as your returns} 20 | 21 | \item{digits}{number of digits to round results to} 22 | } 23 | \description{ 24 | Table of Annualized Return, Annualized Std Dev, and 25 | Annualized Sharpe 26 | } 27 | \examples{ 28 | data(managers) 29 | table.AnnualizedReturns(managers[,1:8]) 30 | 31 | require("Hmisc") 32 | result = t(table.AnnualizedReturns(managers[,1:8], Rf=.04/12)) 33 | 34 | textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, 35 | cdec=c(3,3,1)), rmar = 0.8, cmar = 2, max.cex=.9, 36 | halign = "center", valign = "top", row.valign="center", 37 | wrap.rownames=20, wrap.colnames=10, col.rownames=c("red", 38 | rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1) 39 | 40 | title(main="Annualized Performance") 41 | } 42 | \author{ 43 | Peter Carl 44 | } 45 | \seealso{ 46 | \code{\link{Return.annualized}} \cr 47 | \code{\link{StdDev.annualized}} \cr 48 | \code{\link{SharpeRatio.annualized}} 49 | } 50 | \keyword{distribution} 51 | \keyword{models} 52 | \keyword{multivariate} 53 | \keyword{ts} 54 | 55 | -------------------------------------------------------------------------------- /man/table.Autocorrelation.Rd: -------------------------------------------------------------------------------- 1 | \name{table.Autocorrelation} 2 | \alias{table.Autocorrelation} 3 | \title{table for calculating the first six autocorrelation coefficients and 4 | significance} 5 | \usage{ 6 | table.Autocorrelation(R, digits = 4) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{digits}{number of digits to round results to for 13 | display} 14 | } 15 | \description{ 16 | Produces data table of autocorrelation coefficients 17 | \eqn{\rho}{rho} and corresponding Q(6)-statistic for each 18 | column in R. 19 | } 20 | \note{ 21 | To test returns for autocorrelation, Lo (2001) suggests the 22 | use of the Ljung-Box test, a significance test for the 23 | auto-correlation coefficients. Ljung and Box (1978) provide 24 | a refinement of the Q-statistic proposed by Box and Pierce 25 | (1970) that offers a better fit for the \eqn{\chi^2}{chi^2} 26 | test for small sample sizes. \code{\link{Box.test}} 27 | provides both. 28 | } 29 | \examples{ 30 | data(managers) 31 | t(table.Autocorrelation(managers)) 32 | 33 | result = t(table.Autocorrelation(managers[,1:8])) 34 | 35 | textplot(result, rmar = 0.8, cmar = 2, max.cex=.9, halign = "center", 36 | valign = "top", row.valign="center", wrap.rownames=15, 37 | wrap.colnames=10, mar = c(0,0,3,0)+0.1) 38 | 39 | title(main="Autocorrelation") 40 | } 41 | \author{ 42 | Peter Carl 43 | } 44 | \references{ 45 | Lo, Andrew W. 2001. Risk Management for Hedge Funds: 46 | Introduction and Overview. SSRN eLibrary. 47 | } 48 | \seealso{ 49 | \code{\link{Box.test}}, \code{\link{acf}} 50 | } 51 | \keyword{distribution} 52 | \keyword{models} 53 | \keyword{multivariate} 54 | \keyword{ts} 55 | 56 | -------------------------------------------------------------------------------- /man/table.CAPM.Rd: -------------------------------------------------------------------------------- 1 | \name{table.SFM} 2 | \alias{table.CAPM} 3 | \alias{table.SFM} 4 | \title{Single Factor Asset-Pricing Model Summary: Statistics and Stylized Facts} 5 | \usage{ 6 | table.SFM(Ra, Rb, scale = NA, Rf = 0, digits = 4) 7 | } 8 | \arguments{ 9 | \item{Ra}{a vector of returns to test, e.g., the asset to 10 | be examined} 11 | 12 | \item{Rb}{a matrix, data.frame, or timeSeries of 13 | benchmark(s) to test the asset against.} 14 | 15 | \item{scale}{number of periods in a year (daily scale = 16 | 252, monthly scale = 12, quarterly scale = 4)} 17 | 18 | \item{Rf}{risk free rate, in same period as your returns} 19 | 20 | \item{digits}{number of digits to round results to} 21 | } 22 | \description{ 23 | Takes a set of returns and relates them to a benchmark 24 | return. Provides a set of measures related to an excess 25 | return single factor model, or CAPM. 26 | } 27 | \details{ 28 | This table will show statistics pertaining to an asset 29 | against a set of benchmarks, or statistics for a set of 30 | assets against a benchmark. 31 | } 32 | \examples{ 33 | data(managers) 34 | table.SFM(managers[,1:3], managers[,8], Rf = managers[,10]) 35 | 36 | result = table.SFM(managers[,1:3], managers[,8], Rf = managers[,10]) 37 | textplot(result, rmar = 0.8, cmar = 1.5, max.cex=.9, 38 | halign = "center", valign = "top", row.valign="center", 39 | wrap.rownames=15, wrap.colnames=10, mar = c(0,0,3,0)+0.1) 40 | title(main="Single Factor Model Related Statistics") 41 | } 42 | \author{ 43 | Peter Carl 44 | } 45 | \seealso{ 46 | \code{\link{CAPM.alpha}} \cr \code{\link{CAPM.beta}} \cr 47 | \code{\link{TrackingError}} \cr \code{\link{ActivePremium}} 48 | \cr \code{\link{InformationRatio}} \cr 49 | \code{\link{TreynorRatio}} 50 | } 51 | \keyword{distribution} 52 | \keyword{models} 53 | \keyword{multivariate} 54 | \keyword{ts} 55 | 56 | -------------------------------------------------------------------------------- /man/table.CalendarReturns.Rd: -------------------------------------------------------------------------------- 1 | \name{table.CalendarReturns} 2 | \alias{table.CalendarReturns} 3 | \alias{table.Returns} 4 | \title{Monthly and Calendar year Return table} 5 | \usage{ 6 | table.CalendarReturns(R, digits = 1, as.perc = TRUE, geometric = TRUE) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{digits}{number of digits to round results to for 13 | presentation} 14 | 15 | \item{as.perc}{TRUE/FALSE if TRUE, multiply simple 16 | returns by 100 to get \%} 17 | 18 | \item{geometric}{utilize geometric chaining (TRUE) or 19 | simple/arithmetic chaining (FALSE) to aggregate returns, 20 | default TRUE} 21 | } 22 | \description{ 23 | Returns a table of returns formatted with years in rows, 24 | months in columns, and a total column in the last column. 25 | For additional columns in \code{R}, annual returns will be 26 | appended as columns. 27 | } 28 | \note{ 29 | This function assumes monthly returns and does not 30 | currently have handling for other scales. 31 | 32 | This function defaults to the first column as the monthly 33 | returns to be formatted. 34 | } 35 | \examples{ 36 | data(managers) 37 | t(table.CalendarReturns(managers[,c(1,7,8)])) 38 | 39 | # prettify with format.df in hmisc package 40 | require("Hmisc") 41 | result = t(table.CalendarReturns(managers[,c(1,8)])) 42 | 43 | textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, 44 | cdec=rep(1,dim(result)[2])), rmar = 0.8, cmar = 1, 45 | max.cex=.9, halign = "center", valign = "top", 46 | row.valign="center", wrap.rownames=20, wrap.colnames=10, 47 | col.rownames=c( rep("darkgray",12), "black", "blue"), 48 | mar = c(0,0,3,0)+0.1) 49 | 50 | title(main="Calendar Returns") 51 | } 52 | \author{ 53 | Peter Carl 54 | } 55 | \keyword{distribution} 56 | \keyword{models} 57 | \keyword{multivariate} 58 | \keyword{ts} 59 | 60 | -------------------------------------------------------------------------------- /man/table.CaptureRatios.Rd: -------------------------------------------------------------------------------- 1 | \name{table.CaptureRatios} 2 | \alias{table.CaptureRatios} 3 | \alias{table.UpDownRatios} 4 | \title{Calculate and display a table of capture ratio and related statistics} 5 | \usage{ 6 | table.CaptureRatios(Ra, Rb, digits = 4) 7 | 8 | table.UpDownRatios(Ra, Rb, digits = 4) 9 | } 10 | \arguments{ 11 | \item{Ra}{a vector of returns to test, e.g., the asset to 12 | be examined} 13 | 14 | \item{Rb}{a matrix, data.frame, or timeSeries of 15 | benchmark(s) to test the asset against.} 16 | 17 | \item{digits}{number of digits to round results to for 18 | presentation} 19 | } 20 | \description{ 21 | Creates a table of capture ratios and similar metrics for a 22 | set of returns against a benchmark. 23 | } 24 | \details{ 25 | This table will show statistics pertaining to an asset 26 | against a set of benchmarks, or statistics for a set of 27 | assets against a benchmark. \code{table.CaptureRatios} 28 | shows only the capture ratio; \code{table.UpDownRatios} 29 | shows three: the capture ratio, the number ratio, and the 30 | percentage ratio. 31 | } 32 | \examples{ 33 | data(managers) 34 | table.CaptureRatios(managers[,1:6], managers[,7,drop=FALSE]) 35 | table.UpDownRatios(managers[,1:6], managers[,7,drop=FALSE]) 36 | 37 | result = t(table.UpDownRatios(managers[,1:6], managers[,7,drop=FALSE])) 38 | colnames(result)=colnames(managers[,1:6]) 39 | textplot(result, rmar = 0.8, cmar = 1.5, max.cex=.9, 40 | halign = "center", valign = "top", row.valign="center", 41 | wrap.rownames=15, wrap.colnames=10, mar = c(0,0,3,0)+0.1) 42 | 43 | title(main="Capture Ratios for EDHEC LS EQ") 44 | } 45 | \author{ 46 | Peter Carl 47 | } 48 | \seealso{ 49 | \code{\link{UpDownRatios}}, 50 | \code{\link{chart.CaptureRatios}} 51 | } 52 | \keyword{distribution} 53 | \keyword{models} 54 | \keyword{multivariate} 55 | \keyword{ts} 56 | 57 | -------------------------------------------------------------------------------- /man/table.Correlation.Rd: -------------------------------------------------------------------------------- 1 | \name{table.Correlation} 2 | \alias{table.Correlation} 3 | \title{calculate correlalations of multicolumn data} 4 | \usage{ 5 | table.Correlation(Ra, Rb, ...) 6 | } 7 | \arguments{ 8 | \item{Ra}{a vector of returns to test, e.g., the asset to 9 | be examined} 10 | 11 | \item{Rb}{a matrix, data.frame, or timeSeries of 12 | benchmark(s) to test the asset against.} 13 | 14 | \item{\dots}{any other passthru parameters to 15 | \code{\link{cor.test}}} 16 | } 17 | \description{ 18 | This is a wrapper for calculating correlation and 19 | significance against each column of the data provided. 20 | } 21 | \examples{ 22 | # First we load the data 23 | data(managers) 24 | table.Correlation(managers[,1:6],managers[,7:8]) 25 | 26 | result=table.Correlation(managers[,1:6],managers[,8]) 27 | rownames(result)=colnames(managers[,1:6]) 28 | require("Hmisc") 29 | textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, 30 | cdec=rep(3,dim(result)[2])), rmar = 0.8, cmar = 1.5, 31 | max.cex=.9, halign = "center", valign = "top", row.valign="center" 32 | , wrap.rownames=20, wrap.colnames=10, mar = c(0,0,3,0)+0.1) 33 | title(main="Correlations to SP500 TR") 34 | 35 | ctable = table.Correlation(managers[,1:6],managers[,8,drop=FALSE], conf.level=.99) 36 | dotchart(ctable[,1],labels=rownames(ctable),xlim=c(-1,1)) 37 | } 38 | \author{ 39 | Peter Carl 40 | } 41 | \seealso{ 42 | \code{\link{cor.test}} 43 | } 44 | \keyword{distribution} 45 | \keyword{models} 46 | \keyword{multivariate} 47 | \keyword{ts} 48 | 49 | -------------------------------------------------------------------------------- /man/table.Distributions.Rd: -------------------------------------------------------------------------------- 1 | \name{table.Distributions} 2 | \alias{table.Distributions} 3 | \title{Distributions Summary: Statistics and Stylized Facts} 4 | \usage{ 5 | table.Distributions(R, scale = NA, digits = 4) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{scale}{number of periods in a year (daily scale = 12 | 252, monthly scale = 12, quarterly scale = 4)} 13 | 14 | \item{digits}{number of digits to round results to} 15 | } 16 | \description{ 17 | Table of Monthly standard deviation, Skewness, Sample 18 | standard deviation, Kurtosis, Excess kurtosis, Sample 19 | Skweness and Sample excess kurtosis 20 | } 21 | \examples{ 22 | data(managers) 23 | table.Distributions(managers[,1:8]) 24 | 25 | require("Hmisc") 26 | result = t(table.Distributions(managers[,1:8])) 27 | 28 | textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)), 29 | rmar = 0.8, cmar = 2, max.cex=.9, halign = "center", valign = "top", 30 | row.valign="center", wrap.rownames=20, wrap.colnames=10, 31 | col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1) 32 | title(main="Portfolio Distributions statistics") 33 | } 34 | \author{ 35 | Matthieu Lestel 36 | } 37 | \references{ 38 | Carl Bacon, \emph{Practical portfolio performance 39 | measurement and attribution}, second edition 2008 p.87 40 | } 41 | \seealso{ 42 | \code{\link{StdDev.annualized}} \cr \code{\link{skewness}} 43 | \cr \code{\link{kurtosis}} 44 | } 45 | \keyword{distribution} 46 | \keyword{models} 47 | \keyword{multivariate} 48 | \keyword{ts} 49 | 50 | -------------------------------------------------------------------------------- /man/table.DownsideRisk.Rd: -------------------------------------------------------------------------------- 1 | \name{table.DownsideRisk} 2 | \alias{table.DownsideRisk} 3 | \title{Downside Risk Summary: Statistics and Stylized Facts} 4 | \usage{ 5 | table.DownsideRisk(R, ci = 0.95, scale = NA, Rf = 0, MAR = 0.1/12, 6 | p = 0.95, digits = 4) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{ci}{confidence interval, defaults to 95\%} 13 | 14 | \item{scale}{number of periods in a year (daily scale = 15 | 252, monthly scale = 12, quarterly scale = 4)} 16 | 17 | \item{Rf}{risk free rate, in same period as your returns} 18 | 19 | \item{MAR}{Minimum Acceptable Return, in the same 20 | periodicity as your returns} 21 | 22 | \item{p}{confidence level for calculation, default p=.99} 23 | 24 | \item{digits}{number of digits to round results to} 25 | } 26 | \description{ 27 | Creates a table of estimates of downside risk measures for 28 | comparison across multiple instruments or funds. 29 | } 30 | \examples{ 31 | data(edhec) 32 | table.DownsideRisk(edhec, Rf=.04/12, MAR =.05/12, p=.95) 33 | 34 | result=t(table.DownsideRisk(edhec, Rf=.04/12, MAR =.05/12, p=.95)) 35 | require("Hmisc") 36 | textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, 37 | cdec=rep(3,dim(result)[2])), rmar = 0.8, cmar = 1.5, 38 | max.cex=.9, halign = "center", valign = "top", row.valign="center", 39 | wrap.rownames=15, wrap.colnames=10, mar = c(0,0,3,0)+0.1) 40 | title(main="Downside Risk Statistics") 41 | } 42 | \author{ 43 | Peter Carl 44 | } 45 | \seealso{ 46 | \code{\link{DownsideDeviation}} \cr 47 | \code{\link{maxDrawdown}} \cr \code{\link{VaR}} \cr 48 | \code{\link{ES}} \cr 49 | } 50 | \keyword{distribution} 51 | \keyword{models} 52 | \keyword{multivariate} 53 | \keyword{ts} 54 | 55 | -------------------------------------------------------------------------------- /man/table.DownsideRiskRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{table.DownsideRiskRatio} 2 | \alias{table.DownsideRiskRatio} 3 | \title{Downside Summary: Statistics and ratios} 4 | \usage{ 5 | table.DownsideRiskRatio(R, MAR = 0, scale = NA, digits = 4) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{MAR}{Minimum Acceptable Return, in the same 12 | periodicity as your returns} 13 | 14 | \item{scale}{number of periods in a year (daily scale = 15 | 252, monthly scale =} 16 | 17 | \item{digits}{number of digits to round results to} 18 | } 19 | \description{ 20 | Table of Monthly downside risk, Annualised downside risk, 21 | Downside potential, Omega, Sortino ratio, Upside potential, 22 | Upside potential ratio and Omega-Sharpe ratio 23 | } 24 | \examples{ 25 | data(managers) 26 | table.DownsideRiskRatio(managers[,1:8]) 27 | 28 | require("Hmisc") 29 | result = t(table.DownsideRiskRatio(managers[,1:8])) 30 | 31 | textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)), 32 | rmar = 0.8, cmar = 2, max.cex=.9, halign = "center", valign = "top", 33 | row.valign="center", wrap.rownames=20, wrap.colnames=10, 34 | col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1) 35 | title(main="Downside risk statistics") 36 | } 37 | \author{ 38 | Matthieu Lestel 39 | } 40 | \references{ 41 | Carl Bacon, \emph{Practical portfolio performance 42 | measurement and attribution}, second edition 2008 p.98 43 | } 44 | \seealso{ 45 | \code{\link{CalmarRatio}} \cr \code{\link{BurkeRatio}} \cr 46 | \code{\link{PainIndex}} \cr \code{\link{UlcerIndex}} \cr 47 | \code{\link{PainRatio}} \cr \code{\link{MartinRatio}} 48 | } 49 | \keyword{distribution} 50 | \keyword{models} 51 | \keyword{multivariate} 52 | \keyword{ts} 53 | 54 | -------------------------------------------------------------------------------- /man/table.DrawdownsRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{table.DrawdownsRatio} 2 | \alias{table.DrawdownsRatio} 3 | \title{Drawdowns Summary: Statistics and ratios} 4 | \usage{ 5 | table.DrawdownsRatio(R, Rf = 0, scale = NA, digits = 4) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rf}{risk free rate, in same period as your returns} 12 | 13 | \item{scale}{number of periods in a year (daily scale = 14 | 252, monthly scale = 12, quarterly scale = 4)} 15 | 16 | \item{digits}{number of digits to round results to} 17 | } 18 | \description{ 19 | Table of Calmar ratio, Sterling ratio, Burke ratio, Pain 20 | index, Ulcer index, Pain ratio and Martin ratio 21 | } 22 | \examples{ 23 | data(managers) 24 | table.DrawdownsRatio(managers[,1:8]) 25 | 26 | require("Hmisc") 27 | result = t(table.DrawdownsRatio(managers[,1:8], Rf=.04/12)) 28 | 29 | textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)), 30 | rmar = 0.8, cmar = 2, max.cex=.9, halign = "center", valign = "top", 31 | row.valign="center", wrap.rownames=20, wrap.colnames=10, 32 | col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1) 33 | title(main="Drawdowns ratio statistics") 34 | } 35 | \author{ 36 | Matthieu Lestel 37 | } 38 | \references{ 39 | Carl Bacon, \emph{Practical portfolio performance 40 | measurement and attribution}, second edition 2008 p.93 41 | } 42 | \seealso{ 43 | \code{\link{CalmarRatio}} \cr \code{\link{BurkeRatio}} \cr 44 | \code{\link{PainIndex}} \cr \code{\link{UlcerIndex}} \cr 45 | \code{\link{PainRatio}} \cr \code{\link{MartinRatio}} 46 | } 47 | \keyword{distribution} 48 | \keyword{models} 49 | \keyword{multivariate} 50 | \keyword{ts} 51 | 52 | -------------------------------------------------------------------------------- /man/table.InformationRatio.Rd: -------------------------------------------------------------------------------- 1 | \name{table.InformationRatio} 2 | \alias{table.InformationRatio} 3 | \title{Information ratio Summary: Statistics and Stylized Facts} 4 | \usage{ 5 | table.InformationRatio(R, Rb, scale = NA, digits = 4) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{scale}{number of periods in a year (daily scale = 14 | 252, monthly scale = 12, quarterly scale = 4)} 15 | 16 | \item{digits}{number of digits to round results to} 17 | } 18 | \description{ 19 | Table of Tracking error, Annualised tracking error and 20 | Information ratio 21 | } 22 | \examples{ 23 | data(managers) 24 | table.InformationRatio(managers[,1:8], managers[,8]) 25 | 26 | require("Hmisc") 27 | result = t(table.InformationRatio(managers[,1:8], managers[,8])) 28 | 29 | textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)), 30 | rmar = 0.8, cmar = 2, max.cex=.9, halign = "center", valign = "top", 31 | row.valign="center", wrap.rownames=20, wrap.colnames=10, 32 | col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1) 33 | title(main="Portfolio information ratio") 34 | } 35 | \author{ 36 | Matthieu Lestel 37 | } 38 | \references{ 39 | Carl Bacon, \emph{Practical portfolio performance 40 | measurement and attribution}, second edition 2008 p.81 41 | } 42 | \seealso{ 43 | \code{\link{InformationRatio}} \cr 44 | \code{\link{TrackingError}} 45 | } 46 | \keyword{distribution} 47 | \keyword{models} 48 | \keyword{multivariate} 49 | \keyword{ts} 50 | 51 | -------------------------------------------------------------------------------- /man/table.MonthlyReturns.Rd: -------------------------------------------------------------------------------- 1 | \name{table.Stats} 2 | \alias{table.MonthlyReturns} 3 | \alias{table.Stats} 4 | \title{Returns Summary: Statistics and Stylized Facts} 5 | \usage{ 6 | table.Stats(R, ci = 0.95, digits = 4) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{ci}{confidence interval, defaults to 95\%} 13 | 14 | \item{digits}{number of digits to round results to} 15 | } 16 | \description{ 17 | Returns a basic set of statistics that match the period of 18 | the data passed in (e.g., monthly returns will get monthly 19 | statistics, daily will be daily stats, and so on) 20 | } 21 | \details{ 22 | This was created as a way to display a set of related 23 | statistics together for comparison across a set of 24 | instruments or funds. Careful consideration to missing 25 | data or unequal time series should be given when 26 | intepreting the results. 27 | } 28 | \examples{ 29 | data(edhec) 30 | table.Stats(edhec[,1:3]) 31 | t(table.Stats(edhec)) 32 | 33 | result=t(table.Stats(edhec)) 34 | require("Hmisc") 35 | textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(rep(1,2),rep(3,14))), 36 | rmar = 0.8, cmar = 1.5, max.cex=.9, halign = "center", valign = "top", 37 | row.valign="center", wrap.rownames=10, wrap.colnames=10, mar = c(0,0,3,0)+0.1) 38 | title(main="Statistics for EDHEC Indexes") 39 | } 40 | \author{ 41 | Peter Carl 42 | } 43 | \keyword{distribution} 44 | \keyword{models} 45 | \keyword{multivariate} 46 | \keyword{ts} 47 | 48 | -------------------------------------------------------------------------------- /man/table.SpecificRisk.Rd: -------------------------------------------------------------------------------- 1 | \name{table.SpecificRisk} 2 | \alias{table.SpecificRisk} 3 | \title{Specific risk Summary: Statistics and Stylized Facts} 4 | \usage{ 5 | table.SpecificRisk(Ra, Rb, Rf = 0, digits = 4) 6 | } 7 | \arguments{ 8 | \item{Ra}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{Rb}{return vector of the benchmark asset} 12 | 13 | \item{Rf}{risk free rate, in same period as your returns} 14 | 15 | \item{digits}{number of digits to round results to} 16 | } 17 | \description{ 18 | Table of specific risk, systematic risk and total risk 19 | } 20 | \examples{ 21 | data(managers) 22 | table.SpecificRisk(managers[,1:8], managers[,8]) 23 | 24 | require("Hmisc") 25 | result = t(table.SpecificRisk(managers[,1:8], managers[,8], Rf=.04/12)) 26 | 27 | textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)), 28 | rmar = 0.8, cmar = 2, max.cex=.9, halign = "center", valign = "top", 29 | row.valign="center", wrap.rownames=20, wrap.colnames=10, 30 | col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1) 31 | title(main="Portfolio specific, systematic and total risk") 32 | } 33 | \author{ 34 | Matthieu Lestel 35 | } 36 | \references{ 37 | Carl Bacon, \emph{Practical portfolio performance 38 | measurement and attribution}, second edition 2008 p.76 39 | } 40 | \seealso{ 41 | \code{\link{SystematicRisk}} \cr \code{\link{SpecificRisk}} 42 | \cr \code{\link{TotalRisk}} 43 | } 44 | \keyword{distribution} 45 | \keyword{models} 46 | \keyword{multivariate} 47 | \keyword{ts} 48 | 49 | -------------------------------------------------------------------------------- /man/table.Variability.Rd: -------------------------------------------------------------------------------- 1 | \name{table.Variability} 2 | \alias{table.Variability} 3 | \title{Variability Summary: Statistics and Stylized Facts} 4 | \usage{ 5 | table.Variability(R, scale = NA, geometric = TRUE, digits = 4) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{geometric}{utilize geometric chaining (TRUE) or 12 | simple/arithmetic chaining (FALSE) to aggregate returns, 13 | default TRUE} 14 | 15 | \item{scale}{number of periods in a year (daily scale = 16 | 252, monthly scale = 12, quarterly scale = 4)} 17 | 18 | \item{digits}{number of digits to round results to} 19 | } 20 | \description{ 21 | Table of Mean absolute difference, Monthly standard 22 | deviation and annualised standard deviation 23 | } 24 | \examples{ 25 | data(managers) 26 | table.Variability(managers[,1:8]) 27 | 28 | require("Hmisc") 29 | result = t(table.Variability(managers[,1:8])) 30 | 31 | textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)), 32 | rmar = 0.8, cmar = 2, max.cex=.9, halign = "center", valign = "top", 33 | row.valign="center", wrap.rownames=20, wrap.colnames=10, 34 | col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1) 35 | title(main="Portfolio variability") 36 | } 37 | \author{ 38 | Matthieu Lestel 39 | } 40 | \references{ 41 | Carl Bacon, \emph{Practical portfolio performance 42 | measurement and attribution}, second edition 2008 p.65 43 | } 44 | \seealso{ 45 | \code{\link{StdDev.annualized}} \cr 46 | \code{\link{MeanAbsoluteDeviation}} 47 | } 48 | \keyword{distribution} 49 | \keyword{models} 50 | \keyword{multivariate} 51 | \keyword{ts} 52 | 53 | -------------------------------------------------------------------------------- /man/weights.Rd: -------------------------------------------------------------------------------- 1 | \name{weights} 2 | \docType{data} 3 | \alias{weights} 4 | \title{Selected Portfolio Weights Data} 5 | \description{ 6 | An xts object that contains columns of monthly weights for a subset of the EDHEC hedge 7 | fund indexes that demonstrate rebalancing portfolios through time. 8 | 9 | Note that all the EDHEC indices are available in \code{\link{edhec}}. 10 | } 11 | \usage{managers} 12 | \details{ 13 | A relatively random weights file used for charting examples. 14 | } 15 | \format{CSV conformed into an xts object with monthly observations} 16 | \examples{ 17 | data(weights) 18 | 19 | #preview the data 20 | head(weights) 21 | 22 | } 23 | \keyword{datasets} 24 | \keyword{ ts } 25 | -------------------------------------------------------------------------------- /man/zerofill.Rd: -------------------------------------------------------------------------------- 1 | \name{zerofill} 2 | \alias{zerofill} 3 | \title{zerofill} 4 | \usage{ 5 | zerofill(x) 6 | } 7 | \arguments{ 8 | \item{x}{time series to zero fill} 9 | } 10 | \description{ 11 | Fill NA's with zeros in a time series to allow analysis 12 | when the matrix must be complete. 13 | } 14 | \details{ 15 | Note that this function has risks, use carefully. Complete 16 | data is preferred. Barring that, filling a small 17 | percentage of results in a the middle of a large set are 18 | unlikely to cause problems. Barring that, realize that this 19 | will skew your results. 20 | } 21 | 22 | -------------------------------------------------------------------------------- /sandbox/PAenhance/inst/PA-KirkLi.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/PAenhance/inst/PA-KirkLi.pdf -------------------------------------------------------------------------------- /sandbox/Return.wealthindex.R: -------------------------------------------------------------------------------- 1 | Return.wealthindex <- 2 | function (R, wealth.index = TRUE, ...) 3 | { # @author Peter Carl 4 | 5 | # DESCRIPTION: 6 | # Cumulates the returns given as a cumulative return or a "wealth index". 7 | 8 | # Inputs: 9 | # R: a matrix, data frame, or timeSeries of returns 10 | # wealth.index: if true, shows the "value of $1", starting the cumulation 11 | # of returns at 1 rather than zero 12 | 13 | # Outputs: 14 | # A timeseries line chart of the cumulative return series 15 | 16 | # FUNCTION: 17 | 18 | # Transform input data to a matrix 19 | x = checkData(R) 20 | 21 | # Get dimensions and labels 22 | columns = ncol(x) 23 | columnnames = colnames(x) 24 | 25 | # Calculate the cumulative return 26 | one = 0 27 | if(!wealth.index) 28 | one = 1 29 | 30 | for(column in 1:columns) { 31 | column.Return.cumulative = na.skip(x[,column,drop=FALSE],FUN = function(x,one) {cumprod(1+x) - one},one=one) 32 | if(column == 1) 33 | Return.cumulative = column.Return.cumulative 34 | else 35 | Return.cumulative = merge(Return.cumulative,column.Return.cumulative) 36 | } 37 | if(columns == 1) 38 | Return.cumulative = as.xts(Return.cumulative) 39 | colnames(Return.cumulative) = columnnames 40 | reclass(Return.cumulative,match.to=x) 41 | 42 | } 43 | 44 | ############################################################################### 45 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 46 | # 47 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 48 | # 49 | # This R package is distributed under the terms of the GNU Public License (GPL) 50 | # for full details see the file COPYING 51 | # 52 | # $Id$ 53 | # 54 | ############################################################################### -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: noniid.sm 2 | Type: Package 3 | Title: Non-i.i.d. GSoC 2013 Shubhankit 4 | Version: 0.1 5 | Date: $Date: 2013-05-13 14:30:22 -0500 (Mon, 13 May 2013) $ 6 | Author: Shubhankit Mohan 7 | Contributors: Peter Carl, Brian G. Peterson 8 | Depends: 9 | xts, 10 | PerformanceAnalytics, 11 | tseries, 12 | stats, 13 | gld 14 | Maintainer: Brian G. Peterson 15 | Description: GSoC 2013 project to replicate literature on drawdowns and 16 | non-i.i.d assumptions in finance. 17 | License: GPL-3 18 | ByteCompile: TRUE 19 | Collate: 20 | 'ACStdDev.annualized.R' 21 | 'CalmarRatio.Norm.R' 22 | 'CDrawdown.R' 23 | 'chart.AcarSim.R' 24 | 'chart.Autocorrelation.R' 25 | 'EmaxDDGBM.R' 26 | 'GLMSmoothIndex.R' 27 | 'na.skip.R' 28 | 'noniid.sm-internal.R' 29 | 'QP.Norm.R' 30 | 'Return.GLM.R' 31 | 'Return.Okunev.R' 32 | 'SterlingRatio.Norm.R' 33 | 'table.ComparitiveReturn.GLM.R' 34 | 'table.EMaxDDGBM.R' 35 | 'table.UnsmoothReturn.R' 36 | 'UnsmoothReturn.R' 37 | 'LoSharpe.R' 38 | 'se.LoSharpe.R' 39 | 'table.Sharpe.R' 40 | 'glmi.R' 41 | 'lmi.R' 42 | 'table.normDD.R' 43 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/NAMESPACE: -------------------------------------------------------------------------------- 1 | export(ACStdDev.annualized) 2 | export(CalmarRatio.Norm) 3 | export(CDrawdown) 4 | export(chart.AcarSim) 5 | export(chart.Autocorrelation) 6 | export(EmaxDDGBM) 7 | export(glmi) 8 | export(GLMSmoothIndex) 9 | export(lmi) 10 | export(LoSharpe) 11 | export(QP.Norm) 12 | export(Return.GLM) 13 | export(Return.Okunev) 14 | export(se.LoSharpe) 15 | export(SterlingRatio.Norm) 16 | export(table.ComparitiveReturn.GLM) 17 | export(table.EMaxDDGBM) 18 | export(table.normDD) 19 | export(table.Sharpe) 20 | export(table.UnsmoothReturn) 21 | export(UnsmoothReturn) 22 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/R/QP.Norm.R: -------------------------------------------------------------------------------- 1 | #' QP function for calculation of Sharpe Ratio 2 | #' 3 | #' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of 4 | #' asset returns 5 | #' @param tau Time Scale Translations Factor 6 | #' @param scale number of periods in a year (daily scale = 252, monthly scale = 7 | #' @seealso 8 | #' \code{\link{CalmarRatio.Norm}}, \cr 9 | #' @export 10 | QP.Norm <- function (R, tau,scale = NA) 11 | { 12 | Sharpe= as.numeric(SharpeRatio.annualized(R)) 13 | return(.63519+(.5*log(tau))+log(Sharpe)) 14 | } 15 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/R/na.skip.R: -------------------------------------------------------------------------------- 1 | na.skip <- function (x, FUN=NULL, ...) # maybe add a trim capability? 2 | { # @author Brian Peterson 3 | 4 | # DESCRIPTION: 5 | 6 | # Time series data often contains NA's, either due to missing days, 7 | # noncontiguous series, or merging multiple series, 8 | # 9 | # Some Calulcations, such as return calculations, require data that 10 | # looks like a vector, and needs the output of na.omit 11 | # 12 | # It is often convenient to apply these vector-like functions, but 13 | # you still need to keep track of the structure of the oridginal data. 14 | 15 | # Inputs 16 | # x the time series to apply FUN too 17 | # FUN function to apply 18 | # ... any additonal parameters to FUN 19 | 20 | # Outputs: 21 | # An xts time series that has the same index and NA's as the data 22 | # passed in, after applying FUN 23 | 24 | nx <- na.omit(x) 25 | fx <- FUN(nx, ... = ...) 26 | if (is.vector(fx)) { 27 | result <- .xts(fx, .index(x), .indexCLASS = indexClass(x)) 28 | } 29 | else { 30 | result <- merge(fx, .xts(, .index(x))) 31 | } 32 | return(result) 33 | } 34 | 35 | ############################################################################### 36 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 37 | # 38 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 39 | # 40 | # This R package is distributed under the terms of the GNU Public License (GPL) 41 | # for full details see the file COPYING 42 | # 43 | # $Id: na.skip.R 1855 2012-01-15 12:57:58Z braverock $ 44 | # 45 | ############################################################################### -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/man/ACStdDev.annualized.Rd: -------------------------------------------------------------------------------- 1 | \name{ACStdDev.annualized} 2 | \alias{ACStdDev.annualized} 3 | \alias{sd.annualized} 4 | \alias{sd.multiperiod} 5 | \alias{StdDev.annualized} 6 | \title{Autocorrleation adjusted Standard Deviation} 7 | \usage{ 8 | ACStdDev.annualized(R, lag = 6, scale = NA, ...) 9 | } 10 | \arguments{ 11 | \item{R}{an xts, vector, matrix, data frame, timeSeries 12 | or zoo object of asset returns} 13 | 14 | \item{lag}{: number of autocorrelated lag factors 15 | inputted by user} 16 | 17 | \item{scale}{number of periods in a year (daily scale = 18 | 252, monthly scale = 12, quarterly scale = 4)} 19 | 20 | \item{\dots}{any other passthru parameters} 21 | } 22 | \description{ 23 | Incorporating the component of lagged autocorrelation 24 | factor into adjusted time scale standard deviation 25 | translation 26 | } 27 | \details{ 28 | Given a sample of historical returns R(1),R(2), . . 29 | .,R(T),the method assumes the fund manager smooths 30 | returns in the following manner, when 't' is the unit 31 | time interval: The square root time translation can be 32 | defined as : \deqn{ \sigma(T) = T \sqrt\sigma(t)} 33 | } 34 | \examples{ 35 | library(PerformanceAnalytics) 36 | data(edhec) 37 | ACStdDev.annualized(edhec,3) 38 | } 39 | \author{ 40 | Peter Carl,Brian Peterson, Shubhankit Mohan 41 | } 42 | \references{ 43 | Burghardt, G., and L. Liu, \emph{ It's the 44 | Autocorrelation, Stupid (November 2012) Newedge working 45 | paper.} Paper Available at : 46 | \url{http://www.amfmblog.com/assets/Newedge-Autocorrelation.pdf} 47 | } 48 | \keyword{distribution} 49 | \keyword{models} 50 | \keyword{multivariate} 51 | \keyword{ts} 52 | 53 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/man/AcarSim.Rd: -------------------------------------------------------------------------------- 1 | \name{AcarSim} 2 | \alias{AcarSim} 3 | \title{Acar-Shane Maximum Loss Plot} 4 | \usage{ 5 | AcarSim(R, nsim = 1) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{nsim}{number of simulations input} 12 | } 13 | \description{ 14 | To get some insight on the relationships between maximum 15 | drawdown per unit of volatility and mean return divided 16 | by volatility, we have proceeded to Monte-Carlo 17 | simulations. We have simulated cash flows over a period 18 | of 36 monthly returns and measured maximum drawdown for 19 | varied levels of annualised return divided by volatility 20 | varying from minus \emph{two to two} by step of 21 | \emph{0.1} . The process has been repeated \bold{six 22 | thousand times}. 23 | } 24 | \details{ 25 | Unfortunately, there is no \bold{analytical formulae} to 26 | establish the maximum drawdown properties under the 27 | random walk assumption. We should note first that due to 28 | its definition, the maximum drawdown divided by 29 | volatility can be interpreted as the only function of the 30 | ratio mean divided by volatility. \deqn{MD/[\sigma]= Min 31 | (\sum[X(j)])/\sigma = F(\mu/\sigma)} Where j varies from 32 | 1 to n ,which is the number of drawdown's in simulation 33 | } 34 | \examples{ 35 | library(PerformanceAnalytics) 36 | #AcarSim(R) 37 | } 38 | \author{ 39 | Shubhankit Mohan 40 | } 41 | \references{ 42 | Maximum Loss and Maximum Drawdown in Financial 43 | Markets,\emph{International Conference Sponsored by BNP 44 | and Imperial College on: Forecasting Financial Markets, 45 | London, United Kingdom, May 1997} 46 | \url{http://www.intelligenthedgefundinvesting.com/pubs/easj.pdf} 47 | } 48 | \keyword{Drawdown} 49 | \keyword{Loss} 50 | \keyword{Maximum} 51 | \keyword{Simulated} 52 | 53 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/man/EMaxDDGBM.Rd: -------------------------------------------------------------------------------- 1 | \name{EmaxDDGBM} 2 | \alias{EmaxDDGBM} 3 | \title{Summary of Expected Drawdown using Brownian Motion Assumptions and Return-Volatility} 4 | \usage{ 5 | EmaxDDGBM(R, digits = 4) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{digits}{significant number} 12 | } 13 | \description{ 14 | Works on the model specified by Maddon-Ismail which 15 | investigates the behavior of this statistic for a 16 | Brownian motion with drift. 17 | } 18 | \details{ 19 | If X(t) is a random process on [0, T ], the maximum 20 | drawdown at time T , D(T), is defined by where \deqn{D(T) 21 | = sup [X(s) - X(t)]} where s belongs to [0,t] and s 22 | belongs to [0,T] Informally, this is the largest drop 23 | from a peak to a bottom. In this paper, we investigate 24 | the behavior of this statistic for a Brownian motion with 25 | drift. In particular, we give an infinite series 26 | representation of its distribution, and consider its 27 | expected value. When the drift is zero, we give an 28 | analytic expression for the expected value, and for 29 | non-zero drift, we give an infinite series 30 | representation. For all cases, we compute the limiting 31 | \bold{(\eqn{T tends to \infty})} behavior, which can be 32 | logarithmic (\eqn{\mu} > 0), square root (\eqn{\mu} = 0), 33 | or linear (\eqn{\mu} < 0). 34 | } 35 | \examples{ 36 | library(PerformanceAnalytics) 37 | data(edhec) 38 | EmaxDDGBM(edhec) 39 | } 40 | \author{ 41 | Shubhankit Mohan 42 | } 43 | \references{ 44 | Magdon-Ismail, M., Atiya, A., Pratap, A., and Yaser S. 45 | Abu-Mostafa: On the Maximum Drawdown of a Browninan 46 | Motion, Journal of Applied Probability 41, pp. 147-161, 47 | 2004 48 | \url{http://alumnus.caltech.edu/~amir/drawdown-jrnl.pdf} 49 | } 50 | \keyword{Assumptions} 51 | \keyword{Brownian} 52 | \keyword{Drawdown} 53 | \keyword{Expected} 54 | \keyword{models} 55 | \keyword{Motion} 56 | \keyword{Using} 57 | 58 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/man/GLMSmoothIndex.Rd: -------------------------------------------------------------------------------- 1 | \name{GLMSmoothIndex} 2 | \alias{GLMSmoothIndex} 3 | \alias{Return.Geltner} 4 | \title{GLM Index} 5 | \usage{ 6 | GLMSmoothIndex(R = NULL, ...) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeSeries 10 | or zoo object of asset returns} 11 | 12 | \item{...}{Additional Parameters} 13 | } 14 | \description{ 15 | Getmansky Lo Markov Smoothing Index is a useful summary 16 | statistic for measuring the concentration of weights is a 17 | sum of square of Moving Average lag coefficient. This 18 | measure is well known in the industrial organization 19 | literature as the \bold{ Herfindahl index}, a measure of 20 | the concentration of firms in a given industry. The index 21 | is maximized when one coefficient is 1 and the rest are 22 | 0. In the context of smoothed returns, a lower value 23 | implies more smoothing, and the upper bound of 1 implies 24 | no smoothing, hence \eqn{\xi} is reffered as a 25 | '\bold{smoothingindex}'. \deqn{ \xi = \sum\theta(j)^2} 26 | Where j belongs to 0 to k,which is the number of lag 27 | factors input. 28 | } 29 | \examples{ 30 | require(PerformanceAnalytics) 31 | library(PerformanceAnalytics) 32 | data(edhec) 33 | GLMSmoothIndex(edhec) 34 | } 35 | \author{ 36 | Peter Carl, Brian Peterson, Shubhankit Mohan 37 | } 38 | \references{ 39 | \emph{Getmansky, Mila, Lo, Andrew W. and Makarov, Igor} 40 | An Econometric Model of Serial Correlation and 41 | Illiquidity in Hedge Fund Returns (March 1, 2003). MIT 42 | Sloan Working Paper No. 4288-03; MIT Laboratory for 43 | Financial Engineering Working Paper No. LFE-1041A-03; 44 | EFMA 2003 Helsinki Meetings. Paper available at SSRN: 45 | \url{http://ssrn.com/abstract=384700} 46 | } 47 | \keyword{distribution} 48 | \keyword{models} 49 | \keyword{multivariate} 50 | \keyword{non-iid} 51 | \keyword{ts} 52 | 53 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/man/QP.Norm.Rd: -------------------------------------------------------------------------------- 1 | \name{QP.Norm} 2 | \alias{QP.Norm} 3 | \title{QP function for calculation of Sharpe Ratio} 4 | \usage{ 5 | QP.Norm(R, tau, scale = NA) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{tau}{Time Scale Translations Factor} 12 | 13 | \item{scale}{number of periods in a year (daily scale = 14 | 252, monthly scale =} 15 | } 16 | \description{ 17 | QP function for calculation of Sharpe Ratio 18 | } 19 | \seealso{ 20 | \code{\link{CalmarRatio.Norm}}, \cr 21 | } 22 | 23 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/man/chart.AcarSim.Rd: -------------------------------------------------------------------------------- 1 | \name{chart.AcarSim} 2 | \alias{chart.AcarSim} 3 | \title{Acar-Shane Maximum Loss Plot} 4 | \usage{ 5 | chart.AcarSim(R) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | } 11 | \description{ 12 | To get some insight on the relationships between maximum 13 | drawdown per unit of volatility and mean return divided 14 | by volatility, we have proceeded to Monte-Carlo 15 | simulations. We have simulated cash flows over a period 16 | of 36 monthly returns and measured maximum drawdown for 17 | varied levels of annualised return divided by volatility 18 | varying from minus \emph{two to two} by step of 19 | \emph{0.1} . The process has been repeated \bold{six 20 | thousand times}. 21 | } 22 | \details{ 23 | Unfortunately, there is no \bold{analytical formulae} to 24 | establish the maximum drawdown properties under the 25 | random walk assumption. We should note first that due to 26 | its definition, the maximum drawdown divided by 27 | volatility is an only function of the ratio mean divided 28 | by volatility. \deqn{MD/[\sigma]= Min (\sum[X(j)])/\sigma 29 | = F(\mu/\sigma)} Where j varies from 1 to n ,which is the 30 | number of drawdown's in simulation 31 | } 32 | \examples{ 33 | require(PerformanceAnalytics) 34 | library(PerformanceAnalytics) 35 | data(edhec) 36 | chart.AcarSim(edhec) 37 | } 38 | \author{ 39 | Shubhankit Mohan 40 | } 41 | \references{ 42 | Maximum Loss and Maximum Drawdown in Financial 43 | Markets,\emph{International Conference Sponsored by BNP 44 | and Imperial College on: Forecasting Financial Markets, 45 | London, United Kingdom, May 1997} 46 | \url{http://www.intelligenthedgefundinvesting.com/pubs/easj.pdf} 47 | } 48 | \keyword{Drawdown} 49 | \keyword{Loss} 50 | \keyword{Maximum} 51 | \keyword{Simulated} 52 | 53 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/man/chart.Autocorrelation.Rd: -------------------------------------------------------------------------------- 1 | \name{chart.Autocorrelation} 2 | \alias{chart.Autocorrelation} 3 | \title{Stacked Bar Autocorrelation Plot} 4 | \usage{ 5 | chart.Autocorrelation(R) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of an asset return} 10 | } 11 | \value{ 12 | Stack Bar plot of lagged return coefficients 13 | } 14 | \description{ 15 | A wrapper to create box and whiskers plot of lagged 16 | autocorrelation analysis 17 | } 18 | \details{ 19 | We have also provided controls for all the symbols and 20 | lines in the chart. One default, set by 21 | \code{as.Tufte=TRUE}, will strip chartjunk and draw a 22 | Boxplot per recommendations by Burghardt, Duncan and 23 | Liu(2013) 24 | } 25 | \examples{ 26 | data(edhec) 27 | chart.Autocorrelation(edhec[,1]) 28 | } 29 | \author{ 30 | Peter Carl, Brian Peterson, Shubhankit Mohan 31 | } 32 | \references{ 33 | Burghardt, G., and L. Liu, \emph{ It's the 34 | Autocorrelation, Stupid (November 2012) Newedge working 35 | paper.} Paper Available at : 36 | \url{http://www.amfmblog.com/assets/Newedge-Autocorrelation.pdf} 37 | } 38 | \seealso{ 39 | \code{\link[graphics]{boxplot}} 40 | } 41 | \keyword{Autocorrelation} 42 | \keyword{factors} 43 | \keyword{lag} 44 | 45 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/man/table.ComparitiveReturn.GLM.Rd: -------------------------------------------------------------------------------- 1 | \name{table.ComparitiveReturn.GLM} 2 | \alias{table.ComparitiveReturn.GLM} 3 | \title{Compenent Decomposition of Table of Unsmooth Returns for GLM Model} 4 | \usage{ 5 | table.ComparitiveReturn.GLM(R, n = 3, digits = 4) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{n}{number of series lags} 12 | 13 | \item{digits}{number of digits to round results to} 14 | } 15 | \description{ 16 | Creates a table of comparitive changes in Normality 17 | Properties for Third and Fourth Moment Vectors i.e. 18 | Skewness and Kurtosis for Orignal and Unsmooth Returns 19 | Respectively 20 | } 21 | \examples{ 22 | library(PerformanceAnalytics) 23 | library(tseries) 24 | data(managers) 25 | table.ComparitiveReturn.GLM(managers,3) 26 | } 27 | \author{ 28 | Peter Carl, Brian Peterson, Shubhankit Mohan 29 | } 30 | \references{ 31 | Okunev, John and White, Derek R., \emph{ Hedge Fund Risk 32 | Factors and Value at Risk of Credit Trading Strategies} 33 | (October 2003). Available at SSRN: 34 | \url{http://ssrn.com/abstract=460641} 35 | } 36 | \keyword{GLM} 37 | \keyword{models} 38 | \keyword{return} 39 | \keyword{ts} 40 | \keyword{unsmooth} 41 | 42 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/noniid.sm.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageInstallArgs: --no-multiarch 17 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/tests/Examples/noniid.sm-Ex.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/tests/Examples/noniid.sm-Ex.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-ACFSTDEV.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-ACFSTDEV.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-ConditionalDrawdown.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-ConditionalDrawdown.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-EmaxDDGBM.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-EmaxDDGBM.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-GLMReturn.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-GLMReturn.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-GLMSmoothIndex.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-GLMSmoothIndex.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-LoSharpeRatio.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-LoSharpeRatio.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-Managers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-Managers.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-NormCalmar-Sterling.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-NormCalmar-Sterling.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-OWReturn.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-OWReturn.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-OkunevWhite.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-OkunevWhite.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-ShaneAcarMaxLoss.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-ShaneAcarMaxLoss.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-UnSmoothReturnAnalysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm/vignettes/Non-iid-UnSmoothReturnAnalysis.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/noniid.sm_0.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/noniid.sm_0.1.zip -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Code/Data/Investment.csv: -------------------------------------------------------------------------------- 1 | "","GNP","Investment","Price","Interest","RealGNP","RealInv","RealInt" 2 | "1",596.7,90.9,0.7167,3.23,832.565927166178,126.83131017162,NA 3 | "2",637.7,97.4,0.7277,3.55,876.322660436993,133.84636526041,2.01518766568997 4 | "3",691.1,113.5,0.7436,4.04,929.397525551372,152.635825712749,1.85503366772021 5 | "4",756,125.7,0.7676,4.5,984.887962480459,163.757165190203,1.27245831091986 6 | "5",799.6,122.8,0.7906,4.19,1011.38375917025,155.325069567417,1.19364773319437 7 | "6",873.4,133.3,0.8254,5.16,1058.15362248607,161.497455779016,0.758279787503155 8 | "7",944,149.3,0.8679,5.87,1087.68291277797,172.024426777279,0.720981342379455 9 | "8",992.7,144.2,0.9145,5.95,1085.51120831055,157.681793329688,0.580717824634178 10 | "9",1077.6,166.4,0.9601,4.88,1122.3830850953,173.315279658369,-0.106331328594858 11 | "10",1185.9,195,1,4.5,1185.9,195,0.344182897614827 12 | "11",1326.4,229.8,1.0575,6.44,1254.27895981087,217.304964539007,0.68999999999999 13 | "12",1434.2,228.7,1.1508,7.83,1246.26346889121,198.731317344456,-0.992695035460986 14 | "13",1549.2,206.1,1.2579,6.25,1231.57643691867,163.844502742666,-3.05656934306569 15 | "14",1718,257.9,1.3234,5.5,1298.17137675684,194.87683240139,0.292908816281112 16 | "15",1918.3,324.1,1.4005,5.46,1369.72509817922,231.417350946091,-0.365902977180004 17 | "16",2163.9,386.6,1.5042,7.46,1438.57199840447,257.013694987369,0.0555016065690905 18 | "17",2417.8,423,1.6342,10.28,1479.50067311223,258.842246970995,1.63753224305278 19 | "18",2631.7,401.9,1.7842,11.77,1475.00280237642,225.255016253783,2.59119691592217 20 | "19",2954.1,474.9,1.9514,13.42,1513.83622014964,243.363738854156,4.0488532675709 21 | "20",3073,414.5,2.0688,11.02,1485.40216550657,200.357695282289,5.00380649789895 22 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Code/Data/PublicSchools.csv: -------------------------------------------------------------------------------- 1 | "","Expenditure","Income" 2 | "Alabama",275,6247 3 | "Alaska",821,10851 4 | "Arizona",339,7374 5 | "Arkansas",275,6183 6 | "California",387,8850 7 | "Colorado",452,8001 8 | "Connecticut",531,8914 9 | "Delaware",424,8604 10 | "Florida",316,7505 11 | "Georgia",265,6700 12 | "Hawaii",403,8380 13 | "Idaho",304,6813 14 | "Illinois",437,8745 15 | "Indiana",345,7696 16 | "Iowa",431,7873 17 | "Kansas",355,8001 18 | "Kentucky",260,6615 19 | "Louisiana",316,6640 20 | "Maine",327,6333 21 | "Maryland",427,8306 22 | "Massachusetts",427,8063 23 | "Michigan",466,8442 24 | "Minnesota",477,7847 25 | "Mississippi",259,5736 26 | "Missouri",274,7342 27 | "Montana",433,7051 28 | "Nebraska",294,7391 29 | "Nevada",359,9032 30 | "New Hampshire",279,7277 31 | "New Jersey",423,8818 32 | "New Mexico",388,6505 33 | "New York",447,8267 34 | "North Carolina",335,6607 35 | "North Dakota",311,7478 36 | "Ohio",322,7812 37 | "Oklahoma",320,6951 38 | "Oregon",397,7839 39 | "Pennsylvania",412,7733 40 | "Rhode Island",342,7526 41 | "South Carolina",315,6242 42 | "South Dakota",321,6841 43 | "Tennessee",268,6489 44 | "Texas",315,7697 45 | "Utah",417,6622 46 | "Vermont",353,6541 47 | "Virginia",356,7624 48 | "Washington",415,8450 49 | "Washington DC",428,10022 50 | "West Virginia",320,6456 51 | "Wisconsin",NA,7597 52 | "Wyoming",500,9096 53 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Code/Data/RealInt.csv: -------------------------------------------------------------------------------- 1 | "","V1" 2 | "1",1.99132 3 | "2",0.00403 4 | "3",2.27 5 | "4",0.84833 6 | "5",1.89112 7 | "6",-0.28 8 | "7",3.68431 9 | "8",1.62478 10 | "9",1.21599 11 | "10",1.28373 12 | "11",1.70141 13 | "12",3.16687 14 | "13",2.32779 15 | "14",2.26202 16 | "15",1.91218 17 | "16",3.53196 18 | "17",-0.31777 19 | "18",3.44694 20 | "19",1.52422 21 | "20",0.74268 22 | "21",1.31541 23 | "22",0.36646 24 | "23",3.59562 25 | "24",3.6574 26 | "25",0.97494 27 | "26",-0.5328 28 | "27",1.12681 29 | "28",0.31123 30 | "29",0.57834 31 | "30",1.08163 32 | "31",0.24977 33 | "32",0.23792 34 | "33",-0.32653 35 | "34",1.14733 36 | "35",1.19323 37 | "36",2.58962 38 | "37",0.01195 39 | "38",2.63842 40 | "39",0.42092 41 | "40",2.58823 42 | "41",-2.19809 43 | "42",2.89548 44 | "43",1.8213 45 | "44",0.86332 46 | "45",0.67496 47 | "46",0.34435 48 | "47",1.22762 49 | "48",-2.83991 50 | "49",-1.8163 51 | "50",-2.22965 52 | "51",-1.58457 53 | "52",-6.31184 54 | "53",-2.46258 55 | "54",-5.61479 56 | "55",-3.53887 57 | "56",1.0178 58 | "57",-1.58875 59 | "58",-1.85396 60 | "59",-0.2567 61 | "60",2.42226 62 | "61",-1.29502 63 | "62",-0.48977 64 | "63",1.21167 65 | "64",-4.85498 66 | "65",-3.599 67 | "66",0.17094 68 | "67",1.51603 69 | "68",-1.85304 70 | "69",-5.60478 71 | "70",-1.25767 72 | "71",0.96658 73 | "72",-3.09451 74 | "73",-5.26773 75 | "74",-4.03154 76 | "75",-1.76618 77 | "76",-5.73978 78 | "77",3.83047 79 | "78",0.52007 80 | "79",-0.18033 81 | "80",3.82808 82 | "81",3.01171 83 | "82",2.75289 84 | "83",11.74184 85 | "84",9.91701 86 | "85",3.03444 87 | "86",10.15143 88 | "87",9.29177 89 | "88",6.87498 90 | "89",2.43675 91 | "90",4.37202 92 | "91",6.77774 93 | "92",4.16692 94 | "93",5.65037 95 | "94",5.17734 96 | "95",9.41206 97 | "96",3.77006 98 | "97",4.24568 99 | "98",4.53154 100 | "99",3.39706 101 | "100",8.93951 102 | "101",4.20825 103 | "102",3.43461 104 | "103",4.30529 105 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Code/Data/ps.csv: -------------------------------------------------------------------------------- 1 | "","Expenditure","Income" 2 | "Alabama",275,0.6247 3 | "Alaska",821,1.0851 4 | "Arizona",339,0.7374 5 | "Arkansas",275,0.6183 6 | "California",387,0.885 7 | "Colorado",452,0.8001 8 | "Connecticut",531,0.8914 9 | "Delaware",424,0.8604 10 | "Florida",316,0.7505 11 | "Georgia",265,0.67 12 | "Hawaii",403,0.838 13 | "Idaho",304,0.6813 14 | "Illinois",437,0.8745 15 | "Indiana",345,0.7696 16 | "Iowa",431,0.7873 17 | "Kansas",355,0.8001 18 | "Kentucky",260,0.6615 19 | "Louisiana",316,0.664 20 | "Maine",327,0.6333 21 | "Maryland",427,0.8306 22 | "Massachusetts",427,0.8063 23 | "Michigan",466,0.8442 24 | "Minnesota",477,0.7847 25 | "Mississippi",259,0.5736 26 | "Missouri",274,0.7342 27 | "Montana",433,0.7051 28 | "Nebraska",294,0.7391 29 | "Nevada",359,0.9032 30 | "New Hampshire",279,0.7277 31 | "New Jersey",423,0.8818 32 | "New Mexico",388,0.6505 33 | "New York",447,0.8267 34 | "North Carolina",335,0.6607 35 | "North Dakota",311,0.7478 36 | "Ohio",322,0.7812 37 | "Oklahoma",320,0.6951 38 | "Oregon",397,0.7839 39 | "Pennsylvania",412,0.7733 40 | "Rhode Island",342,0.7526 41 | "South Carolina",315,0.6242 42 | "South Dakota",321,0.6841 43 | "Tennessee",268,0.6489 44 | "Texas",315,0.7697 45 | "Utah",417,0.6622 46 | "Vermont",353,0.6541 47 | "Virginia",356,0.7624 48 | "Washington",415,0.845 49 | "Washington DC",428,1.0022 50 | "West Virginia",320,0.6456 51 | "Wyoming",500,0.9096 52 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Code/Equivalent Matlab Code/NWmissings.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/sandbox/Week6-7/Code/Equivalent Matlab Code/NWmissings.m -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Code/Equivalent Matlab Code/effort.dat: -------------------------------------------------------------------------------- 1 | setting effort change 2 | Bolivia 46 0 1 3 | Brazil 74 0 10 4 | Chile 89 16 29 5 | Colombia 77 16 25 6 | CostaRica 84 21 29 7 | Cuba 89 15 40 8 | DominicanRep 68 14 21 9 | Ecuador 70 6 0 10 | ElSalvador 60 13 13 11 | Guatemala 55 9 4 12 | Haiti 35 3 0 13 | Honduras 51 7 7 14 | Jamaica 87 23 21 15 | Mexico 83 4 9 16 | Nicaragua 68 0 7 17 | Panama 84 19 22 18 | Paraguay 74 3 6 19 | Peru 73 0 2 20 | TrinidadTobago 84 15 29 21 | Venezuela 91 7 11 22 | 23 | 24 | -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Code/Equivalent Matlab Code/nwse.m: -------------------------------------------------------------------------------- 1 | function [V,S]=nwse(e,X,nlags) 2 | % PURPOSE: computes Newey-West adjusted heteroscedastic-serial 3 | % consistent standard errors (only se's) 4 | %--------------------------------------------------- 5 | % USAGE: [V,S] = nwse(e,X,nlag) 6 | % where: e = T x n vector of model residuls 7 | % X = T x k matrix of independ vars 8 | % nlags = lag length to use 9 | %--------------------------------------------------- 10 | % RETURNS: 11 | % V is the Newey-West Var-Cov matrix 12 | % S is the spectral density of u = e.*X 13 | % -------------------------------------------------- 14 | 15 | % written by: Mike Cliff, Purdue Finance, mcliff@mgmt.purdue.edu 16 | % CREATED 11/17/00 17 | % MODIFIED 1/23/01 Input e, X separtely; return V, S; df adjustment 18 | % 2/20/01 Allow for system of eqs (multiple e vectors) 19 | 20 | if (nargin ~= 3); error('Wrong # of arguments to nwse'); end; 21 | 22 | [T,k] = size(X); 23 | n = cols(e); 24 | S = zeros(n*k,n*k); 25 | if k == 1 & X == ones(T,1) 26 | u = e; 27 | else 28 | u = []; 29 | for i = 1:cols(e) 30 | u = [u repmat(e(:,i),1,k).*X]; 31 | end 32 | end 33 | 34 | for lag = 0:nlags 35 | rho = u(1:T-lag,:)'*u(1+lag:T,:)/(T-k); 36 | if lag >= 1, rho = rho + rho'; end 37 | wt = 1 - lag/(nlags+1); 38 | S = S + wt*rho; 39 | end 40 | 41 | V = kron(eye(n),(X'*X/T)\eye(k)); 42 | V = V*S*V/T; -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Code/Equivalent Matlab Code/sim_NWmissings.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/sandbox/Week6-7/Code/Equivalent Matlab Code/sim_NWmissings.m -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Code/Tests/HAC Data.R: -------------------------------------------------------------------------------- 1 | data("RealInt") 2 | #OLS-based CUSUM test with quadratic spectral kernel HAC estimate: 3 | ocus <- gefp(RealInt ~ 1, fit = lm, vcov = kernHAC) 4 | plot(ocus, aggregate = FALSE) 5 | sctest(ocus) 6 | #supF test with quadratic spectral kernel HAC estimate: 7 | fs <- Fstats(RealInt ~ 1, vcov = kernHAC) 8 | plot(fs) 9 | sctest(fs) 10 | #Breakpoint estimation and confidence intervals with quadratic spectral kernel HAC estimate: 11 | bp <- breakpoints(RealInt ~ 1) 12 | confint(bp, vcov = kernHAC) 13 | plot(bp) 14 | #Visualization: 15 | plot(RealInt, ylab = "Real interest rate") 16 | lines(ts(fitted(bp), start = start(RealInt), freq = 4), col = 4) 17 | lines(confint(bp, vcov = kernHAC)) -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Code/Tests/Tests.R: -------------------------------------------------------------------------------- 1 | fpe <- read.table("http://data.princeton.edu/wws509/datasets/effort.dat") 2 | attach(fpe) 3 | lmfit = lm( change ~ setting + effort ) 4 | sandwich(lmfit) 5 | Fr <- c(68,42,42,30, 37,52,24,43, 6 | 66,50,33,23, 47,55,23,47, 7 | 63,53,29,27, 57,49,19,29) 8 | 9 | Temp <- gl(2, 2, 24, labels = c("Low", "High")) 10 | Soft <- gl(3, 8, 24, labels = c("Hard","Medium","Soft")) 11 | M.user <- gl(2, 4, 24, labels = c("N", "Y")) 12 | Brand <- gl(2, 1, 24, labels = c("X", "M")) 13 | 14 | detg <- data.frame(Fr,Temp, Soft,M.user, Brand) 15 | detg.m0 <- glm(Fr ~ M.user*Temp*Soft + Brand, family = poisson, data = detg) 16 | summary(detg.m0) 17 | 18 | detg.mod <- glm(terms(Fr ~ M.user*Temp*Soft + Brand*M.user*Temp, 19 | keep.order = TRUE), 20 | family = poisson, data = detg) 21 | sandwich(detg.mod) -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Literature/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/sandbox/Week6-7/Literature/Thumbs.db -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Literature/Zelisis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/sandbox/Week6-7/Literature/Zelisis.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Literature/sandwich-OOP.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/sandbox/Week6-7/Literature/sandwich-OOP.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Vignette/HACintegrated-hac-kweights.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/sandbox/Week6-7/Vignette/HACintegrated-hac-kweights.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Vignette/HACintegrated-hac-plot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/sandbox/Week6-7/Vignette/HACintegrated-hac-plot.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Vignette/HACintegrated-hc-plot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/sandbox/Week6-7/Vignette/HACintegrated-hc-plot.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Vignette/Test_Report.Rnw: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \begin{document} 4 | 5 | \SweaveOpts{concordance=TRUE} 6 | <<>>= 7 | library(sandwich) 8 | fpe <- read.table("http://data.princeton.edu/wws509/datasets/effort.dat") 9 | attach(fpe) 10 | lmfit = lm( change ~ setting + effort ) 11 | lmfit 12 | sandwich(lmfit) 13 | Fr <- c(68,42,42,30, 37,52,24,43, 14 | 66,50,33,23, 47,55,23,47, 15 | 63,53,29,27, 57,49,19,29) 16 | 17 | Temp <- gl(2, 2, 24, labels = c("Low", "High")) 18 | Soft <- gl(3, 8, 24, labels = c("Hard","Medium","Soft")) 19 | M.user <- gl(2, 4, 24, labels = c("N", "Y")) 20 | Brand <- gl(2, 1, 24, labels = c("X", "M")) 21 | 22 | detg <- data.frame(Fr,Temp, Soft,M.user, Brand) 23 | detg.m0 <- glm(Fr ~ M.user*Temp*Soft + Brand, family = poisson, data = detg) 24 | detg.m0 25 | sandwich(detg.m0) 26 | detg.mod <- glm(terms(Fr ~ M.user*Temp*Soft + Brand*M.user*Temp, 27 | keep.order = TRUE), 28 | family = poisson, data = detg) 29 | sandwich(detg.mod) 30 | @ 31 | 32 | 33 | 34 | 35 | \end{document} -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/Week6-7/Vignette/Test_Report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/sandbox/Week6-7/Vignette/Test_Report.pdf -------------------------------------------------------------------------------- /sandbox/Shubhankit/sandbox/vignettes/Managers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/Shubhankit/sandbox/vignettes/Managers.pdf -------------------------------------------------------------------------------- /sandbox/fPerformance/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: fPerformance 2 | Version: 290.75 3 | Revision: 4030 4 | Date: 2009-04-01 5 | Title: Rmetrics - Portfolio Performance 6 | Author: Diethelm Wuertz 7 | Depends: R (>= 2.7.0), methods, MASS, timeDate, timeSeries (>= 290.81), 8 | fPortfolio 9 | Suggests: corpcor, covRobust, RUnit, tcltk 10 | Maintainer: Rmetrics Core Team 11 | Description: Environment for teaching "Financial Engineering and 12 | Computational Finance" 13 | NOTE: SEVERAL PARTS ARE STILL PRELIMINARY AND MAY BE CHANGED IN THE 14 | FUTURE. THIS TYPICALLY INCLUDES FUNCTION AND ARGUMENT NAMES, AS 15 | WELL AS DEFAULTS FOR ARGUMENTS AND RETURN VALUES. 16 | LazyLoad: yes 17 | LazyData: yes 18 | License: GPL (>= 2) 19 | URL: http://www.rmetrics.org 20 | -------------------------------------------------------------------------------- /sandbox/fPerformance/man/returns.Rd: -------------------------------------------------------------------------------- 1 | \name{returns} 2 | 3 | 4 | \alias{returns} 5 | \alias{annualisedReturn} 6 | \alias{periodicReturn} 7 | \alias{averageReturn} 8 | 9 | 10 | \title{Financial Returns} 11 | 12 | 13 | \description{ 14 | 15 | Returns financial returns 16 | 17 | } 18 | 19 | 20 | \usage{ 21 | annualisedReturn(periodPercentReturns, 22 | method = c("geometric", "arithmetic"), 23 | scale = c("quarterly", "monthly", "weekly", "daily")) 24 | 25 | periodicReturn(periodPercentReturns) 26 | averageReturn(periodPercentReturns) 27 | } 28 | 29 | 30 | \arguments{ 31 | 32 | \item{periodPercentReturns}{ 33 | a univariate object of class \code{timeSeries} with 34 | percentual returns whose period is given by the argument 35 | \code{scale}. 36 | } 37 | \item{method}{ 38 | a character string, describing how the returns should be 39 | calculated, either \code{"geometric"} or \code{"arithmetic"}. 40 | } 41 | \item{scale}{ 42 | a character string specifying the scale or period of the 43 | returns. This may be one of \code{"quarterly"}, \code{"monthly"}, 44 | \code{"weekly"}, \code{"daily"}. 45 | } 46 | 47 | } 48 | 49 | 50 | \value{ 51 | 52 | the functions return a numeric value, the financial return. 53 | 54 | } 55 | 56 | 57 | \details{ 58 | 59 | \tabular{ll}{ 60 | \code{annualisedReturn} \tab Returns annualised return, \cr 61 | \code{periodicReturn} \tab returns period return, \cr 62 | \code{averageReturn} \tab a synonyme for the function periodReturn(). } 63 | 64 | For the definitions and mathematical formulas we refer to Carl Bacon's 65 | book (2008). 66 | 67 | } 68 | 69 | 70 | \author{ 71 | 72 | Diethelm Wuertz for this \R-port. 73 | 74 | } 75 | 76 | 77 | \references{ 78 | 79 | Bacon, C., (2008); 80 | \emph{Practical Portfolio Performance Measurement and Attribution}, 81 | 2nd Edtion, Wiley. 82 | 83 | } 84 | 85 | 86 | \keyword{models} 87 | 88 | -------------------------------------------------------------------------------- /sandbox/pulkit/.Rbuildignore: -------------------------------------------------------------------------------- 1 | sandbox 2 | generatechangelog\.sh 3 | ChangeLog\.1\.0\.0 4 | week* 5 | Week* 6 | ^.*\.Rproj$ 7 | ^\.Rproj\.user$ 8 | -------------------------------------------------------------------------------- /sandbox/pulkit/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: noniid.pm 2 | Type: Package 3 | Title: Non-i.i.d. GSoC 2013 Pulkit 4 | Version: 0.1 5 | Date: $Date: 2013-05-13 14:30:22 -0500 (Mon, 13 May 2013) $ 6 | Author: Pulkit Mahotra 7 | Contributors: Peter Carl, Brian G. Peterson 8 | Depends: 9 | xts, 10 | PerformanceAnalytics, 11 | lpSolve 12 | Suggests: 13 | PortfolioAnalytics, 14 | lpSolve 15 | Maintainer: Brian G. Peterson 16 | Description: GSoC 2013 project to replicate literature on drawdowns and 17 | non-i.i.d assumptions in finance. 18 | License: GPL (>=3) 19 | ByteCompile: TRUE 20 | Collate: 21 | 'BenchmarkPlots.R' 22 | 'BenchmarkSR.R' 23 | 'CDaRMultipath.R' 24 | 'CdaR.R' 25 | 'chart.Penance.R' 26 | 'chart.REDD.R' 27 | 'chart.SharpeEfficient.R' 28 | 'Drawdownalpha.R' 29 | 'DrawdownBetaMulti.R' 30 | 'DrawdownBeta.R' 31 | 'EDDCOPS.R' 32 | 'Edd.R' 33 | 'GoldenSection.R' 34 | 'MaxDD.R' 35 | 'MinTRL.R' 36 | 'MonteSimulTriplePenance.R' 37 | 'na.skip.R' 38 | 'ProbSharpeRatio.R' 39 | 'PSRopt.R' 40 | 'REDDCOPS.R' 41 | 'redd.R' 42 | 'REM.R' 43 | 'SRIndifferenceCurve.R' 44 | 'table.Penance.R' 45 | 'table.PSR.R' 46 | 'TriplePenance.R' 47 | 'TuW.R' 48 | 'capm_aorda.R' 49 | 'psr_python.R' 50 | 'ret.R' 51 | 'Penance.R' 52 | 'ExtremeDrawdown.R' 53 | 'gpdmle.R' 54 | -------------------------------------------------------------------------------- /sandbox/pulkit/NAMESPACE: -------------------------------------------------------------------------------- 1 | export(AlphaDrawdown) 2 | export(BenchmarkSR) 3 | export(BetaDrawdown) 4 | export(CDaR) 5 | export(CdarMultiPath) 6 | export(chart.BenchmarkSR) 7 | export(chart.Penance) 8 | export(chart.REDD) 9 | export(chart.SRIndifference) 10 | export(DrawdownGPD) 11 | export(EconomicDrawdown) 12 | export(EDDCOPS) 13 | export(golden_section) 14 | export(MaxDD) 15 | export(MinTrackRecord) 16 | export(MonteSimulTriplePenance) 17 | export(MultiBetaDrawdown) 18 | export(Penance) 19 | export(ProbSharpeRatio) 20 | export(PsrPortfolio) 21 | export(REDDCOPS) 22 | export(rollDrawdown) 23 | export(rollEconomicMax) 24 | export(table.Penance) 25 | export(table.PSR) 26 | export(TuW) 27 | useDynLib(noniid.pm) 28 | -------------------------------------------------------------------------------- /sandbox/pulkit/R/capm_aorda.R: -------------------------------------------------------------------------------- 1 | #' @name capm_aorda 2 | #' @title Data to test Cdar and other related functions 3 | #' @description This data set will be used to validate the results of the paper 4 | #' @docType data 5 | #' @usage capm_aorda 6 | NULL 7 | -------------------------------------------------------------------------------- /sandbox/pulkit/R/chart.SharpeEfficient.R: -------------------------------------------------------------------------------- 1 | chart.SharpeEfficientFrontier<-function(R){ 2 | 3 | x = checkData(R) 4 | x = na.omit(x) 5 | columns = ncol(x) 6 | weights<-matrix(ncol=ncol(x)) 7 | for(i in 1:20000){ 8 | weights<-rbind(weights,sample(1:ncol(x))/ncol(x)) 9 | } 10 | y_axis<-NULL 11 | x_axis<-NULL 12 | print(weights) 13 | for(i in 1:20000){ 14 | x_portfolio = Return.portfolio(x,weights[i,]) 15 | print(x_portfolio) 16 | sr<-SharpeRatio(x_portfolio,FUN="StdDev") 17 | sk<-skewness(x_portfolio) 18 | kr<-kurtosis(x_portfolio) 19 | sd<-StdDev(x_portfolio) 20 | sigma_sr<-((1-sk*sr+(sr^2)*(kr-1)/4)/(length(x_portfolio)-1))^0.5 21 | y_axis<-c(y_axis,as.vector(sr)) 22 | x_axis<-c(x_axis,as.vector(sigma_sr)) 23 | } 24 | plot(x_axis,y_axis) 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /sandbox/pulkit/R/na.skip.R: -------------------------------------------------------------------------------- 1 | na.skip <- function (x, FUN=NULL, ...) # maybe add a trim capability? 2 | { # @author Brian Peterson 3 | 4 | # DESCRIPTION: 5 | 6 | # Time series data often contains NA's, either due to missing days, 7 | # noncontiguous series, or merging multiple series, 8 | # 9 | # Some Calulcations, such as return calculations, require data that 10 | # looks like a vector, and needs the output of na.omit 11 | # 12 | # It is often convenient to apply these vector-like functions, but 13 | # you still need to keep track of the structure of the oridginal data. 14 | 15 | # Inputs 16 | # x the time series to apply FUN too 17 | # FUN function to apply 18 | # ... any additonal parameters to FUN 19 | 20 | # Outputs: 21 | # An xts time series that has the same index and NA's as the data 22 | # passed in, after applying FUN 23 | 24 | nx <- na.omit(x) 25 | fx <- FUN(nx, ... = ...) 26 | if (is.vector(fx)) { 27 | result <- .xts(fx, .index(x), .indexCLASS = indexClass(x)) 28 | } 29 | else { 30 | result <- merge(fx, .xts(, .index(x))) 31 | } 32 | return(result) 33 | } 34 | 35 | ############################################################################### 36 | # R (http://r-project.org/) Econometrics for Performance and Risk Analysis 37 | # 38 | # Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson 39 | # 40 | # This R package is distributed under the terms of the GNU Public License (GPL) 41 | # for full details see the file COPYING 42 | # 43 | # $Id: na.skip.R 1855 2012-01-15 12:57:58Z braverock $ 44 | # 45 | ############################################################################### 46 | -------------------------------------------------------------------------------- /sandbox/pulkit/R/psr_python.R: -------------------------------------------------------------------------------- 1 | #' @name psr_python 2 | #' @title Data to test Probabilistic Sharpe Ratio 3 | #' @description This data set will be used to validate the results of the paper 4 | #' @docType data 5 | #' @usage psr_python 6 | NULL 7 | -------------------------------------------------------------------------------- /sandbox/pulkit/R/ret.R: -------------------------------------------------------------------------------- 1 | #' @name ret 2 | #' @title Return Series to test Rolling Economic Drawdowns 3 | #' @description This data set will be used to validate the results of the paper 4 | #' @docType data 5 | #' @usage ret 6 | NULL 7 | -------------------------------------------------------------------------------- /sandbox/pulkit/data/capm_aorda.csv: -------------------------------------------------------------------------------- 1 | Date;AORDA;Benchmark 2 | 2008-01-01;0.0389;-0.0612 3 | 2008-02-01;0.0713;-0.0348 4 | 2008-03-01;0.0417;-0.006 5 | 2008-04-01;0.0743;0.0475 6 | 2008-05-01;0.0324;0.0107 7 | 2008-06-01;-0.0013;-0.086 8 | 2008-07-01;0.0849;-0.0099 9 | 2008-08-01;-0.0283;0.0122 10 | 2008-09-01;0.2821;-0.0921 11 | 2008-10-01;0.0964;-0.1683 12 | 2008-11-01;0.0055;-0.0748 13 | 2008-12-01;-0.0288;0.0078 14 | 2009-01-01;-0.0078;-0.0857 15 | 2009-02-01;0.0684;-0.1099 16 | 2009-03-01;0.0599;0.0854 17 | 2009-04-01;-0.038;0.0939 18 | 2009-05-01;0.0419;0.0531 19 | 2009-06-01;-0.0489;2e-04 20 | 2009-07-01;-0.1022;0.0741 21 | 2009-08-01;-0.0166;0.0336 22 | 2009-09-01;-0.0884;0.0357 23 | 2009-10-01;-0.0284;-0.0198 24 | 2009-11-01;-0.0103;0.0574 25 | 2009-12-01;-0.0118;0.0178 26 | 2010-01-01;0.0054;-0.037 27 | 2010-02-01;-0.0224;0.0285 28 | 2010-03-01;0.0085;0.0588 29 | 2010-04-01;-0.0294;0.0148 30 | 2010-05-01;0.1343;-0.082 31 | 2010-06-01;0.0779;-0.0539 32 | 2010-07-01;0.0661;0.0688 33 | 2010-08-01;0.0313;-0.0474 34 | 2010-09-01;0.0367;0.0876 35 | 2010-10-01;0.003;0.0369 36 | 2010-11-01;0.0361;-0.0023 37 | 2010-12-01;-0.0042;0.0653 38 | 2011-01-01;0.0346;0.0226 39 | 2011-02-01;-0.0068;0.032 40 | 2011-03-01;-0.03;-0.001 41 | 2011-04-01;-0.0148;0.0285 42 | 2011-05-01;0.0372;-0.0135 43 | 2011-06-01;-0.0358;-0.0183 44 | 2011-07-01;-0.0056;-0.0215 45 | 2011-08-01;0.1628;-0.0568 46 | 2011-09-01;-0.0504;-0.0718 47 | 2011-10-01;-0.0354;0.1077 48 | 2011-11-01;0.0011;-0.0051 49 | 2011-12-01;-0.0204;0.0085 50 | 2012-01-01;-1e-04;0.0436 51 | 2012-02-01;5e-04;0.0406 52 | 2012-03-01;0.0169;0.0313 53 | 2012-04-01;0.029;-0.0075 54 | 2012-05-01;-0.0634;-0.0627 55 | 2012-06-01;0.0684;0.0396 56 | 2012-07-01;-0.0198;0.0126 57 | 2012-08-01;0.0399;0.0198 58 | 2012-09-01;-0.0323;0.0242 59 | 2012-10-01;0.006;-0.0198 60 | 2012-11-01;-0.0074;0.0028 61 | 2012-12-01;-0.0048;0.0071 62 | 2013-01-01;-0.0117;0.0504 63 | 2013-02-01;-0.0173;0.0111 64 | 2013-03-01;0.0174;0.036 65 | 2013-04-01;-0.0367;0.0181 66 | 2013-05-01;0.0117;0.0208 67 | 2013-06-01;0.005;-0.015 68 | 2013-07-01;-0.0046;0.0495 69 | -------------------------------------------------------------------------------- /sandbox/pulkit/data/psr_python.csv: -------------------------------------------------------------------------------- 1 | Code,Mean,StDev,Phi,Sigma,t-Stat(Phi) 2 | HFRIFOF Index,0.005516691,0.016969081,0.35942732,0.015835089,6.246140275 3 | HFRIFWI Index,0.008881851,0.020176781,0.304802238,0.019216682,5.190679363 4 | HFRIEHI Index,0.009858566,0.026444472,0.26510117,0.025498305,4.460055655 5 | HFRIMI Index,0.009527016,0.021496073,0.184350274,0.021127643,3.041856755 6 | HFRIFOFD Index,0.005179518,0.017416384,0.353548291,0.016291569,6.129496094 7 | HFRIDSI Index,0.009621101,0.018800339,0.545792492,0.015753187,10.56122157 8 | HFRIEMNI Index,0.005182009,0.009427888,0.164396537,0.009299616,2.703456292 9 | HFRIFOFC Index,0.004809119,0.011620459,0.455662847,0.01034398,8.302257893 10 | HFRIEDI Index,0.009536151,0.019247216,0.391629021,0.01770981,6.902140563 11 | HFRIMTI Index,0.008528045,0.021556689,-0.0188129,0.021552874,-0.305148009 12 | HFRIFIHY Index,0.007177975,0.017707746,0.483806908,0.015497372,8.972011994 13 | HFRIFI Index,0.006855376,0.012881753,0.505908165,0.011111637,9.587381222 14 | HFRIRVA Index,0.008020951,0.012975483,0.452790992,0.011569158,8.242977673 15 | HFRIMAI Index,0.007142082,0.010437017,0.298219544,0.009962104,5.067023312 16 | HFRICAI Index,0.007122016,0.019973858,0.578004656,0.016299336,11.48654001 17 | HFRIEM Index,0.010352034,0.041000178,0.359277175,0.038262633,6.243082394 18 | HFRIEMA Index,0.007989882,0.038243416,0.311226738,0.036344083,5.310865179 19 | HFRISHSE Index,-0.001675503,0.053512968,0.090737496,0.053292219,1.477615589 20 | HFRIEMLA Index,0.011074013,0.05084986,0.196931418,0.04985408,3.257468873 21 | HFRIFOFS Index,0.006834983,0.024799788,0.323053217,0.023470043,5.536016371 22 | HFRIENHI Index,0.010092318,0.036682513,0.201118844,0.035932974,3.329910279 23 | HFRIFWIG Index,0.009382896,0.035972197,0.231372973,0.034996096,3.857301725 24 | HFRIFOFM Index,0.005607926,0.015907089,0.042154535,0.015892949,0.684239764 25 | HFRIFWIC Index,0.008947104,0.039009601,0.050499002,0.038959829,0.820004462 26 | HFRIFWIJ Index,0.008423965,0.03629762,0.0953987,0.036132072,1.554206093 27 | HFRISTI Index,0.011075118,0.046441033,0.160831261,0.04583646,2.642789417 28 | -------------------------------------------------------------------------------- /sandbox/pulkit/inst/doc/ProbSharpe.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/pulkit/inst/doc/ProbSharpe.pdf -------------------------------------------------------------------------------- /sandbox/pulkit/man/BenchmarkSR.Rd: -------------------------------------------------------------------------------- 1 | \name{BenchmarkSR} 2 | \alias{BenchmarkSR} 3 | \title{Benchmark Sharpe Ratio} 4 | \usage{ 5 | BenchmarkSR(R) 6 | } 7 | \arguments{ 8 | \item{R}{a vector, matrix, data frame,timeseries or zoo 9 | object of asset returns} 10 | } 11 | \description{ 12 | The benchmark SR is a linear function of the average 13 | annualized SR of the individual strategies, and a 14 | decreasing convex function of the number of strategies 15 | and the average pairwise correlation. The Returns are 16 | given as the input with the benchmark Sharpe Ratio as the 17 | output. 18 | 19 | \deqn{SR_B = \bar{SR}\sqrt{\frac{S}{1+(S-1)\bar{\rho}}}} 20 | 21 | Here \eqn{\bar{SR}} is the average annualized Sharpe 22 | Ratio of the portfolio and \eqn{\bar{\rho}} is the 23 | average correlation across off-diagonal elements. 24 | } 25 | \examples{ 26 | data(edhec) 27 | BenchmarkSR(edhec) #expected 0.393797 28 | data(managers) 29 | BenchmarkSR(managers) # expected 0.8110536 30 | } 31 | \author{ 32 | Pulkit Mehrotra 33 | } 34 | \references{ 35 | Bailey, David H. and Lopez de Prado, Marcos, The Strategy 36 | Approval Decision: A Sharpe Ratio Indifference Curve 37 | Approach (January 2013). Algorithmic Finance, Vol. 2, No. 38 | 1 (2013). 39 | } 40 | 41 | -------------------------------------------------------------------------------- /sandbox/pulkit/man/CDaR.Rd: -------------------------------------------------------------------------------- 1 | \name{CDaR} 2 | \alias{CDaR} 3 | \alias{CDD} 4 | \title{Calculate Uryasev's proposed Conditional Drawdown at Risk (CDD or CDaR) 5 | measure} 6 | \usage{ 7 | CDaR(R, weights = NULL, geometric = TRUE, invert = TRUE, 8 | p = 0.95, ...) 9 | } 10 | \arguments{ 11 | \item{R}{an xts, vector, matrix, data frame, timeSeries 12 | or zoo object of asset returns} 13 | 14 | \item{weights}{portfolio weighting vector, default NULL, 15 | see Details} 16 | 17 | \item{geometric}{utilize geometric chaining (TRUE) or 18 | simple/arithmetic chaining (FALSE) to aggregate returns, 19 | default TRUE} 20 | 21 | \item{invert}{TRUE/FALSE whether to invert the drawdown 22 | measure. see Details.} 23 | 24 | \item{p}{confidence level for calculation, default 25 | p=0.95} 26 | 27 | \item{\dots}{any other passthru parameters} 28 | } 29 | \description{ 30 | For some confidence level \eqn{p}, the conditional 31 | drawdown is the the mean of the worst \eqn{p\%} 32 | drawdowns. 33 | } 34 | \examples{ 35 | library(lpSolve) 36 | data(edhec) 37 | t(round(CDaR(edhec),4)) 38 | } 39 | \author{ 40 | Brian G. Peterson 41 | } 42 | \references{ 43 | Chekhlov, A., Uryasev, S., and M. Zabarankin. Portfolio 44 | Optimization With Drawdown Constraints. B. Scherer (Ed.) 45 | Asset and Liability Management Tools, Risk Books, London, 46 | 2003 http://www.ise.ufl.edu/uryasev/drawdown.pdf 47 | } 48 | \seealso{ 49 | \code{\link{ES}} \code{\link{maxDrawdown}} 50 | \code{\link{CdarMultiPath}} \code{\link{AlphaDrawdown}} 51 | \code{\link{MultiBetaDrawdown}} 52 | \code{\link{BetaDrawdown}} 53 | } 54 | \keyword{distribution} 55 | \keyword{models} 56 | \keyword{multivariate} 57 | \keyword{ts} 58 | 59 | -------------------------------------------------------------------------------- /sandbox/pulkit/man/EDDCOPS.Rd: -------------------------------------------------------------------------------- 1 | \name{EDDCOPS} 2 | \alias{EDDCOPS} 3 | \title{Economic Drawdown Controlled Optimal Portfolio Strategy} 4 | \usage{ 5 | EDDCOPS(R, delta, gamma, Rf, geometric = TRUE, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeSeries 9 | or zoo object of asset returns} 10 | 11 | \item{delta}{Drawdown limit} 12 | 13 | \item{gamma}{(1-gamma) is the investor risk aversion else 14 | the return series will be used} 15 | 16 | \item{Rf}{risk free rate can be vector such as government 17 | security rate of return.} 18 | 19 | \item{geometric}{geometric utilize geometric chaining 20 | (TRUE) or simple/arithmetic #'chaining(FALSE) to 21 | aggregate returns, default is TRUE.} 22 | 23 | \item{...}{any other variable} 24 | } 25 | \description{ 26 | The Economic Drawdown Controlled Optimal Portfolio 27 | Strategy(EDD-COPS) has the portfolio fraction allocated 28 | to single risky asset as: \deqn{x_t = 29 | Max\left\{0,\biggl(\frac{\lambda/\sigma + 30 | 1/2}{1-\delta.\gamma}\biggr).\biggl[\frac{\delta-EDD(t)}{1-EDD(t)}\biggr]\right\}} 31 | 32 | The risk free asset accounts for the rest of the 33 | portfolio allocation \eqn{x_f = 1 - x_t}. 34 | dt<-read.zoo("../data/ret.csv",sep=",",header = TRUE) 35 | } 36 | \examples{ 37 | # with S&P 500 data and T-bill data 38 | data(ret) 39 | dt<-as.xts(read.zoo(ret)) 40 | EDDCOPS(dt[,1],delta = 0.33,gamma = 0.7,Rf = (1+dt[,2])^(1/12)-1,geometric = TRUE) 41 | 42 | data(edhec) 43 | EDDCOPS(edhec,delta = 0.1,gamma = 0.7,Rf = 0) 44 | } 45 | \author{ 46 | Pulkit Mehrotra 47 | } 48 | \references{ 49 | Yang, Z. George and Zhong, Liang, Optimal Portfolio 50 | Strategy to Control Maximum Drawdown - The Case of Risk 51 | Based Dynamic Asset Allocation (February 25, 2012) 52 | } 53 | \seealso{ 54 | \code{\link{chart.REDD}} \code{\link{EconomicDrawdown}} 55 | \code{\link{rollDrawdown}} \code{\link{REDDCOPS}} 56 | \code{\link{rollEconomicMax}} 57 | } 58 | 59 | -------------------------------------------------------------------------------- /sandbox/pulkit/man/EconomicDrawdown.Rd: -------------------------------------------------------------------------------- 1 | \name{EconomicDrawdown} 2 | \alias{EconomicDrawdown} 3 | \title{Calculate the Economic Drawdown} 4 | \usage{ 5 | EconomicDrawdown(R, Rf, geometric = TRUE, ...) 6 | } 7 | \arguments{ 8 | \item{R}{an xts, vector, matrix, data frame, timeseries, 9 | or zoo object of asset return.} 10 | 11 | \item{Rf}{risk free rate can be vector such as government 12 | security rate of return} 13 | 14 | \item{geometric}{utilize geometric chaining (TRUE) or 15 | simple/arithmetic chaining(FALSE) to aggregate returns, 16 | default is TRUE} 17 | 18 | \item{\dots}{any other variable} 19 | } 20 | \description{ 21 | \code{EconomicDrawdown} calculates the Economic 22 | Drawdown(EDD) for a return series.To calculate the 23 | economic drawdown cumulative return and economic max is 24 | calculated for each point. The risk free return(rf) is 25 | taken as the input. 26 | 27 | Economic Drawdown is given by the equation 28 | 29 | \deqn{EDD(t)=1-\frac{W_t}/{EM(t)}} 30 | 31 | Here EM stands for Economic Max. 32 | } 33 | \examples{ 34 | data(edhec) 35 | EconomicDrawdown(edhec,0.08,100) 36 | } 37 | \author{ 38 | Pulkit Mehrotra 39 | } 40 | \references{ 41 | Yang, Z. George and Zhong, Liang, Optimal Portfolio 42 | Strategy to Control Maximum Drawdown - The Case of Risk 43 | Based Dynamic Asset Allocation (February 25, 2012) 44 | } 45 | \seealso{ 46 | \code{\link{chart.REDD}} \code{\link{EDDCOPS}} 47 | \code{\link{rollDrawdown}} \code{\link{REDDCOPS}} 48 | \code{\link{rollEconomicMax}} 49 | } 50 | 51 | -------------------------------------------------------------------------------- /sandbox/pulkit/man/MonteSimulTriplePenance.Rd: -------------------------------------------------------------------------------- 1 | \name{MonteSimulTriplePenance} 2 | \alias{MonteSimulTriplePenance} 3 | \title{Monte Carlo Simulation for the Triple Penance Rule} 4 | \usage{ 5 | MonteSimulTriplePenance(size, phi, mu, sigma, dp0, bets, 6 | confidence) 7 | } 8 | \arguments{ 9 | \item{size}{size of the Monte Carlo experiment} 10 | 11 | \item{phi}{AR(1) coefficient} 12 | 13 | \item{mu}{unconditional mean} 14 | 15 | \item{sigma}{Standard deviation of the random shock} 16 | 17 | \item{dp0}{Bet at origin (initialization of AR(1))} 18 | 19 | \item{bets}{Number of bets in the cumulative process} 20 | 21 | \item{confidence}{Confidence level for quantile} 22 | } 23 | \description{ 24 | The following process is simulated using the monte carlo 25 | process and the maximum drawdown is calculated using it. 26 | \deqn{\triangle{\pi_{\tau}}=(1-\phi)\mu + 27 | \phi{\delta_{\tau-1}} + \sigma{\epsilon_{\tau}}} 28 | 29 | The random shocks are iid distributed 30 | \eqn{\epsilon_{\tau}~N(0,1)}. These random shocks follow 31 | an independent and identically distributed Gaussian 32 | Process, however \eqn{\triangle{\pi_\tau}} is neither an 33 | independent nor an identically distributed Gaussian 34 | Process. This is due to the parameter \eqn{\phi}, which 35 | incorporates a first-order serial-correlation effect of 36 | auto-regressive form. 37 | } 38 | \examples{ 39 | MonteSimulTriplePenance(10^6,0.5,1,2,1,25,0.95) # Expected Value Quantile (Exact) = 6.781592 40 | } 41 | \author{ 42 | Pulkit Mehrotra 43 | } 44 | \references{ 45 | Bailey, David H. and Lopez de Prado, Marcos, 46 | Drawdown-Based Stop-Outs and the "Triple Penance" 47 | Rule(January 1, 2013). 48 | } 49 | 50 | -------------------------------------------------------------------------------- /sandbox/pulkit/man/Penance.Rd: -------------------------------------------------------------------------------- 1 | \name{Penance} 2 | \alias{Penance} 3 | \title{Penance} 4 | \usage{ 5 | Penance(R, confidence = 0.95, type = c("ar", "normal"), 6 | ...) 7 | } 8 | \arguments{ 9 | \item{R}{Returns} 10 | 11 | \item{confidence}{the confidence interval} 12 | 13 | \item{type}{The type of distribution "normal" or 14 | "ar"."ar" stands for Autoregressive.} 15 | 16 | \item{\dots}{any other passthru variable} 17 | } 18 | \description{ 19 | A plot for Penance vs phi for the given portfolio The 20 | relationship between penance and phi is given by 21 | 22 | \deqn{penance = \frac{Maximum Time under 23 | water}{t_\alpha^{*}-1}} 24 | 25 | Penance Measures how long it takes to recover from the 26 | maximum drawdown as a multiple of the time it took to 27 | reach the bottom. Penance is smaller, the higher the 28 | value of \eqn{\phi(Phi)} and the higher the ratio 29 | \eqn{\frac{\mu}{\sigma}}. Positive serial autocorrelation 30 | leads to smaller Penance due to greater periods under 31 | water. 32 | } 33 | \examples{ 34 | data(edhec) 35 | Penance(edhec,0.95,"ar") 36 | Penance(edhec[,1],0.95,"normal") 37 | } 38 | \author{ 39 | Pulkit Mehrotra 40 | } 41 | \references{ 42 | Bailey, David H. and Lopez de Prado, Marcos, 43 | Drawdown-Based Stop-Outs and the "Triple Penance" 44 | Rule(January 1, 2013). 45 | } 46 | \seealso{ 47 | \code{\link{chart.Penance}} \code{\link{table.Penance}} 48 | \code{\link{TuW}} 49 | } 50 | 51 | -------------------------------------------------------------------------------- /sandbox/pulkit/man/capm_aorda.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{capm_aorda} 3 | \alias{capm_aorda} 4 | \title{Data to test Cdar and other related functions} 5 | \description{ 6 | This data set will be used to validate the results of the 7 | paper 8 | } 9 | \keyword{datasets} 10 | 11 | -------------------------------------------------------------------------------- /sandbox/pulkit/man/chart.REDD.Rd: -------------------------------------------------------------------------------- 1 | \name{chart.REDD} 2 | \alias{chart.REDD} 3 | \title{Time series of Rolling Economic Drawdown} 4 | \usage{ 5 | chart.REDD(R, rf, h, geometric = TRUE, legend.loc = NULL, 6 | colorset = (1:12), ...) 7 | } 8 | \arguments{ 9 | \item{R}{an xts, vector, matrix, data frame, timeseries, 10 | or zoo object of asset return.} 11 | 12 | \item{rf}{risk free rate can be vector such as government 13 | security rate of return} 14 | 15 | \item{h}{lookback period} 16 | 17 | \item{geometric}{utilize geometric chaining (TRUE) or 18 | simple/arithmetic chaining(FALSE) to aggregate returns, 19 | default is TRUE.} 20 | 21 | \item{legend.loc}{set the legend.loc, as in 22 | \code{\link{plot}}} 23 | 24 | \item{colorset}{set the colorset label, as in 25 | \code{\link{plot}}} 26 | 27 | \item{\dots}{any other variable} 28 | } 29 | \description{ 30 | This function plots the time series of Rolling Economic 31 | Drawdown. For more details on rolling economic drawdown 32 | see \code{rollDrawdown}. 33 | } 34 | \examples{ 35 | data(edhec) 36 | chart.REDD(edhec,0.08,20) 37 | } 38 | \author{ 39 | Pulkit Mehrotra 40 | } 41 | \references{ 42 | Yang, Z. George and Zhong, Liang, Optimal Portfolio 43 | Strategy to Control Maximum Drawdown - The Case of Risk 44 | Based Dynamic Asset Allocation (February 25, 2012) 45 | } 46 | \seealso{ 47 | \code{\link{plot}} \code{\link{EconomicDrawdown}} 48 | \code{\link{EDDCOPS}} \code{\link{rollDrawdown}} 49 | \code{\link{REDDCOPS}} \code{\link{rollEconomicMax}} 50 | } 51 | 52 | -------------------------------------------------------------------------------- /sandbox/pulkit/man/golden_section.Rd: -------------------------------------------------------------------------------- 1 | \name{golden_section} 2 | \alias{golden_section} 3 | \title{Golden Section Algorithm} 4 | \usage{ 5 | golden_section(a, b, function_name, minimum = TRUE, ...) 6 | } 7 | \arguments{ 8 | \item{a}{initial point} 9 | 10 | \item{b}{final point} 11 | 12 | \item{minimum}{TRUE to calculate the minimum and FALSE to 13 | calculate the Maximum} 14 | 15 | \item{function_name}{The name of the function} 16 | 17 | \item{\dots}{any other passthru variable} 18 | } 19 | \description{ 20 | The Golden Section Search method is used to find the 21 | maximum or minimum of a unimodal [a,b].) To make the 22 | discussion of the method simpler, let us assume that we 23 | are trying to find the maximum of a function. choose 24 | three points \eqn{x_l},\eqn{x_1} and \eqn{x_u} \eqn{(x_l 25 | < x_1 < x_u)} along the x-axis with the corresponding 26 | values of the function \eqn{f(x_l)},\eqn{f(x_1)} and 27 | \eqn{f(x_u)}, respectively. Since \eqn{f(x_1)< f(x_l)} 28 | and \eqn{f(x_1)< f(x_u)}, the maximum must lie between 29 | \eqn{x_l} and \eqn{x_u}. Now a fourth point denoted by 30 | \eqn{x_2} is chosen to be between the larger of the two 31 | intervals of \eqn{[x_l,x_1]} and \eqn{[x_1,x_u]}/ 32 | Assuming that the interval \eqn{[x_l,x_1]} is larger than 33 | the interval \eqn{[x_1,x_u]} we would choose 34 | \eqn{[x_l,x_1]} as the interval in which \eqn{x_2} is 35 | chosen. If \eqn{f(x_2)>f(x_1)} then the new three points 36 | would be \eqn{x_l > x_2 > x_u} else if 37 | \eqn{f(x_2) 2 | #include 3 | #include 4 | 5 | 6 | void gpdlik(double *data, int *n, double *loc, double *scale, 7 | double *shape, double *dns) 8 | { 9 | int i; 10 | double *dvec; 11 | 12 | dvec = (double *)R_alloc(*n, sizeof(double)); 13 | 14 | if(*scale <= 0) { 15 | *dns = -1e6; 16 | return; 17 | } 18 | 19 | for(i=0;i<*n;i++) { 20 | data[i] = (data[i] - loc[i]) / *scale; 21 | if (data[i] <= 0) { 22 | *dns = -1e6; 23 | return; 24 | } 25 | if(fabs(*shape) <= 1e-6){ 26 | *shape = 0; 27 | dvec[i] = -log(*scale) - data[i]; 28 | } 29 | else { 30 | data[i] = 1 + *shape * data[i]; 31 | if(data[i] <= 0) { 32 | *dns = -1e6; 33 | return; 34 | } 35 | dvec[i] = -log(*scale) - (1 / *shape + 1) * log(data[i]); 36 | } 37 | } 38 | 39 | for(i=0;i<*n;i++) 40 | *dns = *dns + dvec[i]; 41 | } 42 | -------------------------------------------------------------------------------- /sandbox/pulkit/src/moment.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | SEXP sums(SEXP mat,SEXP index,SEXP Rmean,SEXP dOrder,SEXP Rweights,SEXP mOrder,SEXP sum){ 6 | double x1,x2,diff; 7 | int a,b,row,column; 8 | SEXP Rdim = getAttrib(mat,R_DimSymbol); 9 | row = INTEGER(Rdim)[0]; 10 | column = INTEGER(Rdim)[1]; 11 | mat = coerceVector(mat,REALSXP); 12 | dOrder = coerceVector(dOrder,INTSXP); 13 | mOrder = coerceVector(mOrder,INTSXP); 14 | index = coerceVector(index,INTSXP); 15 | int ind = INTEGER(index)[0]; 16 | int d = INTEGER(dOrder)[0]; 17 | int m = INTEGER(mOrder)[0]; 18 | double *mean = REAL(Rmean); 19 | double *weights = REAL(Rweights); 20 | double s = 0; 21 | for(a = 0;a 5 | import DD2,DD3 # These are the two modules in Appendices 9 and 10 6 | #--------------------------------------------------------------- 7 | def isNumber(input): 8 | # Determines whether input is a number 9 | try: 10 | float(input) 11 | return True 12 | except: 13 | return False 14 | #--------------------------------------------------------------- 15 | def main(): 16 | #1) Parameters 17 | path='' 18 | inFileName='data1.csv' 19 | outFileName='Results1.csv' 20 | fields=['Code','Mean','Phi','Sigma'] 21 | confidence=.95 22 | dPi0=0 23 | #2) Read file 24 | inFile=open(path+inFileName,'r') 25 | outFile=open(path+outFileName,'w') 26 | headers=inFile.readline().split(',') 27 | indices=[headers.index(i) for i in fields] 28 | for line in inFile: 29 | #3) Get Input 30 | params={} 31 | line=line[:-1].split(',') 32 | for i in indices: 33 | if isNumber(line[i])==True: 34 | params[headers[i]]=float(line[i]) 35 | else: 36 | params[headers[i]]=line[i] 37 | #4) Compute MaxDD,MaxTuW 38 | if params['Mean']>0 and params['Phi']>=0: 39 | t,minQ=DD2.getMinQ(params['Phi'],params['Mean'],params['Sigma'],dPi0,confidence) 40 | maxDD=max(0,-minQ) 41 | maxTuW=DD3.getTuW(params['Phi'],params['Mean'],params['Sigma'],dPi0,confidence) 42 | else: 43 | maxDD,t,maxTuW='--','--','--' 44 | #5) Store result 45 | msg=params['Code']+','+str(maxDD)+','+str(t)+','+str(maxTuW) 46 | outFile.writelines(msg+'\n') 47 | print msg 48 | return 49 | #--------------------------------------------------------------- 50 | # Boilerplate 51 | if __name__=='__main__':main() 52 | -------------------------------------------------------------------------------- /sandbox/pulkit/week3_4/tests/tests.TriplePenance.R: -------------------------------------------------------------------------------- 1 | library(RUnit) 2 | library(PerformanceAnalytics) 3 | data(edhec) 4 | 5 | test_MaxDD<-function(){ 6 | checkEqualsNumeric(MaxDD(edhec[,1],0.95,"normal"),6.618966,tolerance = 1.0e-6) 7 | } 8 | 9 | test_MinTRL<-function(){ 10 | checkEqualsNumeric(TuW(edhec[,1],0.95,"normal"),103.2573,tolerance = 1.0e-3) 11 | } 12 | -------------------------------------------------------------------------------- /sandbox/pulkit/week3_4/vignette/TriplePenance.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/pulkit/week3_4/vignette/TriplePenance.pdf -------------------------------------------------------------------------------- /sandbox/pulkit/week5/REDDCOPS.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/sandbox/pulkit/week5/REDDCOPS.pdf -------------------------------------------------------------------------------- /sandbox/test_Return.rebalancing.R: -------------------------------------------------------------------------------- 1 | library(PerformanceAnalytics) 2 | data(edhec) 3 | R <- edhec["1997",1:5] 4 | colnames(R) <- c("CA", "CTA", "Distr", "EM", "EMN") 5 | 6 | # Note: I verified these results by semi-random spot checks with the 7 | # spreadsheet calculations. Will add more comprehensive tests as time permits. 8 | 9 | # Case 1: User inputs returns only 10 | # Equally weighted portfolio with no rebalancing 11 | out1 <- Return.rebalancing3(R) 12 | 13 | 14 | # Case 2: User input weights with no rebalancing 15 | out2 <- Return.rebalancing3(R, weights=c(0, 0.2, 0.4, 0.1, 0.3), 16 | verbose=TRUE) 17 | 18 | 19 | # Case 3: User input weights and rebalancing frequency 20 | out3 <- Return.rebalancing3(R, weights=c(0, 0.2, 0.4, 0.1, 0.3), 21 | rebalance_on="quarters") 22 | 23 | # Case 4: User input xts object for weights 24 | rebal_dates <- c("1996-12-31", "1997-03-31", "1997-06-30", "1997-09-30") 25 | weights <- xts(matrix(1/ncol(R), nrow=length(rebal_dates), ncol=ncol(R)), 26 | as.Date(rebal_dates)) 27 | out4 <- Return.rebalancing3(R, weights, value=5, verbose=TRUE) 28 | all.equal(rowSums(out4$contribution), as.numeric(out4$returns)) 29 | 30 | out4a <- Return.rebalancing3(R, rebalance_on="quarters", value=5, verbose=TRUE) 31 | all.equal(out4, out4a) 32 | 33 | # out4 and out4a should match Peter's spreadsheet exactly 34 | 35 | # Weights that start after first observation in returns 36 | rebal_dates <- c("1997-03-31", "1997-06-30", "1997-09-30") 37 | weights <- xts(matrix(1/ncol(R), nrow=length(rebal_dates), ncol=ncol(R)), as.Date(rebal_dates)) 38 | out4b <- Return.rebalancing3(R, weights) 39 | 40 | # Case 5: Equally weighted portfolio with monthly rebalancing 41 | out5 <- Return.rebalancing3(R, rebalance_on="months", value=1) 42 | 43 | -------------------------------------------------------------------------------- /vignettes/PA-Bacon.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/vignettes/PA-Bacon.pdf -------------------------------------------------------------------------------- /vignettes/PA-charts.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/vignettes/PA-charts.pdf -------------------------------------------------------------------------------- /vignettes/PerformanceAnalyticsChartsPresentation-Meielisalp-2007.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/vignettes/PerformanceAnalyticsChartsPresentation-Meielisalp-2007.pdf -------------------------------------------------------------------------------- /vignettes/PerformanceAnalyticsGraphicalExamples.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/vignettes/PerformanceAnalyticsGraphicalExamples.pdf -------------------------------------------------------------------------------- /vignettes/PerformanceAnalyticsPresentation-UseR-2007.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/vignettes/PerformanceAnalyticsPresentation-UseR-2007.pdf -------------------------------------------------------------------------------- /vignettes/Rlogo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/vignettes/Rlogo.jpg -------------------------------------------------------------------------------- /vignettes/textplotPresentation-CRUG-2011.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/R-Finance/PerformanceAnalytics/6e32fa7d55b45d32941b5c3fd4579d316b04fe9e/vignettes/textplotPresentation-CRUG-2011.pdf --------------------------------------------------------------------------------