## Estimate Efficient Portfolios for Entire Efficient Frontier for Portfolio Object

There are two ways to look at a portfolio optimization problem that depends on what you are trying to do. One goal is to estimate efficient portfolios and the other is to estimate efficient frontiers. This section focuses on the former goal and Estimate Efficient Frontiers for Portfolio Object focuses on the latter goal. For information on the workflow when using `Portfolio` objects, see Portfolio Object Workflow.

### Obtaining Portfolios Along the Entire Efficient Frontier

The most basic way to obtain optimal portfolios is to obtain points over the entire range of the efficient frontier. Given a portfolio optimization problem in a `Portfolio` object, the `estimateFrontier` function computes efficient portfolios spaced evenly according to the return proxy from the minimum to maximum return efficient portfolios. The number of portfolios estimated is controlled by the hidden property `defaultNumPorts` which is set to `10`. A different value for the number of portfolios estimated is specified as input to `estimateFrontier`. This example shows the default number of efficient portfolios over the entire range of the efficient frontier:

```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 ]; p = Portfolio; p = setAssetMoments(p, m, C); p = setDefaultConstraints(p); pwgt = estimateFrontier(p); disp(pwgt)```
```0.8891 0.7215 0.5540 0.3865 0.2190 0.0515 0 0 0 0 0.0369 0.1289 0.2209 0.3129 0.4049 0.4969 0.4049 0.2314 0.0579 0 0.0404 0.0567 0.0730 0.0893 0.1056 0.1219 0.1320 0.1394 0.1468 0 0.0336 0.0929 0.1521 0.2113 0.2705 0.3297 0.4630 0.6292 0.7953 1.0000```
If you want only four portfolios in the previous example:
```pwgt = estimateFrontier(p, 4); disp(pwgt)```
``` 0.8891 0.3865 0 0 0.0369 0.3129 0.4049 0 0.0404 0.0893 0.1320 0 0.0336 0.2113 0.4630 1.0000```

Starting from the initial portfolio, `estimateFrontier` also returns purchases and sales to get from your initial portfolio to each efficient portfolio on the efficient frontier. For example, given an initial portfolio in `pwgt0`, you can obtain purchases and sales:

```pwgt0 = [ 0.3; 0.3; 0.2; 0.1 ]; p = setInitPort(p, pwgt0); [pwgt, pbuy, psell] = estimateFrontier(p); display(pwgt) display(pbuy) display(psell)```
```pwgt = 0.8891 0.7215 0.5540 0.3865 0.2190 0.0515 0 0 0 0 0.0369 0.1289 0.2209 0.3129 0.4049 0.4969 0.4049 0.2314 0.0579 0 0.0404 0.0567 0.0730 0.0893 0.1056 0.1219 0.1320 0.1394 0.1468 0 0.0336 0.0929 0.1521 0.2113 0.2705 0.3297 0.4630 0.6292 0.7953 1.0000 pbuy = 0.5891 0.4215 0.2540 0.0865 0 0 0 0 0 0 0 0 0 0.0129 0.1049 0.1969 0.1049 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0521 0.1113 0.1705 0.2297 0.3630 0.5292 0.6953 0.9000 psell = 0 0 0 0 0.0810 0.2485 0.3000 0.3000 0.3000 0.3000 0.2631 0.1711 0.0791 0 0 0 0 0.0686 0.2421 0.3000 0.1596 0.1433 0.1270 0.1107 0.0944 0.0781 0.0680 0.0606 0.0532 0.2000 0.0664 0.0071 0 0 0 0 0 0 0 0```
If you do not specify an initial portfolio, the purchase and sale weights assume that your initial portfolio is `0`.