%%HP: T(3)A(D)F(.);
@ BOND by Chris Tham
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
