Long-Only Minimum-Variance Portfolio Weights with an Equality Constraint
Summary
The document frames a portfolio-weight optimization problem for a variable number of assets. Its objective is portfolio return variance, computed from the asset covariance matrix and the candidate weights. The stated constraints require weights to sum to one, remain nonnegative, and make the two rows of a supplied matrix produce equal weighted sums.
It provides R code for the variance objective and an example dataset assembled from adjusted prices for five equities, transformed into returns. The equality condition is described as exact or approximate within a tolerance, but the document does not identify a particular optimizer or show a solution, so it is a problem specification rather than a complete optimization workflow. The example also leaves practical details such as missing-data handling, return alignment, and how the tolerance should be chosen to the implementer.
Key ideas
- The objective is to minimize variance calculated from a return covariance matrix and portfolio weights.
- Weights are constrained to be nonnegative and to sum to one.
- A matrix-based equality constraint requires the two weighted row sums to match.
- The R function evaluates variance using both individual variances and pairwise covariances.
- The example specifies inputs but does not demonstrate an optimizer or report resulting weights.
Tags
Full text
# Optimal weights for portfolio optimisation (r)
# Optimal weights for portfolio optimisation (r)
The question is what R optimization could be applicable to find a vector of weights that when, multiplied by S matrix creates equal rows sums, and when set in the objective function returns the minimal value. The code will be reused for different number and combination of assets. n = number of assets x = vector of weights per asset (the solution of the optimization X1,…,Xn) #unknown R = matrix of returns for n number of assets S = a given matrix of numbers with 2 rows and n columns Objective: minimize the fun.obj
```
fun.obz <- function(R, x, na.rm = TRUE) {
covmat <- var(R = R, na.rm = na.rm)
utc <- upper.tri(covmat)
wt.var <- sum(diag(covmat) * x^2)
wt.cov <- sum(x[row(covmat)[utc]] *
x[col(covmat)[utc]] *
covmat[utc])
variance <- wt.var + 2 * wt.cov
return(variance) }
```
Constraints: The sum of x == 1 Each x >= 0 #positive S[1,] == S[2,] meaning S[1,]-S[2,] == 0 # the sum of each column is equal or with a small tolerance.
Create data
```
library('Quandl')
a1 = Quandl("YAHOO/AAPL", transform ="rdiff", start_date="2013-12-31", type="xts")
a2 = Quandl("YAHOO/GOOG", transform ="rdiff", start_date="2013-12-31", type="xts")
a3 = Quandl("YAHOO/MSFT", transform ="rdiff", start_date="2013-12-31", type="xts")
a4 = Quandl("YAHOO/HPQ", transform ="rdiff", start_date="2013-12-31", type="xts")
a5 = Quandl("YAHOO/ORCL", transform ="rdiff", start_date="2013-12-31", type="xts")
R = merge(a1$`Adjusted Close`,a2$`Adjusted Close`,a3$`Adjusted Close`,a4$`Adjusted Close`, a5$`Adjusted Close`, all=TRUE)
colnames(R) = c('AAPL','GOOG','MSFT','HPQ','ORCL')
n = ncol(R)
S = matrix( c(-0.003296857,-0.003361181,-0.005320475,0.001920951,-0.0017016479,-0.005304732, -0.007212091,-0.003841529,0.004978937,-0.0001444762), byrow=TRUE, ncol=5)
colnames(S) = c('AAPL','GOOG','MSFT','HPQ','ORCL')
rownames(S) = c('S1','S2')
```Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.