[Returnanalytics-commits] r2050 - pkg/PortfolioAnalytics/sandbox
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jun 23 04:21:09 CEST 2012
Author: hezkyvaron
Date: 2012-06-23 04:21:09 +0200 (Sat, 23 Jun 2012)
New Revision: 2050
Modified:
pkg/PortfolioAnalytics/sandbox/testing_ROI.R
Log:
- sample problem updates
Modified: pkg/PortfolioAnalytics/sandbox/testing_ROI.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/testing_ROI.R 2012-06-23 01:54:09 UTC (rev 2049)
+++ pkg/PortfolioAnalytics/sandbox/testing_ROI.R 2012-06-23 02:21:09 UTC (rev 2050)
@@ -1,7 +1,7 @@
# # # # # # # # # # # # # #
# OPTIMIZATION TESTING
#
-setwd("~/Documents/gsoc_portfolio/tests")
+
library(xts)
library(quantmod)
library(quadprog)
@@ -17,36 +17,11 @@
cov.mat <- var(edhec)
mu.vec <- apply(edhec, 2, mean)
n.assets <- ncol(edhec)
-mu.port <- 0.002
-Amat <- cbind(rep(1,n.assets),mu.vec)
-q.prob <- OP(objective=Q_objective(Q=-2*cov.mat, L=mu.vec),
- constraints=L_constraint(L=t(Amat),
- dir=c("==","=="),
- rhs=c(1,mu.port)),
- maximum=TRUE)
-wts <- ROI_solve(x=q.prob, solver="quadprog")$solution
-# Comparing resutls wtih Guy's slides of PortfolioOptimization
-# sllide number 24/70, mean-variance optimization
-# subject to fully-invested and expected portfolio return constraints
-data(CRSPday)
-R <- 100*CRSPday[,4:6]
-mean_vect <- apply(R,2,mean)
-cov_mat <- var(R)
-Amat <- rbind(rep(1,3),mean_vect)
-mu.port <- 0.1
-q.prob <- OP(objective=Q_objective(Q=2*cov_mat, L=rep(0,3)),
- constraints=L_constraint(L=Amat,
- dir=c("==","=="),
- rhs=c(1, mu.port)))
-wts <- ROI_solve(x=q.prob, solver="quadprog")$solution
-# this returuns a long-only portfolio, error within ROI
-
-
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-# Sample portfolio optimization problem....
+# Sample portfolio optimization problems....
# =====================
# Arbitrage
@@ -87,3 +62,36 @@
+# =====================
+# Mean-variance
+#
+mu.port <- 0.002
+Amat <- cbind(rep(1,n.assets),mu.vec)
+q.prob <- OP(objective=Q_objective(Q=-2*cov.mat, L=mu.vec),
+ constraints=L_constraint(L=t(Amat),
+ dir=c("==","=="),
+ rhs=c(1,mu.port)),
+ bounds=bnds,
+ maximum=TRUE)
+wts <- ROI_solve(x=q.prob, solver="quadprog")$solution
+
+
+# Comparing resutls wtih Guy's slides of PortfolioOptimization
+# sllide number 24/70, mean-variance optimization
+# subject to fully-invested and expected portfolio return constraints
+data(CRSPday)
+R <- 100*CRSPday[,4:6]
+mean_vect <- apply(R,2,mean)
+cov_mat <- var(R)
+Amat <- rbind(rep(1,3),mean_vect)
+mu.port <- 0.1
+bnds <- list(lower = list(ind = seq.int(1L, as.integer(3)), val = rep(-Inf,3)),
+ upper = list(ind = seq.int(1L, as.integer(3)), val = rep(Inf,3)))
+q.prob <- OP(objective=Q_objective(Q=2*cov_mat, L=rep(0,3)),
+ constraints=L_constraint(L=Amat,
+ dir=c("==","=="),
+ rhs=c(1, mu.port)),
+ bounds=bnds)
+wts <- ROI_solve(x=q.prob, solver="quadprog")$solution
+
+
More information about the Returnanalytics-commits
mailing list