## Obtaining Efficient Portfolios for Target Returns

To obtain efficient portfolios that have targeted portfolio returns, the `estimateFrontierByReturn` function accepts one or more target portfolio returns and obtains efficient portfolios with the specified returns. For example, assume that you have a universe of four assets where you want to obtain efficient portfolios with target portfolio returns of 7%, 10%, and 12%:

```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 = PortfolioCVaR; p = setScenarios(p, AssetScenarios); p = setDefaultConstraints(p); p = setProbabilityLevel(p, 0.95); pwgt = estimateFrontierByReturn(p, [0.07, 0.10, .12]); display(pwgt)```
```pwgt = 0.7526 0.3773 0.1306 0.1047 0.3079 0.4348 0.0662 0.1097 0.1426 0.0765 0.2051 0.2920```

Sometimes, you can request a return for which no efficient portfolio exists. Based on the previous example, suppose that you want a portfolio with a 4% return (which is the return of the first asset). A portfolio that is fully invested in the first asset, however, is inefficient. `estimateFrontierByReturn` warns if your target returns are outside the range of efficient portfolio returns and replaces it with the endpoint portfolio of the efficient frontier closest to your target return:

``` pwgt = estimateFrontierByReturn(p, [0.04]); ```
```Warning: One or more target return values are outside the feasible range [ 0.066388, 0.178834 ]. Will return portfolios associated with endpoints of the range for these values. > In PortfolioCVaR.estimateFrontierByReturn at 93 ```
The best way to avoid this situation is to bracket your target portfolio returns with `estimateFrontierLimits` and `estimatePortReturn` (see Obtaining Endpoints of the Efficient Frontier and Obtaining CVaR Portfolio Risks and Returns).
```pret = estimatePortReturn(p, p.estimateFrontierLimits); display(pret)```
```pret = 0.0664 0.1788```
This result indicates that efficient portfolios have returns that range from 6.5% to 17.8%. Note, your results for these examples may be different due to the random generation of scenarios.

If you have an initial portfolio, `estimateFrontierByReturn` 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`, to obtain purchases and sales with target returns of 7%, 10%, and 12%:

```pwgt0 = [ 0.3; 0.3; 0.2; 0.1 ]; p = setInitPort(p, pwgt0); [pwgt, pbuy, psell] = estimateFrontierByReturn(p, [0.07, 0.10, .12]); display(pwgt) display(pbuy) display(psell)```
```pwgt = 0.7526 0.3773 0.1306 0.1047 0.3079 0.4348 0.0662 0.1097 0.1426 0.0765 0.2051 0.2920 pbuy = 0.4526 0.0773 0 0 0.0079 0.1348 0 0 0 0 0.1051 0.1920 psell = 0 0 0.1694 0.1953 0 0 0.1338 0.0903 0.0574 0.0235 0 0```
If you do not have an initial portfolio, the purchase and sale weights assume that your initial portfolio is `0`.