[Returnanalytics-commits] r3360 - in pkg/PortfolioAnalytics/sandbox/RFinance2014: . data_figures optimization_figures optimization_results
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Apr 10 20:42:04 CEST 2014
Author: rossbennett34
Date: 2014-04-10 20:42:03 +0200 (Thu, 10 Apr 2014)
New Revision: 3360
Added:
pkg/PortfolioAnalytics/sandbox/RFinance2014/data_analysis.R
pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/
pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/directional_barvar.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/edhec_box.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/equity_box.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/relative_barvar.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/data_prep.R
Removed:
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/crra_ES.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/crra_RR.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/crra_minES.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/eqrb_minES.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/opt_dn.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/opt_minES.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/rb_minES.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/ret_crra.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/ret_minES.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/ret_minVar.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/risk_minES.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/risk_minESEqRB.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/risk_minESRB.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/weights_minVarLW.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/weights_minVarSample.png
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/bt.opt.crra.rda
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/bt.opt.minES.rda
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/opt.crra.rda
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/opt.dn.rda
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/opt.minES.rda
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/opt.minVarLW.rda
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/opt.minVarSample.rda
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/rp.rda
Modified:
pkg/PortfolioAnalytics/sandbox/RFinance2014/optimize.R
pkg/PortfolioAnalytics/sandbox/RFinance2014/presentation.Rmd
pkg/PortfolioAnalytics/sandbox/RFinance2014/presentation.html
pkg/PortfolioAnalytics/sandbox/RFinance2014/presentation.md
pkg/PortfolioAnalytics/sandbox/RFinance2014/slidy_presentation.html
Log:
updating scripts for presentation
Added: pkg/PortfolioAnalytics/sandbox/RFinance2014/data_analysis.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/RFinance2014/data_analysis.R (rev 0)
+++ pkg/PortfolioAnalytics/sandbox/RFinance2014/data_analysis.R 2014-04-10 18:42:03 UTC (rev 3360)
@@ -0,0 +1,45 @@
+library(PerformanceAnalytics)
+
+source("data_prep.R")
+
+##### Equity Data for Example 1 and Example 2 #####
+colors <- c(rep("blue", 15), rep("green", 15), rep("red", 5))
+sd.order <- order(StdDev(equity.data))
+
+# boxplot to compare return distributions
+# mar(bottom, left, top, right)
+# default: par(mar=c(5, 4, 4, 2) + 0.1)
+png("data_figures/equity_box.png")
+boxplot(coredata(equity.data[,sd.order]),
+ cex.axis=0.8, las=3, ylab="Returns", pch=18,
+ col=colors[sd.order],
+ main="Return Distribution\n(sorted by StdDev)")
+legend("topleft", legend=c("Large Cap", "Mid Cap", "Small Cap"),
+ fill=c("blue", "green", "red"), bty="n", cex=0.8)
+dev.off()
+
+##### edhec Data for Example 3 and Example 4 #####
+p <- 0.95
+
+png("data_figures/relative_barvar.png")
+charts.BarVaR(R[,1:3], width=60, methods=c("ModifiedES", "ModifiedVaR"),
+ main="Relative Value")
+dev.off()
+
+png("data_figures/directional_barvar.png")
+charts.BarVaR(R[,4:6], width=60, methods=c("ModifiedES", "ModifiedVaR"),
+ main="Directional")
+dev.off()
+
+
+colors <- c(rep("lightblue", 3), rep("red", 3))
+ES.order <- order(ES(R, p=p, invert=FALSE))
+
+png("data_figures/edhec_box.png")
+boxplot(coredata(R[,ES.order]),
+ cex.axis=0.8, las=3, ylab="Returns", pch=18,
+ col=colors[ES.order],
+ main="Return Distribution\n(sorted by Modified ES (95%))")
+legend("topleft", legend=c("Relative Value", "Directional"),
+ fill=c("lightblue", "red"), bty="n", cex=0.8)
+dev.off()
Added: pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/directional_barvar.png
===================================================================
(Binary files differ)
Property changes on: pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/directional_barvar.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/edhec_box.png
===================================================================
(Binary files differ)
Property changes on: pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/edhec_box.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/equity_box.png
===================================================================
(Binary files differ)
Property changes on: pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/equity_box.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/relative_barvar.png
===================================================================
(Binary files differ)
Property changes on: pkg/PortfolioAnalytics/sandbox/RFinance2014/data_figures/relative_barvar.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: pkg/PortfolioAnalytics/sandbox/RFinance2014/data_prep.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/RFinance2014/data_prep.R (rev 0)
+++ pkg/PortfolioAnalytics/sandbox/RFinance2014/data_prep.R 2014-04-10 18:42:03 UTC (rev 3360)
@@ -0,0 +1,25 @@
+
+##### Equity Data for Example 1 and Example 2 #####
+load("data/crsp_weekly.rda")
+
+equity.data <- cbind(largecap_weekly[,1:15],
+ midcap_weekly[,1:15],
+ smallcap_weekly[,1:5])
+market <- largecap_weekly[,21]
+Rf <- largecap_weekly[,22]
+
+##### edhec Data for Example 3 and Example 4 #####
+# Load the updated edhec dataset
+load("data/edhec.rda")
+
+# Prep data for Examples 3 and 4
+R <- edhec[,c("Convertible.Arbitrage", "Equity.Market.Neutral",
+ "Fixed.Income.Arbitrage",
+ "CTA.Global", "Emerging.Markets", "Global.Macro")]
+# Abreviate column names for convenience and plotting
+colnames(R) <- c("CA", "EMN", "FIA", "CTAG", "EM", "GM")
+
+
+# clean up and remove the data we don't need
+rm(largecap_weekly, midcap_weekly, smallcap_weekly, microcap_weekly)
+rm(edhec)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/crra_ES.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/crra_RR.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/crra_minES.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/eqrb_minES.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/opt_dn.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/opt_minES.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/rb_minES.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/ret_crra.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/ret_minES.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/ret_minVar.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/risk_minES.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/risk_minESEqRB.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/risk_minESRB.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/weights_minVarLW.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_figures/weights_minVarSample.png
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/bt.opt.crra.rda
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/bt.opt.minES.rda
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/opt.crra.rda
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/opt.dn.rda
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/opt.minES.rda
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/opt.minVarLW.rda
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/opt.minVarSample.rda
===================================================================
(Binary files differ)
Deleted: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimization_results/rp.rda
===================================================================
(Binary files differ)
Modified: pkg/PortfolioAnalytics/sandbox/RFinance2014/optimize.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/RFinance2014/optimize.R 2014-04-09 17:53:27 UTC (rev 3359)
+++ pkg/PortfolioAnalytics/sandbox/RFinance2014/optimize.R 2014-04-10 18:42:03 UTC (rev 3360)
@@ -51,25 +51,12 @@
source("R/lwShrink.R")
# Example 1 and Example 2 will use the crsp_weekly data
-# load the CRSP weekly data
-load("data/crsp_weekly.rda")
-
# Example 3 and Example 4 will use the edhec data
-# Load the updated edhec dataset
-load("data/edhec.rda")
+source("data_prep.R")
-# Prep data for Examples 1 and 2
-# use the first 10 stocks in largecap_weekly, midcap_weekly, and smallcap_weekly
-equity.data <- cbind(largecap_weekly[,1:10],
- midcap_weekly[,1:10],
- smallcap_weekly[,1:10])
-market <- largecap_weekly[,21]
-Rf <- largecap_weekly[,22]
-stocks <- colnames(equity.data)
-
-
##### Example 1 #####
+stocks <- colnames(equity.data)
# Specify an initial portfolio
portf.init <- portfolio.spec(stocks)
# Add constraints
@@ -189,13 +176,6 @@
save(opt.dn, file=paste(results.dir, "opt.dn.rda", sep="/"))
}
-# Prep data for Examples 3 and 4
-# For now, use the first 8
-R <- edhec[,1:8]
-# Abreviate column names for convenience and plotting
-colnames(R) <- c("CA", "CTAG", "DS", "EM", "EQN", "ED", "FA", "GM")
-
-
##### Example 3 #####
# Example 3 will consider three portfolios
# - minES
Modified: pkg/PortfolioAnalytics/sandbox/RFinance2014/presentation.Rmd
===================================================================
--- pkg/PortfolioAnalytics/sandbox/RFinance2014/presentation.Rmd 2014-04-09 17:53:27 UTC (rev 3359)
+++ pkg/PortfolioAnalytics/sandbox/RFinance2014/presentation.Rmd 2014-04-10 18:42:03 UTC (rev 3360)
@@ -108,45 +108,20 @@
Just give a general description of the functions to analyze results
-->
-# Data
+# Example 1
+
## Data Setup
-Here we will look at portfolio optimization in the context of portfolio of hedge funds
+Here we will look at portfolio optimization in the context of stocks.
-* EDHEC-Risk Alternative Indexes
-* Monthly returns from 1/31/1997 to 1/31/2014
- * Convertible Arbitrage (CA)
- * CTA Global (CTAG)
- * Distressed Securities (DS)
- * Emerging Markets (EM)
+* Selection of large cap, mid cap, and small cap stocks from CRSP data
+* 15 Large Cap
+* 15 Mid Cap
+* 5 Small Cap
-
-## Monthly Returns
-```{r, echo=FALSE}
-suppressPackageStartupMessages(library(PortfolioAnalytics))
-load("data/edhec.rda")
-R <- edhec[,1:4]
-colnames(R) <- c("CTAG", "DS", "CA", "EM")
-p <- 0.95
-```
-
-```{r, echo=FALSE, cache=TRUE, fig.height=4.5, fig.cap=""}
-charts.BarVaR(R, width=36, methods=c("ModifiedES", "ModifiedVaR"))
-```
-
## Distribution of Monthly Returns
-```{r, echo=FALSE, message=FALSE, fig.height=4.5, fig.cap=""}
-# par(mar=c(5, 4, 4, 2) + 0.1)
-boxplot(coredata(R[,order(ES(R, p=p, invert=FALSE))]),
- cex.axis=0.8, las=3, ylab="Returns", pch=18,
- main="Return Distribution\n(sorted by Modified ES (95%))")
-# par(mar=c(5, 4, 4, 2) + 0.1)
-# dev.off()
-```
+![alt text](data_figures/equity_box.png)
-
-# Example 1
-
## Minimum Variance Portfolio
Consider a portfolio of stocks. Our objective to minimize portfolio variance subect to full investment and box constraints. We will use out of sample backtesting to compare the sample covariance matrix estimate and a Ledoit-Wolf shinkage estimate.
@@ -156,10 +131,9 @@
## Data
```{r, eval=FALSE}
-load("data/crsp_weekly.rda")
-equity.data <- cbind(largecap_weekly[,1:10],
- midcap_weekly[,1:10],
- smallcap_weekly[,1:10])
+equity.data <- cbind(largecap_weekly[,1:15],
+ midcap_weekly[,1:15],
+ smallcap_weekly[,1:5])
```
## Specify Portfolio
@@ -279,6 +253,28 @@
# Example 3
+## 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
+ * Convertible Arbitrage (CA)
+ * Equity Market Neutral (EMN)
+ * Fixed Income Arbitrage (FIA)
+ * CTA Global (CTAG)
+ * Emerging Markets (EM)
+ * Global Macro (GM)
+
+
+## Monthly Returns
+![alt text](data_figures/relative_barvar.png)
+![alt text](data_figures/directional_barvar.png)
+
+
+## Distribution of Monthly Returns
+![alt text](data_figures/edhec_box.png)
+
+
## 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 portfolio expected shortfall, then risk budget percent contribution limit, then equal risk contribution limit.
* Minimize Expected Shortfall
@@ -289,9 +285,11 @@
## Data
```{r, eval=FALSE}
-R <- edhec[,1:8]
+R <- edhec[,c("Convertible.Arbitrage", "Equity.Market.Neutral",
+ "Fixed.Income.Arbitrage",
+ "CTA.Global", "Emerging.Markets", "Global.Macro")]
# Abreviate column names for convenience and plotting
-colnames(R) <- c("CA", "CTAG", "DS", "EM", "EQN", "ED", "FA", "GM")
+colnames(R) <- c("CA", "EMN", "FIA", "CTAG", "EM", "GM")
```
## Specify Initial Portfolio
Modified: pkg/PortfolioAnalytics/sandbox/RFinance2014/presentation.html
===================================================================
--- pkg/PortfolioAnalytics/sandbox/RFinance2014/presentation.html 2014-04-09 17:53:27 UTC (rev 3359)
+++ pkg/PortfolioAnalytics/sandbox/RFinance2014/presentation.html 2014-04-10 18:42:03 UTC (rev 3360)
@@ -313,34 +313,23 @@
Just give a general description of the functions to analyze results
-->
-<h1>Data</h1>
+<h1>Example 1</h1>
<h2>Data Setup</h2>
-<p>Here we will look at portfolio optimization in the context of portfolio of hedge funds</p>
+<p>Here we will look at portfolio optimization in the context of stocks.</p>
<ul>
-<li>EDHEC-Risk Alternative Indexes</li>
-<li>Monthly returns from 1/31/1997 to 1/31/2014
-
-<ul>
-<li>Convertible Arbitrage (CA)</li>
-<li>CTA Global (CTAG)</li>
-<li>Distressed Securities (DS)</li>
-<li>Emerging Markets (EM)</li>
-</ul></li>
+<li>Selection of large cap, mid cap, and small cap stocks from CRSP data</li>
+<li>15 Large Cap</li>
+<li>15 Mid Cap</li>
+<li>5 Small Cap</li>
</ul>
-<h2>Monthly Returns</h2>
-
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/returnanalytics -r 3360
More information about the Returnanalytics-commits
mailing list