## Validate the Portfolio Problem for Portfolio Object

Sometimes, you may want to validate either your inputs to, or outputs from, a portfolio optimization problem. Although most error checking that occurs during the problem setup phase catches most difficulties with a portfolio optimization problem, the processes to validate portfolio sets and portfolios are time consuming and are best done offline. So, the portfolio optimization tools have specialized functions to validate portfolio sets and portfolios. For information on the workflow when using `Portfolio` objects, see Portfolio Object Workflow.

### Validating a Portfolio Set

Since it is necessary and sufficient that your portfolio set must be a nonempty, closed, and bounded set to have a valid portfolio optimization problem, the `estimateBounds` function lets you examine your portfolio set to determine if it is nonempty and, if nonempty, whether it is bounded. Suppose that you have the following portfolio set which is an empty set because the initial portfolio at `0` is too far from a portfolio that satisfies the budget and turnover constraint:

```p = Portfolio('NumAssets', 3, 'Budget', 1); p = setTurnover(p, 0.3, 0); ```

If a portfolio set is empty, `estimateBounds` returns `NaN` bounds and sets the `isbounded` flag to `[]`:

`[lb, ub, isbounded] = estimateBounds(p)`
```lb = NaN NaN NaN ub = NaN NaN NaN isbounded = []```

Suppose that you create an unbounded portfolio set as follows:

```p = Portfolio('AInequality', [1 -1; 1 1 ], 'bInequality', 0); [lb, ub, isbounded] = estimateBounds(p)```
```lb = -Inf -Inf ub = 1.0e-08 * -0.3712 Inf isbounded = logical 0```
In this case, `estimateBounds` returns (possibly infinite) bounds and sets the `isbounded` flag to `false`. The result shows which assets are unbounded so that you can apply bound constraints as necessary.

Finally, suppose that you created a portfolio set that is both nonempty and bounded. `estimateBounds` not only validates the set, but also obtains tighter bounds which are useful if you are concerned with the actual range of portfolio choices for individual assets in your portfolio set:

```p = Portfolio; p = setBudget(p, 1,1); p = setBounds(p, [ -0.1; 0.2; 0.3; 0.2 ], [ 0.5; 0.3; 0.9; 0.8 ]); [lb, ub, isbounded] = estimateBounds(p)```
```lb = -0.1000 0.2000 0.3000 0.2000 ub = 0.3000 0.3000 0.7000 0.6000 isbounded = logical 1```

In this example, all but the second asset has tighter upper bounds than the input upper bound implies.

### Validating Portfolios

Given a portfolio set specified in a `Portfolio` object, you often want to check if specific portfolios are feasible with respect to the portfolio set. This can occur with, for example, initial portfolios and with portfolios obtained from other procedures. The `checkFeasibility` function determines whether a collection of portfolios is feasible. Suppose that you perform the following portfolio optimization and want to determine if the resultant efficient portfolios are feasible relative to a modified problem.

First, set up a problem in the `Portfolio` object `p`, estimate efficient portfolios in `pwgt`, and then confirm that these portfolios are feasible relative to the initial problem:

```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); checkFeasibility(p, pwgt)```
```ans = 1 1 1 1 1 1 1 1 1 1```

Next, set up a different portfolio problem that starts with the initial problem with an additional a turnover constraint and an equally weighted initial portfolio:

```q = setTurnover(p, 0.3, 0.25); checkFeasibility(q, pwgt)```
```ans = 0 0 0 1 1 0 0 0 0 0```
In this case, only two of the 10 efficient portfolios from the initial problem are feasible relative to the new problem in Portfolio object `q`. Solving the second problem using `checkFeasibility` demonstrates that the efficient portfolio for `Portfolio` object `q` is feasible relative to the initial problem:

```qwgt = estimateFrontier(q); checkFeasibility(p, qwgt)```
```ans = 1 1 1 1 1 1 1 1 1 1```
{"ft_lang_label":"__label__en","ft_lang_prob":0.7477125,"math_prob":0.9759578,"size":3849,"snap":"2021-04-2021-17","text_gpt3_token_len":1070,"char_repetition_ratio":0.17113134,"word_repetition_ratio":0.0624,"special_character_ratio":0.27669525,"punctuation_ratio":0.17312661,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9903846,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-01-16T00:15:28Z\",\"WARC-Record-ID\":\"<urn:uuid:ebf18d86-6a67-4b0d-97d5-dd20fb801ed8>\",\"Content-Length\":\"72214\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2f1ffdee-beb5-4b98-9101-790be5782c91>\",\"WARC-Concurrent-To\":\"<urn:uuid:68867fc5-e457-4a1e-b58f-1015c35061ad>\",\"WARC-IP-Address\":\"23.41.4.85\",\"WARC-Target-URI\":\"https://ch.mathworks.com/help/finance/validate-the-portfolio-problem-for-portfolio-object.html\",\"WARC-Payload-Digest\":\"sha1:JCE7R55FN7HGONI3RMGMST75DN2VASBX\",\"WARC-Block-Digest\":\"sha1:L3OONHO32Z7RXR5ZST3N5SZOUGBUTT4E\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-04/CC-MAIN-2021-04_segments_1610703497681.4_warc_CC-MAIN-20210115224908-20210116014908-00691.warc.gz\"}"}