# Documentation

## Estimate Efficient Frontiers for PortfolioCVaR Object

Whereas Estimate Efficient Portfolios for PortfolioCVaR Object focused on estimation of efficient portfolios, this section focuses on the estimation of efficient frontiers. For information on the workflow when using PortfolioCVaR objects, see PortfolioCVaR Object Workflow.

### Obtaining CVaR Portfolio Risks and Returns

Given any portfolio and, in particular, efficient portfolios, the functions `estimatePortReturn` and `estimatePortRisk` provide estimates for the return (or return proxy), risk (or the risk proxy). Each function has the same input syntax but with different combinations of outputs. Suppose that you have this following portfolio optimization problem that gave you a collection of portfolios along the efficient frontier in `pwgt`:

```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 = PortfolioCVaR; p = setScenarios(p, AssetScenarios); p = setDefaultConstraints(p); p = setProbabilityLevel(p, 0.95); pwgt0 = [ 0.3; 0.3; 0.2; 0.1 ]; p = setInitPort(p, pwgt0); pwgt = estimateFrontier(p); ```

 Note:   Remember that the risk proxy for CVaR portfolio optimization is CVaR.

Given `pwgt0` and `pwgt`, use the portfolio risk and return estimation functions to obtain risks and returns for your initial portfolio and the portfolios on the efficient frontier:

```prsk0 = estimatePortRisk(p, pwgt0); pret0 = estimatePortReturn(p, pwgt0); prsk = estimatePortRisk(p, pwgt); pret = estimatePortReturn(p, pwgt); ```
You obtain these risks and returns:
```display(prsk0); display(pret0); display(prsk); display(pret);```
```prsk0 = 0.0591 pret0 = 0.0067 prsk = 0.0414 0.0453 0.0553 0.0689 0.0843 0.1006 0.1193 0.1426 0.1689 0.1969 pret = 0.0050 0.0060 0.0070 0.0080 0.0089 0.0099 0.0109 0.0119 0.0129 0.0139```

### Obtaining Portfolio Standard Deviation and VaR

The PortfolioCVaR object has functions to compute standard deviations of portfolio returns and the value-at-risk of portfolios with the functions `estimatePortStd` and `estimatePortVaR`. These functions work with any portfolios, not necessarily efficient portfolios. For example, the following example obtains five portfolios (`pwgt`) on the efficient frontier and also has an initial portfolio in `pwgt0`. Various portfolio statistics are computed that include the return, risk, standard deviation, and value-at-risk. The listed estimates are for the initial portfolio in the first row followed by estimates for each of the five efficient portfolios in subsequent rows.

```m = [ 0.0042; 0.0083; 0.01; 0.15 ]; C = [ 0.005333 0.00034 0.00016 0; 0.00034 0.002408 0.0017 0.000992; 0.00016 0.0017 0.0048 0.0028; 0 0.000992 0.0028 0.010208 ]; pwgt0 = [ 0.3; 0.3; 0.2; 0.1 ]; p = PortfolioCVaR('initport', pwgt0); p = simulateNormalScenariosByMoments(p, m, C, 20000); p = setDefaultConstraints(p); p = setProbabilityLevel(p, 0.9); pwgt = estimateFrontier(p, 5); pret = estimatePortReturn(p, [pwgt0, pwgt]); prsk = estimatePortRisk(p, [pwgt0, pwgt]); pstd = estimatePortStd(p, [pwgt0, pwgt]); pvar = estimatePortVaR(p, [pwgt0, pwgt]); [pret, prsk, pstd, pvar]```
```ans = 0.0207 0.0464 0.0381 0.0283 0.1009 0.0214 0.0699 -0.0109 0.1133 0.0217 0.0772 -0.0137 0.1256 0.0226 0.0849 -0.0164 0.1380 0.0240 0.0928 -0.0182 0.1503 0.0262 0.1011 -0.0197```

### Plotting the Efficient Frontier for a PortfolioCVaR Object

The `plotFrontier` function creates a plot of the efficient frontier for a given portfolio optimization problem. This function accepts several types of inputs and generates a plot with an optional possibility to output the estimates for portfolio risks and returns along the efficient frontier. `plotFrontier` has four different ways that it can be used. In addition to a plot of the efficient frontier, if you have an initial portfolio in the `InitPort` property, `plotFrontier` also displays the return versus risk of the initial portfolio on the same plot. If you have a well-posed portfolio optimization problem set up in a PortfolioCVaR object and you use `plotFrontier`, you get a plot of the efficient frontier with the default number of portfolios on the frontier (the default number is currently `10` and is maintained in the hidden property `defaultNumPorts`). This example illustrates a typical use of `plotFrontier` to create a new plot:

```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 = PortfolioCVaR; p = setScenarios(p, AssetScenarios); p = setDefaultConstraints(p); p = setProbabilityLevel(p, 0.95); plotFrontier(p);```

The `Name` property appears as the title of the efficient frontier plot if you set it in the PortfolioCVaR object. Without an explicit name, the title on the plot would be "Efficient Frontier." If you want to obtain a specific number of portfolios along the efficient frontier, use `plotFrontier` with the number of portfolios that you want. Suppose that you have the PortfolioCVaR object from the previous example and you want to plot 20 portfolios along the efficient frontier and to obtain 20 risk and return values for each portfolio:

```[prsk, pret] = plotFrontier(p, 20); display([pret, prsk]);```
```ans = 0.0051 0.0406 0.0056 0.0414 0.0061 0.0437 0.0066 0.0471 0.0071 0.0515 0.0076 0.0567 0.0082 0.0624 0.0087 0.0687 0.0092 0.0753 0.0097 0.0821 0.0102 0.0891 0.0107 0.0962 0.0112 0.1044 0.0117 0.1142 0.0122 0.1251 0.0127 0.1369 0.0133 0.1496 0.0138 0.1628 0.0143 0.1766 0.0148 0.1907```

#### Plotting Existing Efficient Portfolios

If you already have efficient portfolios from any of the "estimateFrontier" functions (see Estimate Efficient Portfolios for PortfolioCVaR Object), pass them into `plotFrontier` directly to plot 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); pwgt0 = [ 0.3; 0.3; 0.2; 0.1 ]; p = PortfolioCVaR('Name', 'Asset Allocation Portfolio', 'InitPort', pwgt0); p = setScenarios(p, AssetScenarios); p = setDefaultConstraints(p); p = setProbabilityLevel(p, 0.95); pwgt = estimateFrontier(p, 20); plotFrontier(p, pwgt); ```

#### Plotting Existing Efficient Portfolio Risks and Returns

If you already have efficient portfolio risks and returns, you can use the interface to `plotFrontier` to pass them into `plotFrontier` to obtain a plot 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 ]; AssetScenarios = mvnrnd(m, C, 20000); pwgt0 = [ 0.3; 0.3; 0.2; 0.1 ]; p = PortfolioCVaR('Name', 'Asset Allocation Portfolio', 'InitPort', pwgt0); p = setScenarios(p, AssetScenarios); p = setDefaultConstraints(p); p = setProbabilityLevel(p, 0.95); pwgt = estimateFrontier(p); pret= estimatePortReturn(p, pwgt); prsk = estimatePortRisk(p, pwgt); plotFrontier(p, prsk, pret);```