Constructing and Analyzing Cash Flows Using the Finance Package
Overview
Constructing Cash Flows
Performing Sensitivity Analysis
See Also
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.
BasisPointSensitivity
-
calculate the basis point sensitivity of future cash flows
CashFlows
return the set of cash flows for a bond or a swap
Convexity
calculate the convexity of a set of cash flows
Duration
calculate the duration of a set of cash flows
FixedRateCoupon
construct a fixed-rate coupon on a term structure
InArrearIndexedCoupon
construct an in-arrear indexed coupon
InternalRateOfReturn
calculate the internal rate of return of a set of cash flows or a bond
ParCoupon
construct a coupon at par on a term structure
SimpleCashFlow
construct a simple cash flow at a given date
NetPresentValue
return the net present value of future cash flows
UpFrontIndexedCoupon
construct an up-front indexed coupon on a term structure
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.
restart;withFinance:
SetEvaluationDate⁡November 17, 2006;
December 8, 2006
payment_date:=AdvanceDate⁡3,Months,NewYork,convention=Following;
payment_date:=February 20, 2007
cash_flow1≔SimpleCashFlow100,payment_date;
cash_flow1:=100. on February 20, 2007
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.
cash_flow1amount;
100.
cash_flow1date;
date
eval⁡cash_flow1date;
moduleoptionrecord;exportweekDay,monthDay,month,year,format;end module
FormatDate⁡cash_flow1date;
February 20, 2007
You can calculate the net present value of this cash flow using any given discount rate.
NetPresentValue⁡cash_flow1,0.03;
99.22221858
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.
NetPresentValue⁡cash_flow1,0.03,referencedate=January 18, 2006;
96.78169326
You can also construct cash flows that represent fixed- and floating-rate coupon payments.
accrual_start_date:=AdvanceDate⁡7,Months;
accrual_start_date:=June 17, 2007
accrual_end_date:=AdvanceDate⁡accrual_start_date,3,Months;
accrual_end_date:=September 17, 2007
cash_flow2:=FixedRateCoupon⁡100,0.03,accrual_start_date,accrual_end_date;
cash_flow2:=.7561643836 on September 17, 2007
cash_flow2amount;
0.756164383561643838
FormatDate⁡cash_flow2date;
September 17, 2007
NetPresentValue⁡cash_flow2,0.05;
0.7253214642
Next construct a floating-rate coupon payment.
R:=BenchmarkRate⁡1,Months,CADLIBOR,0.05;
R:=moduleend module
r:=SquareRootDiffusion⁡0.045,0.05,0.2,0.03;
r:=_X
A:=SamplePath⁡r⁡t,t=0..5,timesteps=100;
PathPlot⁡A,axes=BOXED,gridlines=true,thickness=3;
start_history:=AdvanceDate⁡−101,Days;
start_history:=August 8, 2006
LoadHistory⁡R,start_history,A;
R⁡September 15, 2006;
0.05804387158
R⁡January 10, 2007;
0.04941992695
R⁡November 7, 2007;
cash_flow3:=InArrearIndexedCoupon⁡100,R,start_history,AdvanceDate⁡start_history,2,Years;
cash_flow3:=10.00751462 on August 8, 2008
NetPresentValue⁡cash_flow3,0.05;
9.180826599
NetPresentValue⁡cash_flow1,cash_flow2,cash_flow3,0.05;
108.6132094
Consider the set of cash flows defined previously.
cash_flows:=cash_flow1,cash_flow2,cash_flow3;
cash_flows:=cash_flow1,cash_flow2,cash_flow3
You can calculate the convexity of our set of cash flows using the 5% and the 4% rate.
Convexity⁡cash_flows,0.05;
0.3175386474
Convexity⁡cash_flows,0.04;
0.3208599232
Another sensitivity measure is the basis point sensitivity.
BasisPointSensitivity⁡cash_flows,0.05;
210.4591831
BasisPointSensitivity⁡cash_flows,0.04;
213.9014542
You can also compute 3 different types of duration at different market prices.
Duration⁡cash_flows,0.05;
0.3878554142
You can use the internal rate of return of your set of cash flows to compute the Macaulay duration.
ir:=InternalRateOfReturncash_flows,106;
ir:=0.1136419342
Duration⁡cash_flows, ir;
0.3776184776
Calendars worksheet, Term Structures worksheet, Stochastic Processes worksheet, Day Counters worksheet, Lattice Methods worksheet
Download Help Document