## 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 = PortfolioMAD; p = setScenarios(p, AssetScenarios); p = setDefaultConstraints(p); pwgt = estimateFrontierByReturn(p, [0.07, 0.10, .12]); display(pwgt)```
```pwgt = 0.7537 0.3899 0.1478 0.1113 0.2934 0.4136 0.0545 0.1006 0.1319 0.0805 0.2161 0.3066```

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.0591121, 0.182542 ]. Will return portfolios associated with endpoints of the range for these values. > In PortfolioMAD.estimateFrontierByReturn at 90 ```
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 MAD Portfolio Risks and Returns).
```pret = estimatePortReturn(p, p.estimateFrontierLimits); display(pret)```
```pret = 0.0591 0.1825```
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.7537 0.3899 0.1478 0.1113 0.2934 0.4136 0.0545 0.1006 0.1319 0.0805 0.2161 0.3066 pbuy = 0.4537 0.0899 0 0 0 0.1136 0 0 0 0 0.1161 0.2066 psell = 0 0 0.1522 0.1887 0.0066 0 0.1455 0.0994 0.0681 0.0195 0 0```
If you do not have an initial portfolio, the purchase and sale weights assume that your initial portfolio is `0`.