Main Content

append

Add portfolio, value-at-risk (VaR), and expected shortfall (ES) data to backtest objects

Since R2023b

    Description

    example

    vbt = append(vbt,newPortfolioData,newVaRData) adds portfolio and VaR data to a varbacktest object, vbt.

    example

    ebt = append(ebt,newPortfolioData,newVaRData,newESData) adds portfolio, VaR, and ES data to an esbacktest object, ebt (since R2024a).

    example

    ___ = append(___,Time=newDates) adds the new dates contained in newDates to either a varbacktest or an esbacktest object.

    Examples

    collapse all

    Create a varbacktest object and append a new entry to it by using the append function.

    load VaRBacktestData
    vbt = varbacktest(EquityIndex,Normal95)
    vbt = 
      varbacktest with properties:
    
        PortfolioData: [1043x1 double]
              VaRData: [1043x1 double]
                 Time: [1043x1 double]
          PortfolioID: "Portfolio"
                VaRID: "VaR"
             VaRLevel: 0.9500
    
    
    vbt = append(vbt,-0.0021,0.0204)
    vbt = 
      varbacktest with properties:
    
        PortfolioData: [1044x1 double]
              VaRData: [1044x1 double]
                 Time: [1044x1 double]
          PortfolioID: "Portfolio"
                VaRID: "VaR"
             VaRLevel: 0.9500
    
    

    Create an esbacktest object and append a new entry to it by using the append function.

    load ESBacktestData
    ebt = esbacktest(Returns,VaRModel1,ESModel1)
    ebt = 
      esbacktest with properties:
    
        PortfolioData: [1966x1 double]
              VaRData: [1966x1 double]
               ESData: [1966x1 double]
                 Time: [1966x1 double]
          PortfolioID: "Portfolio"
                VaRID: "VaR"
             VaRLevel: 0.9500
    
    
    ebt = append(ebt,-0.0135,0.0300,0.0358)
    ebt = 
      esbacktest with properties:
    
        PortfolioData: [1967x1 double]
              VaRData: [1967x1 double]
               ESData: [1967x1 double]
                 Time: [1967x1 double]
          PortfolioID: "Portfolio"
                VaRID: "VaR"
             VaRLevel: 0.9500
    
    

    Create a varbacktest object and append two new entities with explicit dates by using the Time name-value argument.

    load VaRBacktestData
    vbt = varbacktest(EquityIndex, ...
       [Normal95 Normal99 Historical95 Historical99 EWMA95 EWMA99], ...
       'Time',Date, ...
       'PortfolioID','Equity', ...
       'VaRID',{'Normal95' 'Normal99' 'Historical95' 'Historical99' 'EWMA95' 'EWMA99'}, ...
       'VaRLevel',[0.95 0.99 0.95 0.99 0.95 0.99])
    vbt = 
      varbacktest with properties:
    
        PortfolioData: [1043x1 double]
              VaRData: [1043x6 double]
                 Time: [1043x1 datetime]
          PortfolioID: "Equity"
                VaRID: ["Normal95"    "Normal99"    "Historical95"    "Historical99"    "EWMA95"    "EWMA99"]
             VaRLevel: [0.9500 0.9900 0.9500 0.9900 0.9500 0.9900]
    
    
    newEquityData = [-0.0021; 0.0005];
    newVaRData = [0.02029, 0.0287, 0.01935, 0.02954, 0.01662, 0.02351; ...
        0.020285, 0.0282, 0.01335, 0.02954, 0.01630, 0.023878];
    newDates = [datetime(2003, 1, 2); datetime(2003, 1, 3)];
    vbt = append(vbt,newEquityData,newVaRData,Time=newDates)
    vbt = 
      varbacktest with properties:
    
        PortfolioData: [1045x1 double]
              VaRData: [1045x6 double]
                 Time: [1045x1 datetime]
          PortfolioID: "Equity"
                VaRID: ["Normal95"    "Normal99"    "Historical95"    "Historical99"    "EWMA95"    "EWMA99"]
             VaRLevel: [0.9500 0.9900 0.9500 0.9900 0.9500 0.9900]
    
    

    Create an esbacktest object and append two new entities with explicit dates by using the Time name-value argument.

    load ESBacktestData
    ebt = esbacktest(Returns, ...
         [VaRModel1 VaRModel2 VaRModel3], ...
         [ESModel1 ESModel2 ESModel3], ...
         'Time', Dates, ...
         'PortfolioID','S&P', ...
         'VaRID',{'Model 1','Model 2','Model3'}, ...
         'VaRLevel',VaRLevel)
    ebt = 
      esbacktest with properties:
    
        PortfolioData: [1966x1 double]
              VaRData: [1966x3 double]
               ESData: [1966x3 double]
                 Time: [1966x1 datetime]
          PortfolioID: "S&P"
                VaRID: ["Model 1"    "Model 2"    "Model3"]
             VaRLevel: [0.9750 0.9750 0.9750]
    
    
    newReturnsData = [-0.0056; 0.0034];
    newVaRData = [0.0308,0.0313,0.0313; ...
          0.0310,0.0315,0.0315];
    newESData = [0.0367,0.0396,0.0429; ...
          0.0370, 0.0399, 0.0431];
    newDates = [datetime(2003,7,15); datetime(2003,7,16)];
    ebt = append(ebt,newReturnsData,newVaRData,newESData,Time=newDates)
    ebt = 
      esbacktest with properties:
    
        PortfolioData: [1968x1 double]
              VaRData: [1968x3 double]
               ESData: [1968x3 double]
                 Time: [1968x1 datetime]
          PortfolioID: "S&P"
                VaRID: ["Model 1"    "Model 2"    "Model3"]
             VaRLevel: [0.9750 0.9750 0.9750]
    
    

    Input Arguments

    collapse all

    VaR backtest object, specified as a varbacktest object. Use this input argument when working with the first or third syntax. vbt contains a copy of the given data (the PortfolioData and VarData properties) and all combinations of portfolio ID, VaR ID, and VaR levels to be tested.

    ES backtest object, specified as an esbacktest object. Use this input argument when working with the second or third syntax. ebt contains a copy of the given data (the PortfolioData, VarData, and ESData properties) and all combinations of portfolio ID, VaR ID, and VaR levels to be tested.

    New equity data to be added to the existing portfolio data vector, specified as a numeric vector.

    Data Types: double

    New value-at-risk data to be added to the existing VaR data vector, specified as a matrix with the number of columns matching the number of VaR IDs from the VaRID property in the parent varbacktest object. The VaR vectors should represent the VaR levels at the same confidence level in the same order.

    Data Types: double

    New expected shortfall data, specified as a matrix with the number of columns matching the number of ES vectors in the parent esbacktest object. The ES vectors should represent the ES levels for the same VaR levels in the same order.

    Data Types: double

    New dates to be added to the existing date vector, specified as a sequential numeric vector, a datetime vector, or a duration vector.

    • The default numeric vector is NumRows+1:NumRows+NumNewDataRows, where NumRows is the number of data points in the parent varbacktest or esbacktest object and NumNewDataRows is the number of new data points being appended. For example, vbt=append(vbt,newEquityData,newVaRData,Time=newDates) appends new equity data to the VaR backtest object with explicit dates contained in newDates by using the Time name-value argument.

    • The data type of newDates must match the data type of the Time property in the input varbacktest or esbacktest object.

    • The size of newDates must match the size of the newPortolioData argument.

    Data Types: double | datetime | duration

    Version History

    Introduced in R2023b

    expand all