Setting Up an Initial or Current Portfolio

In many applications, creating a new optimal portfolio requires comparing the new portfolio with an initial or current portfolio to form lists of purchases and sales. The `Portfolio` object property `InitPort` lets you identify an initial or current portfolio. The initial portfolio also plays an essential role if you have either transaction costs or turnover constraints. The initial portfolio need not be feasible within the constraints of the problem. This can happen if the weights in a portfolio have shifted such that some constraints become violated. To check if your initial portfolio is feasible, use the `checkFeasibility` function described in Validating Portfolios. Suppose that you have an initial portfolio in `x0`, then use the `Portfolio` object to set up an initial portfolio:

```x0 = [ 0.3; 0.2; 0.2; 0.0 ]; p = Portfolio('InitPort', x0); disp(p.InitPort)```
``` 0.3000 0.2000 0.2000 0```

As with all array properties, you can set `InitPort` with scalar expansion. This is helpful to set up an equally weighted initial portfolio of, for example, 10 assets:

```p = Portfolio('NumAssets', 10, 'InitPort', 1/10); disp(p.InitPort) ```
``` 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000```

To clear an initial portfolio from your `Portfolio` object, use either the `Portfolio` object or the `setInitPort` function with an empty input for the `InitPort` property. If transaction costs or turnover constraints are set, it is not possible to clear the `InitPort` property in this way. In this case, to clear `InitPort`, first clear the dependent properties and then clear the`InitPort` property.

The `InitPort` property can also be set with `setInitPort` which lets you specify the number of assets if you want to use scalar expansion. For example, given an initial portfolio in `x0`, use `setInitPort` to set the `InitPort` property:

```p = Portfolio; x0 = [ 0.3; 0.2; 0.2; 0.0 ]; p = setInitPort(p, x0); disp(p.InitPort) ```
``` 0.3000 0.2000 0.2000 0```

To create an equally weighted portfolio of four assets, use `setInitPort`:

```p = Portfolio; p = setInitPort(p, 1/4, 4); disp(p.InitPort) ```
``` 0.2500 0.2500 0.2500 0.2500```

Portfolio object functions that work with either transaction costs or turnover constraints also depend on the `InitPort` property. So, the `set` functions for transaction costs or turnover constraints permit the assignment of a value for the `InitPort` property as part of their implementation. For details, see Working with Average Turnover Constraints Using Portfolio Object, Working with One-Way Turnover Constraints Using Portfolio Object, and Working with Transaction Costs for details. If either transaction costs or turnover constraints are used, then the `InitPort` property must have a nonempty value. Absent a specific value assigned through the `Portfolio` object or various `set` functions, the `Portfolio` object sets `InitPort` to `0` and warns if `BuyCost`, `SellCost`, or `Turnover` properties are set. The following example illustrates what happens if an average turnover constraint is specified with an initial portfolio:

```p = Portfolio('Turnover', 0.3, 'InitPort', [ 0.3; 0.2; 0.2; 0.0 ]); disp(p.InitPort) ```
``` 0.3000 0.2000 0.2000 0```
In contrast, this example shows what happens if an average turnover constraint is specified without an initial portfolio:
```p = Portfolio('Turnover', 0.3); disp(p.InitPort) ```
```Warning: InitPort and NumAssets are empty and either transaction costs or turnover constraints specified. Will set NumAssets = 1 and InitPort = 0. > In Portfolio.checkarguments at 367 In Portfolio.Portfolio>Portfolio.Portfolio at 171 0```