Constructing and Analyzing Cash Flows Using the Finance Package - Maple Programming Help

Home : Support : Online Help : Mathematics : Finance : Cash Flow Analysis : Finance/CashFlowAnalysis

Constructing and Analyzing Cash Flows Using the Finance Package

Overview

The Financial Modeling package provides a number of tools for constructing cash flows and for performing basic sensitivity analysis. Here is the list of related commands.

 - calculate the basis point sensitivity of future cash flows - return the set of cash flows for a bond or a swap - calculate the convexity of a set of cash flows - calculate the duration of a set of cash flows - construct a fixed-rate coupon on a term structure - construct an in-arrear indexed coupon - calculate the internal rate of return of a set of cash flows or a bond - construct a coupon at par on a term structure - construct a simple cash flow at a given date - return the net present value of future cash flows - construct an up-front indexed coupon on a term structure

Constructing Cash Flows

First construct a simple cash flow that pays 100 on the first business day three months from now. Set the global evaluation date to November 17, 2006.

 > $\mathrm{restart};$$\mathrm{with}\left(\mathrm{Finance}\right):$
 > $\mathrm{SetEvaluationDate}\left("November 17, 2006"\right);$
 ${"December 8, 2006"}$ (2.1)
 > $\mathrm{payment_date}:=\mathrm{AdvanceDate}\left(3,\mathrm{Months},\mathrm{NewYork},\mathrm{convention}=\mathrm{Following}\right);$
 ${\mathrm{payment_date}}{:=}{"February 20, 2007"}$ (2.2)
 > $\mathrm{cash_flow1}≔\mathrm{SimpleCashFlow}\left(100,\mathrm{payment_date}\right);$
 ${\mathrm{cash_flow1}}{:=}{\mathrm{100. on February 20, 2007}}$ (2.3)

Every cash flow is represented by a module with two exports: amount and date. The first one holds the amount to be paid. The second one holds the payment date.

 > ${\mathrm{cash_flow1}}_{\mathrm{amount}};$
 ${100.}$ (2.4)
 > ${\mathrm{cash_flow1}}_{\mathrm{date}};$
 ${\mathrm{date}}$ (2.5)
 > $\mathrm{eval}\left({\mathrm{cash_flow1}}_{\mathrm{date}}\right);$
 ${\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{option}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{record}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{export}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{weekDay}}{,}{\mathrm{monthDay}}{,}{\mathrm{month}}{,}{\mathrm{year}}{,}{\mathrm{format}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}$ (2.6)
 > $\mathrm{FormatDate}\left({\mathrm{cash_flow1}}_{\mathrm{date}}\right);$
 ${"February 20, 2007"}$ (2.7)

You can calculate the net present value of this cash flow using any given discount rate.

 > $\mathrm{NetPresentValue}\left(\mathrm{cash_flow1},0.03\right);$
 ${99.22221858}$ (2.8)

This is the value of our cash flow on November 17, 2006, which is the global evaluation date. You can use different dates by using appropriate term structures or by specifying the reference date explicitly.

 > $\mathrm{NetPresentValue}\left(\mathrm{cash_flow1},0.03,\mathrm{referencedate}="January 18, 2006"\right);$
 ${96.78169326}$ (2.9)

You can also construct cash flows that represent fixed- and floating-rate coupon payments.

 > $\mathrm{accrual_start_date}:=\mathrm{AdvanceDate}\left(7,\mathrm{Months}\right);$
 ${\mathrm{accrual_start_date}}{:=}{"June 17, 2007"}$ (2.10)
 > $\mathrm{accrual_end_date}:=\mathrm{AdvanceDate}\left(\mathrm{accrual_start_date},3,\mathrm{Months}\right);$
 ${\mathrm{accrual_end_date}}{:=}{"September 17, 2007"}$ (2.11)
 > $\mathrm{cash_flow2}:=\mathrm{FixedRateCoupon}\left(100,0.03,\mathrm{accrual_start_date},\mathrm{accrual_end_date}\right);$
 ${\mathrm{cash_flow2}}{:=}{\mathrm{.7561643836 on September 17, 2007}}$ (2.12)
 > ${\mathrm{cash_flow2}}_{\mathrm{amount}};$
 ${0.756164383561643838}$ (2.13)
 > $\mathrm{FormatDate}\left({\mathrm{cash_flow2}}_{\mathrm{date}}\right);$
 ${"September 17, 2007"}$ (2.14)
 > $\mathrm{NetPresentValue}\left(\mathrm{cash_flow2},0.05\right);$
 ${0.7253214642}$ (2.15)

Next construct a floating-rate coupon payment.

 > $R:=\mathrm{BenchmarkRate}\left(1,\mathrm{Months},\mathrm{CADLIBOR},0.05\right);$
 ${R}{:=}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}$ (2.16)
 > $r:=\mathrm{SquareRootDiffusion}\left(0.045,0.05,0.2,0.03\right);$
 ${r}{:=}{\mathrm{_X}}$ (2.17)
 > $A:=\mathrm{SamplePath}\left(r\left(t\right),t=0..5,\mathrm{timesteps}=100\right);$
 ${A}{:=}\left[\begin{array}{c}{\mathrm{1..1 x 1..101}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (2.18)
 > $\mathrm{PathPlot}\left(A,\mathrm{axes}=\mathrm{BOXED},\mathrm{gridlines}=\mathrm{true},\mathrm{thickness}=3\right);$ > $\mathrm{start_history}:=\mathrm{AdvanceDate}\left(-101,\mathrm{Days}\right);$
 ${\mathrm{start_history}}{:=}{"August 8, 2006"}$ (2.19)
 > $\mathrm{LoadHistory}\left(R,\mathrm{start_history},A\right);$
 > $R\left("September 15, 2006"\right);$
 ${0.05804387158}$ (2.20)
 > $R\left("January 10, 2007"\right);$
 ${0.04941992695}$ (2.21)
 > $R\left("November 7, 2007"\right);$
 ${0.04941992695}$ (2.22)
 > $\mathrm{cash_flow3}:=\mathrm{InArrearIndexedCoupon}\left(100,R,\mathrm{start_history},\mathrm{AdvanceDate}\left(\mathrm{start_history},2,\mathrm{Years}\right)\right);$
 ${\mathrm{cash_flow3}}{:=}{\mathrm{10.00751462 on August 8, 2008}}$ (2.23)
 > $\mathrm{NetPresentValue}\left(\mathrm{cash_flow3},0.05\right);$
 ${9.180826599}$ (2.24)
 > $\mathrm{NetPresentValue}\left(\left[\mathrm{cash_flow1},\mathrm{cash_flow2},\mathrm{cash_flow3}\right],0.05\right);$
 ${108.6132094}$ (2.25)

Performing Sensitivity Analysis

Consider the set of cash flows defined previously.

 > $\mathrm{cash_flows}:=\left[\mathrm{cash_flow1},\mathrm{cash_flow2},\mathrm{cash_flow3}\right];$
 ${\mathrm{cash_flows}}{:=}\left[{\mathrm{cash_flow1}}{,}{\mathrm{cash_flow2}}{,}{\mathrm{cash_flow3}}\right]$ (3.1)

You can calculate the convexity of our set of cash flows using the 5% and the 4% rate.

 > $\mathrm{Convexity}\left(\mathrm{cash_flows},0.05\right);$
 ${0.3175386474}$ (3.2)
 > $\mathrm{Convexity}\left(\mathrm{cash_flows},0.04\right);$
 ${0.3208599232}$ (3.3)

Another sensitivity measure is the basis point sensitivity.

 > $\mathrm{BasisPointSensitivity}\left(\mathrm{cash_flows},0.05\right);$
 ${210.4591831}$ (3.4)
 > $\mathrm{BasisPointSensitivity}\left(\mathrm{cash_flows},0.04\right);$
 ${213.9014542}$ (3.5)

You can also compute 3 different types of duration at different market prices.

 > $\mathrm{Duration}\left(\mathrm{cash_flows},0.05\right);$
 ${0.3878554142}$ (3.6)

You can use the internal rate of return of your set of cash flows to compute the Macaulay duration.

 > $\mathrm{ir}:=\mathrm{InternalRateOfReturn}\left(\mathrm{cash_flows},106\right);$
 ${\mathrm{ir}}{:=}{0.1136419342}$ (3.7)

 >
 ${0.3776184776}$ (3.8)