Description Usage Arguments Value Author(s) Examples
quadprog
provides a simple interface to ROI using the optimization
model specification of MatLab(R)
minimize in x: f'*x + 0.5*x'*H*x subject to: A*x <= b Aeq*x == beq x >= lb x <= ub
1 2 |
H |
Quadratic term (matrix) of the objective function |
f |
Linear term (vector) of the objective function |
A |
Inequality constraints (left-hand side) |
b |
Inequality constraints (right-hand side) |
Aeq |
Equality constraints (left-hand side) |
beq |
Equality constraints (right-hand side) |
lb |
Lower bound |
ub |
Upper bound |
x0 |
Initial solution |
options |
Additional optimization parameters |
The solution vector in x
as well as the objective value
in fval
.
Ronald Hochreiter, ron@hochreiter.net
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # Covariance matrix of four stocks (weekly returns from 2011):
#
# AAPL IBM MSFT ORCL
# AAPL 0.0014708114 0.0006940036 0.0006720841 0.0008276391
# IBM 0.0006940036 0.0009643581 0.0006239411 0.0011266429
# MSFT 0.0006720841 0.0006239411 0.0009387707 0.0008728736
# ORCL 0.0008276391 0.0011266429 0.0008728736 0.0021489512
covariance = matrix(c(0.0014708114, 0.0006940036, 0.0006720841, 0.0008276391,
0.0006940036, 0.0009643581, 0.0006239411, 0.0011266429,
0.0006720841, 0.0006239411, 0.0009387707, 0.0008728736,
0.0008276391, 0.0011266429, 0.0008728736, 0.0021489512),
nrow=4, byrow=TRUE)
assets <- dim(covariance)[1]
H <- covariance
f <- rep(0, assets)
Aeq <- rep(1, assets)
beq <- 1
lb <- rep(0, assets)
ub <- rep(1, assets)
solution <- quadprog(H, f, NULL, NULL, Aeq, beq, lb, ub)
portfolio <- solution$x
print(portfolio)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.