setInitPort

Class: Portfolio

Set up initial or current portfolio

Syntax

obj = setInitPort(obj,InitPort)
obj = setInitPort(obj,InitPort,NumAssets)

Description

obj = setInitPort(obj,InitPort) sets up the initial or current portfolio.

obj = setInitPort(obj,InitPort,NumAssets) sets up the initial or current portfolio with an additional options specified for NumAssets.

Tips

  • You can also use dot notation to set up an initial or current portfolio.

    obj = obj.setInitPort(InitPort, NumAssets);
  • To remove an initial portfolio, call this method with an empty argument [] for InitPort.

Input Arguments

obj

Portfolio object [Portfolio].

InitPort

Initial or current portfolio weights [vector].

    Note:   If InitPort is specified as a scalar and NumAssets exists, then InitPort undergoes scalar expansion.

NumAssets

(Optional) Number of assets in portfolio [scalar].

    Note:   If it is not possible to obtain a value for NumAssets, it is assumed that NumAssets is 1.

Output Arguments

obj

Updated Portfolio object [Portfolio].

Attributes

Accesspublic
Staticfalse
Hiddenfalse

To learn about attributes of methods, see Method Attributes in the MATLAB® Object-Oriented Programming documentation.

Examples

expand all

Set the InitPort Property

Given an initial portfolio in x0, use the setInitPort method to set the InitPort property.

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

Set InitPort to Create an Equally-Weighted Portfolio of Four Assets

Create an equally weighted portfolio of four assets using the setInitPort method.

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

Was this topic helpful?