# 混合整数均值-方差投资组合优化问题

### 均值-方差投资组合

`$\mathit{X}=\left\{\mathit{x}|\sum _{\mathit{i}=1}^{\mathit{n}}{\mathit{x}}_{\mathit{i}}=1,{\mathit{x}}_{\mathit{i}\text{\hspace{0.17em}}}\ge 0\right\}.$`

```% Load data load CAPMuniverse.mat % Create a mean-variance Portfolio object with default constraints p = Portfolio(AssetList=Assets(1:12)); p = estimateAssetMoments(p,Data(:,1:12)); p = setDefaultConstraints(p);```

```% Set conditional bounds condLB = 0.1; condUB = 0.5; p = setBounds(p,condLB,condUB,BoundType="conditional");```

```% Compute efficient frontier pwgt = estimateFrontier(p)```
```pwgt = 12×10 0 0 0.1000 0.1253 0.1745 0.2236 0.2715 0.3327 0.4111 0.5000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1350 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1000 0.1450 0.1406 0.1910 0.2344 0.2778 0.3200 0.3726 0.4415 0.5000 0.1000 0.1609 0.1642 0.2121 0.2415 0.2709 0.3085 0.2947 0.1474 0 0.2354 0.1875 0.1290 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.4296 0.4066 0.3662 0.3717 0.2496 0.1277 0 0 0 0 ⋮ ```
```% Compute risk and returns of the portfolios on the efficient frontier [rsk,ret] = estimatePortMoments(p,pwgt)```
```rsk = 10×1 0.0076 0.0080 0.0085 0.0094 0.0105 0.0117 0.0132 0.0147 0.0168 0.0193 ```
```ret = 10×1 0.0008 0.0012 0.0017 0.0021 0.0026 0.0030 0.0034 0.0039 0.0043 0.0048 ```

```% Plot efficient frontier plotFrontier(p,pwgt)```

### 更改 MINLP 求解器

• `OuterApproximation` - 默认算法，该算法非常稳健，通常比 `ExtenedCP` 速度更快

• `OuterApproximation`，其中 `ExtendedFormulation` 设置为 `true` - 一种稳健的算法，通常比其他算法更快，但仅支持求解 `Portfolio` 对象问题

• `ExtendedCP` - 该求解器稳健性最佳，但通常速度最慢

• `TrustRegionCP` - 该算法速度最快，但稳健性较差，可能提供次优解

```% Select the extended formulation version of 'OuterApproximation' p_EOA = setSolverMINLP(p,'OuterApproximation',... ExtendedFormulation=true); pwgt_EOA = estimateFrontier(p_EOA); [rskEOA,retEOA] = estimatePortMoments(p_EOA,pwgt_EOA); % Select 'TrustRegionCP' as solver p_TR = setSolverMINLP(p,'TrustRegionCP'); pwgt_TR = estimateFrontier(p_TR); [rskTR,retTR] = estimatePortMoments(p_TR,pwgt_TR); % Select 'ExtendedCP' as solver using 'midway' cuts as 'CutGeneration' p_ECP = setSolverMINLP(p,'ExtendedCP','CutGeneration','midway'); pwgt_ECP = estimateFrontier(p_ECP); [rskECP,retECP] = estimatePortMoments(p_ECP,pwgt_ECP);```

```retTable = table(ret,retEOA,retTR,retECP,... 'VariableNames',{'OA','EOA','TR','ECP'})```
```retTable=10×4 table OA EOA TR ECP __________ __________ __________ __________ 0.00078336 0.00078336 0.00078334 0.00078348 0.0012267 0.0012267 0.0012267 0.0012268 0.00167 0.00167 0.00167 0.0016701 0.0021133 0.0021133 0.0021133 0.0021134 0.0025566 0.0025566 0.0025566 0.0025567 0.0029999 0.0029999 0.0029999 0.003 0.0034432 0.0034432 0.0034432 0.0034433 0.0038865 0.0038865 0.0038865 0.0038866 0.0043298 0.0043298 0.0043298 0.0043299 0.0047731 0.0047731 0.0047731 0.0047731 ```
```rskTable = table(rsk,rskEOA,rskTR,rskECP,... 'VariableNames',{'OA','EOA','TR','ECP'})```
```rskTable=10×4 table OA EOA TR ECP _________ _________ _________ _________ 0.0075778 0.0075778 0.0075778 0.0075778 0.0080234 0.0080234 0.0080235 0.0080236 0.0085488 0.0085488 0.0085488 0.008549 0.0094024 0.0094024 0.009405 0.0094025 0.010456 0.010456 0.010456 0.010456 0.011727 0.011727 0.011776 0.011728 0.013155 0.013155 0.013155 0.013155 0.014729 0.014729 0.014729 0.014729 0.016764 0.016764 0.016764 0.016764 0.019273 0.019273 0.019273 0.019273 ```
```% Compare risks from the different OuterApproximation formulations norm(rskTable.OA-rskTable.EOA,Inf) <= 1e-4```
```ans = logical 1 ```