Main Content

plot

Visualize value-at-risk (VaR) or expected shortfall (ES) and portfolio data, and highlight exceptions

Since R2023b

    Description

    plot(btobj) plots the vectors and portfolio data, where btobj is either an esbacktest (since R2024a) or a varbacktest object.

    example

    plot(btobj,Name=Value) specifies additional plot styles using one or more name-value arguments. For example, plot(btobj,Type="bar") specifies a bar-style plot.

    example

    hPlot = plot(___) returns a Line object or an array of Line objects. Use the figure handle hPlot to modify properties of the plot after creating it.

    Examples

    collapse all

    Plot varbacktest data as a line and highlight the exceptions as dot markers. The plot function highlights a loss as an exception with respect to any VaR value.

    load VaRBacktestData
    btobj = varbacktest(EquityIndex, ...
       [Normal95 Normal99], ...
       'PortfolioID',"Equity", ...
       'VaRID',{'Normal95' 'Normal99'}, ...
       'VaRLevel',[0.95 0.99], ...
       'Time',Date);
    plot(btobj)

    Figure contains an axes object. The axes object with title VaR Backtesting, xlabel Time contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent Equity, Normal95, Normal99, Exceptions.

    Use the select function to choose a smaller backtesting time window. Then, use the plot function to make a bar-stye plot to highlight the exceptions for each VaR vector separately.

    load VaRBacktestData
    btobj = varbacktest(EquityIndex, ...
       [Normal95 Normal99], ...
       'PortfolioID',"Equity", ...
       'VaRID',{'Normal95' 'Normal99'}, ...
       'VaRLevel',[0.95 0.99], ...
       'Time',Date);
    btobjQ2 = select(btobj,TimeRange=[datetime(2000,4,1),datetime(2000,6,30)]);
    plot(btobjQ2,Type="bar")

    Figure contains an axes object. The axes object with title VaR Backtesting, xlabel Time contains 5 objects of type bar, stair, line. One or more of the lines displays its values using only markers These objects represent Equity, Normal95, Normal99, Normal95 exceptions, Normal99 exceptions.

    Plot esbacktest data as a line and highlight the exceptions as dot markers.

    load ESBacktestData.mat
    btobj = esbacktest(Returns,[VaRModel1 VaRModel2 VaRModel3], ...
           [ESModel1 ESModel2 ESModel3],'PortfolioID',"S&P", ...
           'VaRID',["Model 1","Model 2","Model 3"],'VaRLevel',VaRLevel);
    plot(btobj);

    Figure contains an axes object. The axes object with title ES Backtesting, xlabel Time contains 8 objects of type line. One or more of the lines displays its values using only markers These objects represent S&P, VaR: Model 1, VaR: Model 2, VaR: Model 3, ES: Model 1, ES: Model 2, ES: Model 3, Exceptions.

    Use the select function to drill down into the second quarter of year 2000 and highlight the exceptions against each VaR vector separately.

    load ESBacktestData.mat
    etobj = esbacktest(Returns,[VaRModel1 VaRModel2 VaRModel3], ...
           [ESModel1 ESModel2 ESModel3],'PortfolioID',"S&P", ...
           'VaRID',["Model 1","Model 2","Model 3"],'VaRLevel',VaRLevel, ...
           'Time',Dates);
    etobjQ2 = select(etobj,'TimeRange', ...
          [datetime(2000,4,1), datetime(2000,6,30)]);
    plot(etobjQ2, Type="bar");

    Figure contains an axes object. The axes object with title ES Backtesting, xlabel Time contains 10 objects of type bar, stair, line. One or more of the lines displays its values using only markers These objects represent S&P, VaR: Model 1, VaR: Model 2, VaR: Model 3, ES: Model 1, ES: Model 2, ES: Model 3, Model 1 exceptions, Model 2 exceptions, Model 3 exceptions.

    Input Arguments

    collapse all

    Backtest object, specified as either a varbacktest or an esbacktest object.

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: hPlot = plot(btobj,Type="bar")

    Axes object in which to plot. If you do not specify Parent, the plot function plots on the current Cartesian axes.

    Output plot type, specified as one of the following:

    • "line" — Plots the portfolio data as a line with the exceptions highlighted as dot markers.

    • "bar" — Plots the portfolio data as bars with the exceptions highlighted as circle markers.

    Example: hPlot = plot(btobj,Type="bar")

    Exception highlighting, specified as true (1) to display exception highlighting or false (0) to exclude it.

    Example: hPlot = plot(btobj,ShowExceptions=false)

    Version History

    Introduced in R2023b

    expand all