Path: blob/master/sandbox/RFinance2014/presentation.Rmd
1433 views
------Overview
Discuss Portfolio Optimization
Introduce PortfolioAnalytics
Demonstrate PortfolioAnalytics with Examples
Modern Portfolio Theory
"Modern" Portfolio Theory (MPT) was introduced by Harry Markowitz in 1952.
In general, MPT states that an investor's objective is to maximize portfolio expected return for a given amount of risk.
General Objectives
Maximize a measure of gain per unit measure of risk
Minimize a measure of risk
How do we define risk? What about more complex objectives and constraints?
Portfolio Optimization Objectives
Minimize Risk
Volatility
Tail Loss (VaR, ES)
Other Downside Risk Measure
Maximize Risk Adjusted Return
Sharpe Ratio, Modified Sharpe Ratio
Several Others
Risk Budgets
Equal Component Contribution to Risk (i.e. Risk Parity)
Limits on Component Contribution
Maximize a Utility Function
Quadratic, CRRA, etc.
PortfolioAnalytics Overview
PortfolioAnalytics is an R package designed to provide numerical solutions and visualizations for portfolio optimization problems with complex constraints and objectives.
Support for multiple constraint and objective types
An objective function can be any valid R function
Modular constraints and objectives
Support for user defined moment functions
Visualizations
Solver agnostic
Support for parallel computing
Support Multiple Solvers
Linear and Quadratic Programming Solvers
R Optimization Infrastructure (ROI)
GLPK (Rglpk)
Symphony (Rsymphony)
Quadprog (quadprog)
Global (stochastic or continuous solvers)
Random Portfolios
Differential Evolution (DEoptim)
Particle Swarm Optimization (pso)
Generalized Simulated Annealing (GenSA)
Random Portfolios
PortfolioAnalytics has three methods to generate random portfolios.
The sample method to generate random portfolios is based on an idea by Pat Burns.
The simplex method to generate random portfolios is based on a paper by W. T. Shaw.
The grid method to generate random portfolios is based on the
gridSearchfunction in the NMOF package.
Comparison of Random Portfolio Methods

Comparison of Random Portfolio Methods (Interactive!)
Random Portfolios: Simplex Method

Workflow: Specify Portfolio
Initializes the portfolio object that holds portfolio level data, constraints, and objectives
Workflow: Add Constraints
Supported Constraint Types
Sum of Weights
Box
Group
Factor Exposure
Position Limit
and many more
Workflow: Add Objectives
Supported Objective types
Return
Risk
Risk Budget
Weight Concentration
Workflow: Run Optimization
Workflow: Analyze Results
| Visualization | Data Extraction |
|---|---|
| plot | extractObjectiveMeasures |
| chart.Concentration | extractStats |
| chart.EfficientFrontier | extractWeights |
| chart.RiskReward | |
| chart.RiskBudget | summary |
| chart.Weights |
Stock Data Setup
Here we will look at portfolio optimization in the context of stocks.
Selection of large cap, mid cap, and small cap stocks from CRSP data
Weekly data from 1/7/1997 to 12/28/2010
15 Large Cap
15 Mid Cap
5 Small Cap
Distribution of Monthly Returns

Example 1: Market Neutral Portfolio
Here we consider a portfolio of stocks. Our objective is to maximize portfolio return with a target of 0.0015 and minimize portfolio StdDev with a target of 0.02 subject to dollar neutral, beta, box, and position limit constraints.
Specify Portfolio: Constraints
Specify Portfolio: Objectives
Run Optimization
Plot Results

EDHEC Data Setup
Here we will look at portfolio optimization in the context of portfolio of hedge funds.
EDHEC-Risk Alternative Indexes monthly returns from 1/31/1997 to 1/31/2014
| Relative Value | Directional |
|---|---|
| Convertible Arbitrage (CA) | CTA Global (CTAG) |
| Equity Market Neutral (EMN) | Emerging Markets (EM) |
| Fixed Income Arbitrage (FIA) | Global Macro (GM) |
Monthly Returns

Example 2: Minimum Expected Shortfall
Consider an allocation to hedge funds using the EDHEC-Risk Alternative Index as a proxy. This will be an extended example starting with an objective to minimize modified expected shortfall, then add risk budget percent contribution limit, and finally add equal risk contribution limit.
Minimize Modified Expected Shortfall
Minimize Modified Expected Shortfall with Risk Budget Limit
Minimize Modified Expected Shortfall with Equal Risk Contribution
Specify Initial Portfolio
Add Objectives
Run Optimization
Plot in Risk-Return Space

Chart Risk Budgets

Set Rebalancing Parameters and Run Backtest
Min ES Risk Contributions and Weights Through Time

Min ES Risk Budget Limit Risk Contributions and Weights Through Time

Min ES Equal Component Contribution Risk Contributions and Weights Through Time

--- &twocol
Min ES Equal Component Contribution Risk Contributions and Weights (interactive!)
*** =left
Percent Contribution to Risk
*** =right
Weights
Compute Returns
Chart Performance

Example 3: Maximize CRRA
Consider an allocation to hedge funds using the EDHEC-Risk Alternative Index as a proxy. Our objective to maximize the fourth order expansion of the Constant Relative Risk Aversion (CRRA) expected utility function as in the Boudt paper and Martellini paper. We use the same data as Example 3.
Define a function to compute CRRA
Define a custom moment function
The default function for momentFUN is set.portfolio.moments. We need to write our own function to estimate the moments for our objective function.
Specify Portfolio
"Dummy" Objectives
Run Optimization
Chart Results

Run Backtest and Compute Returns
Chart Weights Through Time

Chart Performance

Conclusion
Introduced the goals and summary of PortfolioAnalytics
Demonstrated the flexibility through examples
Exciting plans for GSOC 2014
Support for regime switching
Support for supervised learning
many more
Acknowledgements
Many thanks to...
Google: funding for Google Summer of Code (GSoC)
UW CF&RM Program: continued work on PortfolioAnalytics
GSoC Mentors: Brian Peterson, Peter Carl, Doug Martin, and Guy Yollin
R/Finance Committee
PortfolioAnalytics Links
PortfolioAnalytics is on R-Forge in the ReturnAnalytics project
Source code for the slides
and view it here
Any Questions?
References and Useful Links
Martellini paper
Boudt paper