## Estimate Efficient Portfolios Along the Entire Frontier for PortfolioMAD 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 PortfolioMAD Object focuses on the latter goal. For information on the workflow when using PortfolioMAD objects, see PortfolioMAD 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 `PortfolioMAD` 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 ]; m = m/12; C = C/12; AssetScenarios = mvnrnd(m, C, 20000); p = PortfolioMAD; p = setScenarios(p, AssetScenarios); p = setDefaultConstraints(p); pwgt = estimateFrontier(p); disp(pwgt)```
``` Columns 1 through 8 0.8907 0.7289 0.5614 0.3946 0.2257 0.0612 0 0.0000 0.0330 0.1163 0.2119 0.3042 0.3998 0.4876 0.4400 0.3125 0.0420 0.0469 0.0472 0.0505 0.0534 0.0580 0.0374 0.0018 0.0343 0.1079 0.1794 0.2507 0.3211 0.3933 0.5226 0.6857 Columns 9 through 10 0.0000 0.0000 0.1570 0.0000 0.0000 0.0000 0.8430 1.0000```
If you want only four portfolios in the previous example:
```pwgt = estimateFrontier(p, 4); disp(pwgt)```
``` 0.8907 0.3946 0 0.0000 0.0330 0.3042 0.4401 0.0000 0.0420 0.0505 0.0373 0.0000 0.0343 0.2507 0.5227 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 = Columns 1 through 8 0.8907 0.7289 0.5614 0.3946 0.2257 0.0612 0 0.0000 0.0330 0.1163 0.2119 0.3042 0.3998 0.4876 0.4400 0.3125 0.0420 0.0469 0.0472 0.0505 0.0534 0.0580 0.0374 0.0018 0.0343 0.1079 0.1794 0.2507 0.3211 0.3933 0.5226 0.6857 Columns 9 through 10 0.0000 0.0000 0.1570 0.0000 0.0000 0.0000 0.8430 1.0000 pbuy = Columns 1 through 8 0.5907 0.4289 0.2614 0.0946 0 0 0 0 0 0 0 0.0042 0.0998 0.1876 0.1400 0.0125 0 0 0 0 0 0 0 0 0 0.0079 0.0794 0.1507 0.2211 0.2933 0.4226 0.5857 Columns 9 through 10 0 0 0 0 0 0 0.7430 0.9000 psell = Columns 1 through 8 0 0 0 0 0.0743 0.2388 0.3000 0.3000 0.2670 0.1837 0.0881 0 0 0 0 0 0.1580 0.1531 0.1528 0.1495 0.1466 0.1420 0.1626 0.1982 0.0657 0 0 0 0 0 0 0 Columns 9 through 10 0.3000 0.3000 0.1430 0.3000 0.2000 0.2000 0 0```
If you do not specify an initial portfolio, the purchase and sale weights assume that your initial portfolio is `0`.