Finance Package Commands for Term Structures
Overview
Discount Factor and Compound Factor
Interest Rate Calculations
References
See Also
The Finance package also provides for creating and manipulating term structures of interest rates as well as volatility term structures. Here is the list of relevant commands:
BenchmarkRate
-
calculate benchmark rate based on a specified calendar
CompoundFactor
return a compound factor for the specified date or time
DiscountCurve
construct a yield curve based on known discount rates
DiscountFactor
return a discount factor for the specified date or time
EquivalentRate
calculate equivalent interest rate
ForwardCurve
construct a yield curve based on known forward rates
ImpliedRate
calculate interest rate implied by a given compound factor
ParRate
compute par rates based on a given term structure
ZeroCurve
construct a yield curve based on known zero rates
ZeroRate
compute zero rates based on a given term structure
The DiscountFactor command returns the discount factor corresponding to the specified interest rate, compounding type, and frequency.
restart;withFinance:
DF1:=DiscountFactor⁡1,0.2,compounding = Continuous;
DF1:=0.8187307531
1ⅇ0.2;
0.8187307532
DF2:=DiscountFactor⁡1,0.2,compounding = Simple;
DF2:=0.8333333333
11+0.2;
0.8333333333
The CompoundFactor command returns the compound factor corresponding to the specified interest rate, compounding type, and frequency.
CF1:=CompoundFactor⁡1,0.2,compounding=Continuous;
CF1:=1.221402758
CF1⁢DF1;
0.9999999999
CF2:=CompoundFactor⁡1,0.2,compounding=Simple;
CF2:=1.200000000
1+0.2;
1.2
The EquivalentRate command generates a desired interest rate that is equivalent to the given interest rate.
Times:=1;
Times:=1
R1:=0.06;
R1:=0.06
R2:=EquivalentRate⁡R1,Continuous,Monthly,1;
R2:=0.06015025031
V1:=ⅇR1;
V1:=1.061836547
V2:=1+R21212;
V2:=1.061836548
The ImpliedRate command returns the implied rate for the given compound factor.
r1:=0.2;
r1:=0.2
CF1:=CompoundFactor⁡1,r1,compounding =Continuous;
r2:=ImpliedRate⁡CF1,1, Continuous;
r2:=0.1999999999
r3:=ln⁡CF1;
r3:=0.1999999999
The ZeroRate (short for zero-coupon rate) command computes the rate of interest earned on an investment that starts today and ends at a future certain day (in years).
times:=0,0.5,1,1.5,2;
times:=0,0.5,1,1.5,2
rates:=0.01,0.04,0.06,0.07,0.075;
rates:=0.01,0.04,0.06,0.07,0.075
Use the input interest rates at different maturity times to construct a piecewise function.
CurveFitting:-Splinetimes,rates,t,degree=1;
{0.01000000000+0.06000000000⁢tt<0.50.02000000000+0.04000000000⁢tt<10.04000000000+0.02000000000⁢tt<1.50.05500000000+0.01000000000⁢totherwise
F:=unapply⁡,t:
Plot_F:=plot⁡F⁡t,t=0..2:
ZC:=ZeroCurve⁡F:
First consider the case of continuously compounded interest.
ZR:=seq⁡ZeroRate⁡ZC,i100,compounding=Continuous,i=1..200;
ZR:=0.01060000000,0.01120000000,0.01180000000,0.01240000000,0.01300000000,0.01360000000,0.01420000000,0.01480000000,0.01540000000,0.01600000000,0.01660000000,0.01720000000,0.01780000000,0.01840000000,0.01900000000,0.01960000000,0.02020000000,0.02080000000,0.02140000000,0.02200000000,0.02260000000,0.02320000000,0.02380000000,0.02440000000,0.02500000000,0.02560000000,0.02620000000,0.02680000000,0.02740000000,0.02800000000,0.02860000000,0.02920000000,0.02980000000,0.03040000000,0.03100000000,0.03160000000,0.03220000000,0.03280000000,0.03340000000,0.03400000000,0.03460000000,0.03520000000,0.03580000000,0.03640000000,0.03700000000,0.03760000000,0.03820000000,0.03880000000,0.03940000000,0.04000000000,0.04040000000,0.04080000000,0.04120000000,0.04160000000,0.04200000000,0.04240000000,0.04280000000,0.04320000000,0.04360000000,0.04400000000,0.04440000000,0.04480000000,0.04520000000,0.04560000000,0.04600000000,0.04640000000,0.04680000000,0.04720000000,0.04760000000,0.04800000000,0.04840000000,0.04880000000,0.04920000000,0.04960000000,0.05000000000,0.05040000000,0.05080000000,0.05120000000,0.05160000000,0.05200000000,0.05240000000,0.05280000000,0.05320000000,0.05360000000,0.05400000000,0.05440000000,0.05480000000,0.05520000000,0.05560000000,0.05600000000,0.05640000000,0.05680000000,0.05720000000,0.05760000000,0.05800000000,0.05840000000,0.05880000000,0.05920000000,0.05960000000,0.06000000000,0.06020000000,0.06040000000,0.06060000000,0.06080000000,0.06100000000,0.06120000000,0.06140000000,0.06160000000,0.06180000000,0.06200000000,0.06220000000,0.06240000000,0.06260000000,0.06280000000,0.06300000000,0.06320000000,0.06340000000,0.06360000000,0.06380000000,0.06400000000,0.06420000000,0.06440000000,0.06460000000,0.06480000000,0.06500000000,0.06520000000,0.06540000000,0.06560000000,0.06580000000,0.06600000000,0.06620000000,0.06640000000,0.06660000000,0.06680000000,0.06700000000,0.06720000000,0.06740000000,0.06760000000,0.06780000000,0.06800000000,0.06820000000,0.06840000000,0.06860000000,0.06880000000,0.06900000000,0.06920000000,0.06940000000,0.06960000000,0.06980000000,0.07000000000,0.07010000000,0.07020000000,0.07030000000,0.07040000000,0.07050000000,0.07060000000,0.07070000000,0.07080000000,0.07090000000,0.07100000000,0.07110000000,0.07120000000,0.07130000000,0.07140000000,0.07150000000,0.07160000000,0.07170000000,0.07180000000,0.07190000000,0.07200000000,0.07210000000,0.07220000000,0.07230000000,0.07240000000,0.07250000000,0.07260000000,0.07270000000,0.07280000000,0.07290000000,0.07300000000,0.07310000000,0.07320000000,0.07330000000,0.07340000000,0.07350000000,0.07360000000,0.07370000000,0.07380000000,0.07390000000,0.07400000000,0.07410000000,0.07420000000,0.07430000000,0.07440000000,0.07450000000,0.07460000000,0.07470000000,0.07480000000,0.07490000000,0.07500000000
Plot_ZR:=Statistics:-PointPlot⁡ZR,xcoords=seq⁡i100,i=1..200:
plotsdisplay⁡Plot_ZR,Plot_F,thickness=3,axes=BOXED,gridlines=true;
Next consider the case of simply compounded interest.
ZRS:=seq⁡ZeroRate⁡ZC,i100,compounding=Simple,i=1..200;
ZRS:=0.01060056182,0.01120125449,0.01180208885,0.01240307571,0.01300422592,0.01360555031,0.01420705974,0.01480876506,0.01541067713,0.01601280683,0.01661516503,0.01721776262,0.01782061049,0.01842371956,0.01902710074,0.01963076495,0.02023472314,0.02083898624,0.02144356523,0.02204847106,0.02265371474,0.02325930726,0.02386525962,0.02447158286,0.02507828802,0.02568538614,0.02629288830,0.02690080559,0.02750914911,0.02811792997,0.02872715932,0.02933684830,0.02994700810,0.03055764989,0.03116878489,0.03178042432,0.03239257944,0.03300526151,0.03361848182,0.03423225168,0.03484658243,0.03546148541,0.03607697201,0.03669305363,0.03730974168,0.03792704762,0.03854498292,0.03916355907,0.03978278760,0.04040268005,0.04081907405,0.04123588351,0.04165311365,0.04207076971,0.04248885694,0.04290738059,0.04332634593,0.04374575824,0.04416562281,0.04458594495,0.04500672997,0.04542798320,0.04584970999,0.04627191567,0.04669460562,0.04711778521,0.04754145985,0.04796563492,0.04839031584,0.04881550806,0.04924121700,0.04966744814,0.05009420693,0.05052149886,0.05094932944,0.05137770418,0.05180662860,0.05223610825,0.05266614868,0.05309675547,0.05352793421,0.05395969049,0.05439202994,0.05482495819,0.05525848088,0.05569260369,0.05612733229,0.05656267239,0.05699862969,0.05743520992,0.05787241884,0.05831026220,0.05874874579,0.05918787541,0.05962765686,0.06006809599,0.06050919865,0.06095097070,0.06139341803,0.06183654655,0.06206780301,0.06229936591,0.06253123685,0.06276341743,0.06299590925,0.06322871393,0.06346183309,0.06369526833,0.06392902129,0.06416309359,0.06439748686,0.06463220274,0.06486724286,0.06510260887,0.06533830243,0.06557432518,0.06581067878,0.06604736489,0.06628438518,0.06652174131,0.06675943498,0.06699746785,0.06723584160,0.06747455794,0.06771361854,0.06795302512,0.06819277937,0.06843288300,0.06867333772,0.06891414526,0.06915530732,0.06939682565,0.06963870196,0.06988093800,0.07012353551,0.07036649623,0.07060982192,0.07085351432,0.07109757521,0.07134200635,0.07158680951,0.07183198646,0.07207753899,0.07232346888,0.07256977793,0.07281646793,0.07306354069,0.07331099800,0.07355884169,0.07380707357,0.07394452145,0.07408215440,0.07421997297,0.07435797770,0.07449616913,0.07463454782,0.07477311431,0.07491186914,0.07505081287,0.07518994605,0.07532926924,0.07546878298,0.07560848783,0.07574838435,0.07588847310,0.07602875464,0.07616922952,0.07630989832,0.07645076158,0.07659181989,0.07673307380,0.07687452389,0.07701617071,0.07715801485,0.07730005687,0.07744229735,0.07758473686,0.07772737598,0.07787021528,0.07801325535,0.07815649677,0.07829994010,0.07844358595,0.07858743489,0.07873148752,0.07887574441,0.07902020615,0.07916487334,0.07930974657,0.07945482644,0.07960011352,0.07974560843,0.07989131177,0.08003722412,0.08018334609,0.08032967828,0.08047622130,0.08062297574,0.08076994223,0.08091712136
ZR1:=ZeroRate⁡ZC,0.5,compounding=Continuous;
ZR1:=0.04000000000
ZR2:=ZeroRate⁡ZC,0.5,compounding=Simple;
ZR2:=0.04040268005
ZR2=2⁢ⅇ0.5⁢ZR1−1;
0.04040268005=0.040402680
Plot_ZRS:=Statistics:-PointPlot⁡ZRS,xcoords=seq⁡i100,i=1..200:
You can see that the simple rates are a little larger than corresponding continuous compounding rates.
plotsdisplay⁡Plot_ZRS,Plot_F,thickness=3,gridlines=true,axes=BOXED;
The forward rate is defined as the rate of interest implied by current zero rates for periods of time in the future.
ForwardRate⁡ZC,1,2;
0.09000000000
Set compounding = Continuous so that the input interest rates are continuous compounding.
ZR := [seq(ZeroRate(ZC, i/100, compounding = Continuous), i = 1..200)];
Construct a yield term structure based on a piecewise interpolation of the given zero rates.
IZC:=ZeroCurve⁡Jan-01-2006,July-01-2006,Jan-01-2007,Jan-01-2008,July-01-2008,rates:
IZR:=seq⁡ZeroRate⁡IZC,i100,compounding=Continuous,i=1..200;
IZR:=0.01028350086,0.01057503900,0.01087484226,0.01118314498,0.01150018810,0.01182621942,0.01216149376,0.01250627316,0.01286082708,0.01322543264,0.01360037479,0.01398594659,0.01438244938,0.01479019306,0.01520949630,0.01564068683,0.01608410165,0.01654008732,0.01700900022,0.01749120684,0.01798708406,0.01849701944,0.01902141154,0.01956067019,0.02011521688,0.02068548501,0.02127192029,0.02187498106,0.02249513866,0.02313287778,0.02378869685,0.02446310846,0.02515663969,0.02586983259,0.02660324457,0.02735744885,0.02813303488,0.02893060884,0.02975079409,0.03059423167,0.03146158077,0.03235351930,0.03327074435,0.03421397282,0.03518394190,0.03618140968,0.03720715576,0.03826198183,0.03934671231,0.04013243564,0.04045653022,0.04078324208,0.04111259233,0.04144460230,0.04177929345,0.04211668744,0.04245680611,0.04279967144,0.04314530563,0.04349373103,0.04384497018,0.04419904581,0.04455598082,0.04491579831,0.04527852155,0.04564417400,0.04601277933,0.04638436138,0.04675894418,0.04713655198,0.04751720920,0.04790094046,0.04828777059,0.04867772462,0.04907082777,0.04946710548,0.04986658338,0.05026928731,0.05067524333,0.05108447770,0.05149701689,0.05191288759,0.05233211672,0.05275473138,0.05318075892,0.05361022689,0.05404316309,0.05447959553,0.05491955243,0.05536306225,0.05581015370,0.05626085569,0.05671519738,0.05717320816,0.05763491767,0.05810035578,0.05856955258,0.05904253845,0.05951934397,0.06000000000,0.06009256173,0.06018526626,0.06027811380,0.06037110458,0.06046423881,0.06055751672,0.06065093853,0.06074450446,0.06083821474,0.06093206958,0.06102606921,0.06112021386,0.06121450374,0.06130893908,0.06140352010,0.06149824704,0.06159312011,0.06168813954,0.06178330556,0.06187861839,0.06197407826,0.06206968539,0.06216544002,0.06226134236,0.06235739266,0.06245359113,0.06254993800,0.06264643351,0.06274307789,0.06283987135,0.06293681414,0.06303390648,0.06313114861,0.06322854075,0.06332608314,0.06342377600,0.06352161958,0.06361961410,0.06371775979,0.06381605689,0.06391450564,0.06401310626,0.06411185900,0.06421076407,0.06430982173,0.06440903221,0.06450839573,0.06460791255,0.06470758289,0.06480740698,0.06490738508,0.06500751741,0.06510780422,0.06520824574,0.06530884221,0.06540959387,0.06551050096,0.06561156371,0.06571278238,0.06581415719,0.06591568840,0.06601737624,0.06611922095,0.06622122278,0.06632338196,0.06642569875,0.06652817337,0.06663080609,0.06673359714,0.06683654676,0.06693965520,0.06704292271,0.06714634952,0.06724993590,0.06735368207,0.06745758830,0.06756165482,0.06766588188,0.06777026973,0.06787481863,0.06797952881,0.06808440052,0.06818943402,0.06829462956,0.06839998738,0.06850550773,0.06861119087,0.06871703705,0.06882304652,0.06892921952,0.06903555632,0.06914205716,0.06924872231,0.06935555200,0.06946254650,0.06956970606,0.06967703094,0.06978452138,0.06989217765,0.07000000000
Plot_IZR:=Statistics:-PointPlotIZR,xcoords=seq⁡i100,i=1..200:
You will get the same results with the function CurveFitting:-Spline
plotsdisplay⁡Plot_IZR,Plot_ZR,Plot_F, axes = BOXED, gridlines = true;
Construct yield term structures based on piecewise interpolation of the given discount rates and forward rates.
IDC:=DiscountCurveJan-01-2006,July-01-2006,Jan-01-2007,Jan-01-2008,July-01-2008,rates;
IDC:=moduleend module
IFC:=ForwardCurveJan-01-2006,July-01-2006,Jan-01-2007,Jan-01-2008,July-01-2008,rates;
IFC:=moduleend module
Plot_IDC_IFC ≔ plotIDC, IFC, 0 .. 2, thickness = 2, color = red, green:
plotsdisplayPlot_IZR, Plot_IDC_IFC,axes = BOXED, gridlines = true;
John C. Hull, Options, Futures, and Other Derivatives, Prentice Hall, 2002
Stochastic Processes worksheet, Cash Flow Analysis worksheet, Day Counters worksheet, Lattice Methods worksheet, Calendars worksheet
Download Help Document