Obtaining Efficient Portfolios for Target Risks

To obtain efficient portfolios that have targeted portfolio risks, the `estimateFrontierByRisk` function accepts one or more target portfolio risks and obtains efficient portfolios with the specified risks. Suppose that you have a universe of four assets where you want to obtain efficient portfolios with target portfolio risks of 12%, 14%, and 16%.

```m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; AssetScenarios = mvnrnd(m, C, 20000); p = PortfolioMAD; p = setScenarios(p, AssetScenarios); p = setDefaultConstraints(p); pwgt = estimateFrontierByRisk(p, [0.12, 0.14, 0.16]); display(pwgt)```
```pwgt = 0.2102 0.0621 0 0.3957 0.4723 0.4305 0.1051 0.1204 0.1291 0.2889 0.3452 0.4404```

Sometimes, you can request a risk for which no efficient portfolio exists. Based on the previous example, suppose that you want a portfolio with 6% risk (individual assets in this universe have risks ranging from 7% to 42.5%). It turns out that a portfolio with 6% risk cannot be formed with these four assets. `estimateFrontierByRisk` warns if your target risks are outside the range of efficient portfolio risks and replaces it with the endpoint of the efficient frontier closest to your target risk:

`pwgt = estimateFrontierByRisk(p, 0.06)`
```Warning: One or more target risk values are outside the feasible range [ 0.0610574, 0.278711 ]. Will return portfolios associated with endpoints of the range for these values. > In PortfolioMAD.estimateFrontierByRisk at 82 pwgt = 0.8867 0.0396 0.0404 0.0332```
The best way to avoid this situation is to bracket your target portfolio risks with `estimateFrontierLimits` and `estimatePortRisk` (see Obtaining Endpoints of the Efficient Frontier and Estimate Efficient Frontiers for PortfolioMAD Object).
```prsk = estimatePortRisk(p, p.estimateFrontierLimits); display(prsk)```
```prsk = 0.0611 0.2787```
This result indicates that efficient portfolios have risks that range from 7% to 42.5%. Note, your results for these examples may be different due to the random generation of scenarios.

Starting with an initial portfolio, `estimateFrontierByRisk` also returns purchases and sales to get from your initial portfolio to the target portfolios on the efficient frontier. For example, given an initial portfolio in `pwgt0`, you can obtain purchases and sales from the example with target risks of 12%, 14%, and 16%:

```pwgt0 = [ 0.3; 0.3; 0.2; 0.1 ]; p = setInitPort(p, pwgt0); [pwgt, pbuy, psell] = estimateFrontierByRisk(p, [0.12, 0.14, 0.16]); display(pwgt) display(pbuy) display(psell) ```
```pwgt = 0.2102 0.0621 0 0.3957 0.4723 0.4305 0.1051 0.1204 0.1291 0.2889 0.3452 0.4404 pbuy = 0 0 0 0.0957 0.1723 0.1305 0 0 0 0.1889 0.2452 0.3404 psell = 0.0898 0.2379 0.3000 0 0 0 0.0949 0.0796 0.0709 0 0 0```
If you do not specify an initial portfolio, the purchase and sale weights assume that your initial portfolio is `0`.