Documentation Center

  • Trial Software
  • Product Updates

cfplot

Visualize cash flows of financial instruments

Syntax

  • cfplot(CFlowDates,CFlowAmounts) example
  • h = cfplot(___,Name,Value) example
  • [h,axes_handle] = cfplot(___,Name,Value) example

Description

example

cfplot(CFlowDates,CFlowAmounts) plots a cash flow diagram for the specified cash flow amounts (CFlowAmounts) and dates (CFlowDates). The length and orientation of each arrow correspond to the cash flow amount.

example

cfplot(___,Name,Value) plots a cash flow diagram for the specified cash flow amounts (CFlowAmounts), dates (CFlowDates), and optional name-value pair arguments.

example

h = cfplot(___,Name,Value) returns the handle to the line objects used in the cash flow diagram.

example

[h,axes_handle] = cfplot(___,Name,Value) returns the handles to the line objects and the axes using optional name-value pair arguments.

Examples

expand all

Plot Cash Flows

Define CFlowAmounts and CFlowDates using the cfamounts function.

CouponRate = [0.06; 0.05; 0.03];
Settle = '03-Jun-1999';
Maturity = ['15-Aug-2000';'15-Dec-2000';'15-Jun-2000'];
Period = [1; 2; 2];  Basis = [1; 0; 0];
[CFlowAmounts, CFlowDates] = cfamounts(...
CouponRate, Settle, Maturity, Period, Basis)
CFlowAmounts =

   -4.8000    6.0000  106.0000       NaN       NaN
   -2.3352    2.5000    2.5000    2.5000  102.5000
   -1.4011    1.5000    1.5000  101.5000       NaN


CFlowDates =

      730274      730347      730713         NaN         NaN
      730274      730286      730469      730652      730835
      730274      730286      730469      730652         NaN

Plot all cash flows on the same axes, and label the first two.

cfplot(CFlowDates, CFlowAmounts, 'ShowAmnt', [1 2])

Group the second and third cash flows.

figure;
cfplot(CFlowDates, CFlowAmounts, 'Groups', {[2 3]}, 'ShowAmnt', 1);

Format the date axis and place ticks on actual cash flow dates.

figure;
cfplot(CFlowDates, CFlowAmounts, 'Groups', {[2 3]}, 'ShowAmnt', 1, ...
'DateFormat', 6, 'DateSpacing', 100);

Stack the cash flow arrows occurring on the same dates.

figure;
cfplot(CFlowDates, CFlowAmounts, 'Groups', {[2 3]}, 'ShowAmnt', 1, ...
'DateFormat', 6, 'DateSpacing', 100, 'Stacked', 1);

Form subplots of multiple groups and add titles using axes handles.

figure;
[h, axes_handle] = cfplot(CFlowDates, CFlowAmounts, ...
'Groups', {[1] [2 3]}, 'ShowAmnt', 1, 'Stacked', 2, ...
'DateSpacing', [1 60 2 100], 'DateFormat', [1 12 2 6]);
title(axes_handle(1), 'Group 1', 'FontWeight', 'bold');
title(axes_handle(2), 'Group 2', 'FontWeight', 'bold');

Plot Cash Flows for Swap

Define the swap using the swapbyzero function.

Settle = datenum('08-Jun-2010');
RateSpec = intenvset('Rates', [.005 .0075 .01 .014 .02 .025 .03]',...
'StartDates',Settle, 'EndDates',{'08-Dec-2010','08-Jun-2011',...
'08-Jun-2012','08-Jun-2013','08-Jun-2015','08-Jun-2017',...
'08-Jun-2020'}');
Maturity = datenum('15-Sep-2020');
LegRate = [.025 50];
LegType = [1 0]; % fixed/floating
LatestFloatingRate = .005;
[Price, SwapRate, AI, RecCF, RecCFDates, PayCF,PayCFDates] = ...
swapbyzero(RateSpec, LegRate, Settle, Maturity,'LegType',LegType,...
'LatestFloatingRate',LatestFloatingRate)
Price =

   -6.7258


SwapRate =

   NaN


AI =

    1.4575


RecCF =

  Columns 1 through 7

   -1.8219    2.5000    2.5000    2.5000    2.5000    2.5000    2.5000

  Columns 8 through 12

    2.5000    2.5000    2.5000    2.5000  102.5000


RecCFDates =

  Columns 1 through 6

      734297      734396      734761      735127      735492      735857

  Columns 7 through 12

      736222      736588      736953      737318      737683      738049


PayCF =

  Columns 1 through 7

   -0.3644    0.5000    1.4048    1.9823    2.8436    3.2842    3.8218

  Columns 8 through 12

    4.1733    4.5164    4.4666    4.8068  104.6743


PayCFDates =

  Columns 1 through 6

      734297      734396      734761      735127      735492      735857

  Columns 7 through 12

      736222      736588      736953      737318      737683      738049

Define CFlowDates and CFlowAmounts for the swap and generate a cash flow plot using cfplot.

CFlowDates = [PayCFDates;RecCFDates];
CFlowAmounts = [-PayCF;RecCF];
cfplot(CFlowDates, CFlowAmounts, 'Groups', {[1 2]});
xlabel('Numeric Cash Flow Dates');

Input Arguments

expand all

CFlowDates — Matrix of serial date numbers for cash flowsvector

Matrix of serial date numbers for cash flows, specified as a NINST-by-(Number of cash flows) matrix of cash flow dates in date numbers, with empty entries padded with NaNs.

Each row of the CFlowDates matrix represents an instrument so that CFlowDates(k,:) is the vector of cash flow dates for the kth instrument. Rows are padded with trailing NaNs if the number of cash flows is not the same for all instruments.

cfamounts can be used to generate CFlowDates.

Data Types: double

CFlowAmounts — Matrix of cash flow amounts vector

Matrix of cash flow amounts, specified as a NINST-by-(Number of cash flows) matrix of cash flow amounts, with empty entries padded with NaNs. The CFlowAmounts matrix must be the same size as CFlowDates.

cfamounts can be used to generate CFlowAmounts.

Data Types: double

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 single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: cfplot(CFlowDates,CFlowAmounts,'Groups',{[2 3]},'ShowAmnt',1,‘DateFormat',6,'DateSpacing',100)

'Groups' — Group cash flows'off' (default) | string with value 'off' or 'individual' | cell array of vectors

Group cash flows specified using the following values:

  • 'off' — Show all instruments in one set of axes, arranged from top to bottom.

  • 'individual' — Generate subplots and plot each instrument in its own axis.

  • GRP — Cell array of instrument groups, {Group1, Group2,... }. This generates subplots and plots each group in each axis. When specifying {Group1, Group2,... }, each Group must be mutually exclusive vectors of INSTIndex. Unspecified instruments are not shown in the grouped plot.

Data Types: double

'Stacked' — Stack arrows if cash flows are in same direction on same day Ignored when 'Groups' is 'off', otherwise 'off' (default) | string with value 'off', 'all', or 'GRPIndex'

Stack arrows if the cash flows are in the same direction on the same day specified using the following values:

  • 'off' — For all groups, all arrows originate from the horizontal line.

  • 'all' — For all groups, arrows are stacked if the cash flows are in the same direction on the same day.

  • 'GRPIndex' — For specified groups, arrows are stacked if the cash flows are in the same direction on the same day.

Data Types: double

'ShowAmnt' — Show amount on arrows'off' (default) | string with value 'off' or 'individual' | cell array of vectors |

Show amount on the arrows specified using the following values:

  • 'off' — Hide cash flow amounts on arrows.

  • 'all' — Show cash flow amounts on arrows.

  • [INSTIndex or GRPIndex] — Show cash flow amounts for the specified vector of instruments (when 'Groups' is 'off') or groups.

Data Types: double

'DateSpacing' — Control for date axis tick spacing'off' (default) | string with value 'off' or string TickDateSpace | numeric value for TickDateSpace

Control for data spacing specified by the following values:

  • 'off' — The date axis ticks are spaced regularly.

  • TickDateSpace — The date axis ticks are placed on actual cash flow dates. The ticks skip some cash flows if they are less than TickDateSpace apart.

Data Types: double

'DateFormat' — Date format'off' (default) | string with value 'off' or string DateFormNum | numeric value for DateFormNum

Date format is specified by the following values:

  • 'off' — The date axis tick labels will be in date numbers.

  • DateFormNum — The date format number (2 = 'mm/dd/yy', 6 = 'mm/dd', and 10 = 'yyyy'). Additional values for DateFormNum are as follows:

    DateFormNumExample
    2 03/01/00
    3Mar
    503
    603/01
    701
    8Wed
    9W
    102000
    1100
    12Mar00
    17Q1–00
    18Q1
    1901/03
    2001/03/00
    27Q1–2000
    28Mar2000
    292000–03–01

Data Types: double

Output Arguments

expand all

h — Handles to line objectsvector

Handles to line objects, returned as a NINST-by-3 matrix of handles to line objects, containing [hLines, hUArrowHead, hDArrowHead] where:

  • hLines — Horizontal and vertical lines used in the cash flow diagram

  • hUArrowHead — "Up" arrowheads

  • hDArrowHead — "Down" arrowheads

axes_handle — Handles to axes for plot or subplotsvector

Handles to axes for the plot or subplots, returned as a (Number of axes)-by-1 vector of handles to axes.

See Also

| |

Was this topic helpful?