setScenarios

Set asset returns scenarios by direct matrix

setScenarios has been partially removed and will no longer accept a fints object for the GetAssetList argument. Use timetable instead for financial time series.

Use fts2timetable to convert a fints object to a timetable object.

Description

example

obj = setScenarios(obj,AssetScenarios) sets asset returns scenarios by direct matrix for PortfolioCVaR or PortfolioMAD objects. For details on the workflows, see PortfolioCVaR Object Workflow, and PortfolioMAD Object Workflow.

example

obj = setScenarios(obj,AssetScenarios,Name,Value) set asset returns scenarios by direct matrix for PortfolioCVaR or PortfolioMAD objects using additional options specified by one or more Name,Value pair arguments.

Examples

collapse all

Given a PortfolioCVaR object p, use the setScenarios function to set asset return scenarios.

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);
disp(p)
  PortfolioCVaR with properties:

             BuyCost: []
            SellCost: []
        RiskFreeRate: []
    ProbabilityLevel: 0.9500
            Turnover: []
         BuyTurnover: []
        SellTurnover: []
        NumScenarios: 20000
                Name: []
           NumAssets: 4
           AssetList: []
            InitPort: []
         AInequality: []
         bInequality: []
           AEquality: []
           bEquality: []
          LowerBound: [4x1 double]
          UpperBound: []
         LowerBudget: 1
         UpperBudget: 1
         GroupMatrix: []
          LowerGroup: []
          UpperGroup: []
              GroupA: []
              GroupB: []
          LowerRatio: []
          UpperRatio: []
        MinNumAssets: []
        MaxNumAssets: []
           BoundType: [4x1 categorical]

Given PortfolioMAD object p, use the setScenarios function to set asset return scenarios.

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);
disp(p)
  PortfolioMAD with properties:

         BuyCost: []
        SellCost: []
    RiskFreeRate: []
        Turnover: []
     BuyTurnover: []
    SellTurnover: []
    NumScenarios: 20000
            Name: []
       NumAssets: 4
       AssetList: []
        InitPort: []
     AInequality: []
     bInequality: []
       AEquality: []
       bEquality: []
      LowerBound: [4x1 double]
      UpperBound: []
     LowerBudget: 1
     UpperBudget: 1
     GroupMatrix: []
      LowerGroup: []
      UpperGroup: []
          GroupA: []
          GroupB: []
      LowerRatio: []
      UpperRatio: []
    MinNumAssets: []
    MaxNumAssets: []
       BoundType: [4x1 categorical]

To illustrate using the setScenarios function with AssetScenarios data continued in a timetable object, use the CAPMuniverse.mat which contains a timetable object (AssetTimeTable) for returns data.

load CAPMuniverse;
AssetsTimeTable.Properties;
head(AssetsTimeTable,5)
ans=5×15 timetable
            Time              AAPL         AMZN         CSCO         DELL         EBAY       GOOG       HPQ          IBM         INTC         MSFT         ORCL         YHOO        MARKET         CASH   
    ____________________    _________    _________    _________    _________    _________    ____    _________    _________    _________    _________    _________    _________    _________    __________

    03-Jan-2000 00:00:00     0.088805       0.1742     0.008775    -0.002353      0.12829    NaN       0.03244     0.075368      0.05698    -0.001627     0.054078     0.097784    -0.012143    0.00020522
    04-Jan-2000 00:00:00    -0.084331     -0.08324     -0.05608     -0.08353    -0.093805    NaN     -0.075613    -0.033966    -0.046667    -0.033802      -0.0883    -0.067368     -0.03166    0.00020339
    05-Jan-2000 00:00:00     0.014634     -0.14877    -0.003039     0.070984     0.066875    NaN     -0.006356      0.03516     0.008199     0.010567    -0.052837    -0.073363     0.011443    0.00020376
    06-Jan-2000 00:00:00    -0.086538    -0.060072    -0.016619    -0.038847    -0.012302    NaN     -0.063688    -0.017241     -0.05824    -0.033477    -0.058824     -0.10307     0.011743    0.00020266
    07-Jan-2000 00:00:00     0.047368     0.061013       0.0587    -0.037708    -0.000964    NaN      0.028416    -0.004386      0.04127     0.013091     0.076771      0.10609      0.02393    0.00020157

setScenarios accepts a name-value pair argument name 'DataFormat' with a corresponding value set to 'prices' to indicate that the input to the function is in the form of asset prices and not returns (the default value for the 'DataFormat' argument is 'returns').

r = PortfolioCVaR;
r = setScenarios(r,AssetsTimeTable,'dataformat','returns');

In addition, the setScenarios function also extracts asset names or identifiers from a timetable object when the name-value argument 'GetAssetList' set to true (its default value is false). If the 'GetAssetList' value is true, the timetable column identifiers are used to set the AssetList property of the PortfolioCVaR object. To show this, the formation of the PortfolioCVaR object r is repeated with the 'GetAssetList' flag set to true.

r = setScenarios(r,AssetsTimeTable,'GetAssetList',true);
disp(r.AssetList')
    'AAPL'
    'AMZN'
    'CSCO'
    'DELL'
    'EBAY'
    'GOOG'
    'HPQ'
    'IBM'
    'INTC'
    'MSFT'
    'ORCL'
    'YHOO'
    'MARKET'
    'CASH'

Input Arguments

collapse all

Object for portfolio, specified using a PortfolioCVaR or PortfolioMAD object.

For more information on creating a PortfolioCVaR or PortfolioMAD object, see

Data Types: object

Scenarios for asset returns or prices, specified as a matrix, table, or timetable that contains asset data that can be converted into asset returns ([NumSamples-by-NumAssets] matrix).

AssetReturns data can be:

  • NumSamples-by-NumAssets matrix.

  • Table of NumSamples prices or returns at a given periodicity for a collection of NumAssets assets

  • Timetable object with NumSamples observations and NumAssets time series

If the input data are prices, they can be converted into returns with the DataFormat name-value pair argument, where the default format is assumed to be 'Returns'. Be careful using price data because portfolio optimization usually requires total returns and not simply price returns.

This function sets up a function handle to indirectly access input AssetScenarios without needing to make a copy of the data.

Data Types: double | table | timetable

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: p = setScenarios(p, AssetScenarios,'DataFormat','Returns','GetAssetList',false);

Flag to convert input data as prices into returns, specified as the comma-separated pair consisting of 'DataFormat' and a character vector with the values:

  • 'Returns' — Data in AssetReturns contains asset total returns.

  • 'Prices' — Data in AssetReturns contains asset total return prices.

Data Types: char

Flag indicating which asset names to use for the asset list, specified as the comma-separated pair consisting of 'GetAssetList' and a logical with a value of true or false. Acceptable values for GetAssetList are:

  • false — Do not extract or create asset names.

  • true — Extract or create asset names from table or timetable.

If a table or timetable is passed into this function as AssetScenarios and the GetAssetList flag is true, the column names from the table or timetable are used as asset names in obj.AssetList.

If a matrix is passed and the GetAssetList flag is true, default asset names are created based on the AbstractPortfolio property defaultforAssetList, which is currently 'Asset'.

If the GetAssetList flag is false, no action occurs, which is the default behavior.

Data Types: logical

Output Arguments

collapse all

Updated portfolio object, returned as a PortfolioCVaR or PortfolioMAD object. For more information on creating a portfolio object, see

Tips

You can also use dot notation to set asset return scenarios.

obj = obj.setScenarios(AssetScenarios);

Introduced in R2012b