Skip to content
All library documents

Formulating Equal-Weight Bet Selection as a Binary Portfolio Problem

Article Quant Q&A · Author: JB17

Summary

The document frames a portfolio-selection problem in which rows represent candidate bets and columns represent binary win-or-loss scenarios. Because bets may be correlated, selecting the highest individual win rates is not necessarily sufficient. The author wants to select a fixed number of bets, assign equal weight to those selected, enforce a minimum win rate, and optimize a risk-adjusted objective involving mean absolute deviation (MAD) or a Sharpe-like ratio.

The author shares an attempted R linear-programming formulation and reports that it returns fractional weights rather than selecting the required number of bets. They ask how to model binary decisions and equal weights, and point to a mixed-integer portfolio example as a reference. No corrected formulation or solution is provided, and the stated objectives and constraints may require different optimization models; in particular, a ratio objective is not a plain linear program. The example is therefore useful as a modeling question, not as a validated implementation.

Key ideas

  • Correlated bets require evaluating selections jointly rather than ranking them only by individual win rates.
  • The proposed model asks for a fixed number of binary selections with equal weights among included bets.
  • The attempted R formulation returns fractional values, so it does not enforce binary inclusion.
  • MAD can be incorporated into optimization, but the requested objectives and constraints need a suitable model formulation.
  • The document asks for guidance and provides no verified solution.

Tags

Full text
# Portfolio Optimization with equal weight for assets selected


# Portfolio Optimization with equal weight for assets selected












I have a data frame of bets, with 1 being a win and 0 being a loss. These bets are correlated so I cannot just pick the highest winning percentage. Goal is to get 2 optimizations, 1 for max sharpe ration, and 1 for minMAD for a given return. This is similar to any portfolio questions, but with the unique constraint that each bet can only be placed once and some bets are correlated with one another

```
> df
  X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
A  0  1  0  1  0  0  0  1  1   0
B  0  1  0  0  1  1  1  1  1   1
C  1  0  0  0  0  0  0  1  1   0
D  1  0  1  1  1  0  0  1  0   1
E  0  0  1  0  1  0  1  1  1   0
F  0  1  0  1  0  1  1  0  1   1
G  1  0  0  0  0  1  1  1  1   0
H  0  0  1  1  0  0  1  1  0   1
I  1  0  0  0  0  1  1  1  1   0
J  0  1  1  0  0  1  0  1  0   0
```

Bets can either be included or excluded, but each bet can only be placed 1 time. I posted a questions over the weekend Optimization with Binary decision variable and simulated database thinking an equal weighted quadratic optimization could solve the problem but I could not figure out how to program binary variables. After doing so research today, I saw an example of a GLPK program that used mean absolute deviation and transformed it for a LP.

I am trying to tweak this for a binary variable, but have no experience with optimizations. What are some good resource to learn how to program the matrix. Here is the goal.

Minimize - Mean Absolute Deviation

S.T.

Number of bets = 4

Bets are a binary variable

Winning percentage >= 0.52

And

Maximize winning percentage / MAD

ST

Weights are equal (1/n) or 0.25, and sum to 1

Can someone help point me in the right direction. I am new to R and never set up a LP before. Some resource to help learn, and advice on set up will be much appreciated. I spend this weekend trying to figure it out spinning circles. Also I plan on playing around with the constraints and objective function once I get a base model going so please pass along good resources on R optimizations so I can learn. S.O. has been a great resource helping me learn R, right now I am using excel as a stop gap but the read data set is too big for the standard excel solve so I have to make several adjustments to get any usable results.

Thanks for all of your help.

So this is what I have so far, but the output is not correct.

```
> nAssets = nrow(df)
> nScenarios = ncol(df)
> Mean = rowMeans(df)
> data = as.matrix(df)
> sucessRate = .52
>   vec <- c(weights=rep(0, nAssets), scenarios=rep(1/nScenarios, nScenarios))
> mat <- rbind(
+       MAD.LE = cbind(data, -diag(nScenarios)),
+       MAD.GE = cbind(data, +diag(nScenarios)),
+       RETURN = t(c(Mean, rep(0, nScenarios))),
+       BUDGET = t(c(rep(1, nAssets), rep(0, nScenarios))),
+       X = cbind(matrix(rep(0, nAssets*nScenarios),ncol=nAssets), diag(nScenarios)),
+       WEIGHTS = cbind(diag(nAssets), matrix(rep(0, nScenarios*nAssets), nrow=nAssets)))
> mat <- rbind(
+       MAD.LE = cbind(data, -diag(nScenarios)),
+       MAD.GE = cbind(data, +diag(nScenarios)),
+       RETURN = t(c(Mean, rep(0, nScenarios))),
+       BUDGET = t(c(rep(1, nAssets), rep(0, nScenarios))),
+       X = cbind(matrix(rep(0, nAssets*nScenarios),ncol=nAssets), diag(nScenarios)),
+       WEIGHTS = cbind(diag(nAssets), matrix(rep(0, nScenarios*nAssets), nrow=nAssets)))
> rhs <- c(
+       MAD.LE = rep(0, nScenarios),
+       MAD.GE = rep(0, nScenarios),
+       RETURN = sucessRate,
+       BUDGET = 1,
+       X = rep(0, nScenarios),
+       WEIGHTS = rep(0, nAssets))
>  dir <- c(
+       MAD.LE = rep("<=", nScenarios),
+       MAS.GE = rep(">=", nScenarios),
+       RETURN = "==",
+       BUDGET = "==",
+       X = rep(">=", nScenarios),
+       WEIGHTS = rep(">=", nAssets))
>  Rglpk::Rglpk_solve_LP(vec, mat, dir, rhs)
$optimum
[1] 0.31

$solution
 [1] 0.000000e+00 1.000000e-01 0.000000e+00 0.000000e+00 9.000000e-01 0.000000e+00 0.000000e+00
 [8] 0.000000e+00 0.000000e+00 9.860761e-32 1.000000e-01 1.000000e+00 0.000000e+00 9.000000e-01
[15] 9.000000e-01 1.000000e-01 0.000000e+00 9.860761e-32 0.000000e+00 1.000000e-01

$status
[1] 0
```

What mistake did I make that is yielding more than 10 weights, and how do I get the weights equal and only 4 bets selected. Here is MatLab code for almost exactly what I am looking for, can someone help translate what is missing to R.

http://www.mathworks.com/help/optim/examples/mixed-integer-quadratic-programming-portfolio-optimization.html

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.