From: christie@extro.ucc.su.OZ.AU (Chris Tham) Newsgroups: comp.sources.hp48 Subject: v03i006: bond - Bond Pricing Application v1.0, Part01/02 Date: 25 Nov 91 03:20:50 GMT Followup-To: comp.sys.hp48 Organization: Univ. of North Carolina @ Wilmington Checksum: 2277052158 (verify with brik -cv) Submitted-by: Chris Tham Posting-number: Volume 3, Issue 6 Archive-name: bond/part01 HP-48SX Bond pricing application Version 1.0 Copyright (C) 1991 Chris Tham (christie@extro.ucc.su.oz.au) Introduction The BOND application allows your HP-48SX to act as a sophisticated bond pricing calculator, with features above and beyond that incorporated in most financial calculators, including ones manufactured by Hewlett-Packard. Indeed, it has features similar to bond pricing programs normally found on personal computers but retains the ease of use and flexibility of keystroke oriented bond pricing functions found on financial calculators. The BOND application has the following features: * Continuous display of all relevant bond pricing parameters (settlement and maturity dates, coupon and yield rates, bond price) on screen during data entry. * Calculates bond price using the Reserve Bank of Australia pricing formulae, with extensions to support bonds with different coupon payment frequencies and ex-interest periods. The RBA bond pricing formula is compatible with the Securities Industry Association's recommendations. * User can view the RBA bond pricing parameters (i, y, g, x, n, f, d) on screen to verify correct calculation. * Bond pricing is compatible with the bond functions available on the Hewlett-Packard range of financial calculators (including the HP-12C). * Calculation of bond price, capital price, accrued interest, implied yield, implied coupon, duration, modified duration, convexity, dispersion, PVBP (Price Value for a Basis Point change in yield). How to use the BOND Application The BOND application is normally stored in a subdirectory on the HP-48SX called `BOND'. To use the application, simply enter the directory and either type the `GO' command or press the [VAR] menu key and then press the soft key marked [GO] (this should be the left most soft key if you have not created any variables in this directory). The screen should now display something like the following: +-----------------------------------+ | | |{ HOME BOND } | |___________________________________| | | |Settlement 22-Nov-1991 | |Maturity 15-Nov-2000 | |Coupon 12.00% | |Yield 10.500% | |Bond Price 108.812 | |_____ _____ _____ _____ _____ _____| |SETTL MATU CPN YIELD PRICE RBA | |----- ----- ----- ----- ----- -----| +-----------------------------------+ The soft keys at the bottom corresponds to keys for * SETTLement date * MATUrity date * CouPoN rate per annum * YIELD of bond if held to maturity * Bond Gross (Total) PRICE * RBA (Reserve Bank of Australia) Pricing Parameters If you press the [NXT] (Next Menu) key, the soft menus will successively show the following soft keys: * [CAPL] (Calculate bond capital price) * [ACCR] (Calculate bond accrued interest) * [DUR] (Calculate bond duration) * [MDUR] (Calculate bond Modified duration) * [CONV] (Calculate bond convexity) * [DISPR] (Calculate bond dispersion) * [PVBP] (Calculate change in bond Price Value per 1 Basis Point change in yield) * [FREQ] (Change coupon frequency per annum) * [EXINT] (Change coupon ex-interest period) The settlement date is entered into the system by typing in a date as a number of the form DD.MMYYYY or MM.DDYYYY (depending on flag -42 in the calculator) and then pressing the [SETTL] key. The display should automatically update to show the new settlement date. The calculator does not check that the settlement date falls on a business day, or even if it is in the right format, so be careful. Entering a nonsensical date will cause the program to crash. The maturity date of the bond is similarly entered into the system by typing in the date in the current HP-48SX date format and then pressing the [MATU] key. The display will automatically update to show the new maturity date. The annual coupon rate must be entered as a percentage and then followed by the [CPN] key. The system displays coupon rates to 2 decimal places. The desired or actual yield to maturity of the bond must be entered as a percentage followed by the [YIELD] key. The system displays yields to three decimal places. The bond gross price per $100 face value is entered into the system by typing in the price and then pressing the [PRICE] key. The system displays the price to 3 decimal places. To calculate the bond price, implied yield or implied coupon, enter the remaining (known) parameters as outlined above and then calculate the unknown parameter by pressing the appropriate key preceeded by the left (orange) shift key. To retrieve the current value of any parameter, press the appropriate key preceeded by the right (blue) shift key. Let's run through the examples given in the HP-12C Owner's Handbook and Problem-Solving Guide (Reorder Number 00012-90001 Edition 1, Copyright (C) Hewlett-Packard Company 1982, July 1987) on pages 76-78. Example 1: What price should you pay on April 28, 1982 for a 6 3/4% US Treasury bond that matures on June 4, 1996, if you want a yield of 8 1/4%? Lets assume our current date format is DD.MMYYYY. Key sequence will be 28.041982 [SETTL] 4.061996 [MATU] 6 [SPC] 3 [SPC] 4 / + [CPN] 8 [SPC] 1 [SPC] 4 / + [YIELD] [Left Shift] [PRICE] The screen will show: +-----------------------------------+ | | |{ HOME BOND } | |___________________________________| | | |Settlement 28-Apr-1982 | |Maturity 4-Jun-1996 | |Coupon 6.75% | |Yield 8.250% | |Bond Price 90.311 | |_____ _____ _____ _____ _____ _____| |SETTL MATU CPN YIELD PRICE RBA | |----- ----- ----- ----- ----- -----| +-----------------------------------+ Hence, the total bond price is $90.311 per $100 face value (including accrued interest). Note that although the bond price is given to three decimal places the full precision is stored internally. To find out the capital and accrued interest components, press the [NXT] key. The screen will clear and the soft keys will now say [CAPL] [ACCR] [DUR] [MDUR] [CONV] [DISPR]. Press the [CAPL] key, then the [ACCR] key. Depending on the setting of your numeric display format (mine is on FIX 2) you should get something like "Capital: 87.62" on level 2 of your stack and "AccrInt: 2.69" on level 1. Pressing the [PREV] key ([Left Shift] [NXT]) will bring you back to the previous soft key menu and pressing [Left Shift] [SETTL] will restore the screen display of bond parameters. The RBA pricing parameters for the above bond can be obtained by pressing the [RBA] key which should show something like: +-----------------------------------+ |n 28 | |f 37 | |d 182 | |x 1 | |g 3.375 | |i .04125 | |v .960384153661 | |_____ _____ _____ _____ _____ _____| |SETTL MATU CPN YIELD PRICE RBA | |----- ----- ----- ----- ----- -----| +-----------------------------------+ Pressing any key (except the [ON] key, of course!) will restore the bond parameter screen. Example 2: The market is quoting 88 3/8% for the bond described in Example 1. What yield will that provide? We first need to find the gross price corresponding to the quoted capital price, then we can find the implied yield. The key sequence is 88 [SPC] 3 [SPC] 8 / + [NXT] [ACCR] + [PREV] [PRICE] [Left Shift] [YIELD] After a few seconds, the display will show that the corresponding yield is 8.151%. To calculate bond characteristics such as duration, modified duration, convexity, dispersion, and PVBP simply press the appropriate key. For the bond given in example 2, the relevant values are Duration = 8.71 Modified Duration = 8.37 Convexity = 98.66 Dispersion = 5.16 PVBP = 0.08 Note that PVBP/PRICE * 10,000 approximately equals the Modified duration. This is a consequence of the method used to calculate Modified duration. The last two soft keys ([FREQ] and [EXINT]) allows you to change the coupon payment frequency per annum and ex interest period of the bond. By default, FREQ = 2 and EXINT = 15. Pressing either [FREQ] or [EXINT] will display the current settings of FREQ and EXINT respectively. To enter a new coupon frequency, just type the number of coupon payments per year and press [Left Shift] [FREQ] and to enter a new ex interest period, just type the minimum number of days to the next interest period from settlement date before the bond goes ex-interest then press [Left Shift] [EXINT]. The BOND application currently does not handle bonds calculated on a 30/360 day basis. Installing the BOND Application Upload BOND.ASC, BOND.BIN or BOND.48 into the directory where you wish to place the 'BOND' directory on the HP-48SX (normally the HOME directory). Documentation The file `bond.tex' contains LaTeX source code for a derivation of the formulae used in implementing the BOND application. The file `bond.ps' is the PostScript file generated by running LaTeX on bond.tex and then converting the DVI file to PostScript (using a program called dvips). Just send `bond.ps' to a PostScript printer to get a hardcopy of the documentation. %%HP: T(3)A(D)F(.); DIR GO \<< BDISP BMENU TMENU \>> SETTLE 22.111991 MATUR 15.112 CPN 12 YIELD 10.5 BPRICE 108.812374617 EXINT 15 FREQ 2 BOND \<< IF N 1 < THEN 100 CPN FREQ / + YIELD 100 / FREQ / F * D / 1 + / ELSE CPN FREQ / YIELD 100 / FREQ / DUP 1 + INV DUP N ^ \-> G I V VN 'V^(F/ D)*(G*(X+(1-VN)/I)+ 100*VN)' END \>> ACCR \<< CPN FREQ / D F - D / * \>> DUR \<< CPN FREQ / YIELD 100 / FREQ / DUP 1 + INV DUP N ^ F D / \-> G I V VN FD 'V^FD/FREQ*(G/I*((1 -VN)/(I*V)-N*VN)+G* FD*(X+(1-VN)/I)+100 *(N+FD)*VN)/BOND' \>> MDUR \<< DUR YIELD 100 / FREQ / 1 + / \>> CONVEX \<< CPN FREQ / YIELD 100 / FREQ / DUP 1 + INV F D / \-> G I V FD 'V^(FD+2)* (G*\GS(J=0,N,(J+F/D)* (J+FD+1)*V^J)+100*( N+F/D)*(N+F/D+1)*V^ N)/BOND/FREQ/FREQ' \>> DISPER \<< DUR DUP DUP * SWAP FREQ / + CONVEX YIELD 100 / FREQ / 1 + DUP * * SWAP - \v/ \>> PVBP \<< BOND .01 'YIELD' STO+ BOND - -.01 'YIELD' STO+ \>> YAPPROX \<< CPN FREQ / 100 BPRICE - N F D / + / + 100 BPRICE + 2 / / 100 * FREQ * \>> Bpar \<< -12 FREQ / MATUR DMY\-> DROP DROP SETTLE DMY\-> DROP DROP - IF DUP 1 > THEN 1 - DUP NEG MATUR SWAP YADD SWAP FREQ * 1 - ELSE DROP MATUR -1 END 'N' STO \-> M C \<< C WHILE DUP SETTLE DDAYS 0 < REPEAT DUP 'C' STO M MADD 'N' INCR DROP END C DDAYS 'D' STO SETTLE C DDAYS DUP 'F' STO EXINT \>= 1 0 IFTE 'X' STO \>> \>> D 182 F 175 N 17 X 1 BMENU { { "SETTLE" { \<< 'SETTLE' STO BDISP \>> \<< BDISP \>> \<< SETTLE "Settle" \->TAG \>> } } { "MATUR" { \<< 'MATUR' STO BDISP \>> \<< BDISP \>> \<< MATUR "Mat" \->TAG \>> } } { "CPN" { \<< 'CPN' STO BDISP \>> \<< BDISP \>> \<< CPN "Coupon" \->TAG \>> } } { "YIELD" { \<< 'YIELD' STO BDISP \>> \<< Bpar 'BOND- BPRICE' 'YIELD' YAPPROX ROOT DROP BDISP \>> \<< YIELD "Yield" \->TAG \>> } } { "PRICE" { \<< 'BPRICE' STO BDISP \>> \<< Bpar BOND 'BPRICE' STO BDISP \>> \<< BPRICE "Price" \->TAG \>> } } { "RBA" \<< RDISP BDISP \>> } { "CAPL" \<< Bpar BOND ACCR - "Capital" \->TAG \>> } { "ACCR" \<< Bpar ACCR "AccrInt" \->TAG \>> } { "DUR" \<< Bpar DUR "Dur" \->TAG \>> } { "MDUR" \<< Bpar MDUR "MDur" \->TAG \>> } { "CONV" \<< Bpar CONVEX "Convexity" \->TAG \>> } { "DISPR" \<< Bpar DISPER "Dispersion" \->TAG \>> } { "PVBP" \<< Bpar PVBP "PVBP" \->TAG \>> } FREQ EXINT } RDISP \<< RCLF STD CLLCD Bpar "n " N \->STR + 1 DISP "f " F \->STR + 2 DISP "d " D \->STR + 3 DISP "x " X \->STR + 4 DISP "g " CPN FREQ / \->STR + 5 DISP YIELD 100 / FREQ / "i " OVER \->STR + 6 DISP "v " SWAP 1 + INV \->STR + 7 DISP STOF 0 WAIT DROP \>> BDISP \<< CLLCD RCLF "Settlement " SETTLE DSTR + 3 DISP "Maturity " MATUR DSTR + 4 DISP "Coupon " 2 FIX CPN \->STR + "%" + 5 DISP "Yield " 3 FIX YIELD \->STR + "%" + 6 DISP "Bond Price " BPRICE \->STR + 7 DISP 2 FREEZE STOF \>> DSTR \<< RCLF SWAP DMY\-> STD \->STR "-" + { "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec" } ROT GET + "-" + SWAP + SWAP STOF \>> YADD \<< SWAP DMY\-> \-> Y1 Y M D \<< Y Y1 + M D \->DMY \>> \>> MADD \<< SWAP DMY\-> \-> M1 Y M D \<< M M1 + WHILE DUP 1 < REPEAT 12 + 'Y' DECR DROP END WHILE DUP 12 > REPEAT 12 - 'Y' INCR DROP END Y SWAP D \->DMY \>> \>> \->DMY \<< \-> Y M D \<< Y 10000 / M + 100 / D + \>> \>> DMY\-> \<< \-> D \<< D IP D FP 100 * DUP IP SWAP FP 10000 * 3 ROLLD IF -42 FS? THEN SWAP END \>> \>> END christie@extro.ucc.su.oz.au