Black-Scholes for 17BII+ with 12 Digit Accuracy



#4

Black-Scholes for 17BII+ with 12 Digit Accuracy

Tony Hutchins has an article in DataFile V24N2pp13-21 Wronski's Lex Suprema on the HP-12C that presents a Black-Scholes program accurate to 12 digits. Tony has graciously given me permission to post the HP 17BII+ version here. The INIT.VARS equation is to initialize all one-letter variables to allow L() and G() to work properly. I also included run-times for this version; as strike prices become less probable, times increase to around 9 minutes.


PS=52, PE=47, RF%=0.5, T=6, S=0.2054


INIT.VARS:A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+Z

BLK.SCHLS,11.9:
0xPSxPExRF%xTxS+IF(S(CALLV):
0xL(X:(LN(PS÷PE)+(RF%÷100+S^2÷2)xT)÷S÷SQRT(T))
xL(Y:G(X)-SxSQRT(T))+PSxIF(G(X)^2>49:
IF(G(X)>0:1:0):.5+G(X)xEXP(-(G(X)^2)÷2)÷SQRT(2xPI)x(1+
SIGMA(N:1:10xABS(G(X))+IF(ABS(G(X))<1.4:5:0):1:(2xG(X)^2)^NxFACT(N)÷FACT(2xN+1))))
-PExEXP(-RF%xT÷100)xIF(G(Y)^2>49:
IF(G(Y)>0:1:0):.5+G(Y)xEXP(-(G(Y)^2)÷2)÷SQRT(2xPI)x(1+
SIGMA(N:1:10xABS(G(Y))+IF(ABS(G(Y))<1.4:5:0):1:(2xG(Y)^2)^NxFACT(N)÷FACT(2xN+1))))
-CALLV:
-PS+PExEXP(-RF%xT÷100)+CALLV-PUTV)

                    Exact Call        Calculated Call   Error           Execution Time
PE=47, d1=.6957 13.208118745061 13.208118745100 -3.92344E-11 39 sec
PE=37, d1=.9876 18.961966848997 18.961966849000 -3.1477E-12 58 sec
PE=22, d1=2.0209 30.902477228531 30.902477228600 -6.94556E-11 1 min 34 sec
PE=13, d1=3.0666 39.393284752365 39.393284752200 1.64839E-10 2 min 50 sec
PE=02, d1=6.7869 50.059108932926 50.059108932900 2.57856E-11 8 min 55 sec
PE=01, d1=8.1645 51.029554466452 51.029554466500 -4.85088E-11 7 sec

An alternative is to use a 5th order polynomial approximation that always executes in 13 seconds, but only has 7.4 digits of accuracy:


BLK.SCHLS,7.4:
0xPSxPExRF%xTxS+IF(S(CALLV):
0xL(B:1÷(1+.2316419xABS(L(D:L(C:(LN(PS÷PE)
+(RF%÷100+S^2÷2)xT)÷S÷SQRT(T))-SxSQRT(T)))))
xL(A:1÷(1+.2316419xABS(G(C))))+PSxABS(IF(G(C)<0:0:-1)
+(.254829592xG(A)-.284496736xG(A)^2+1.421413741xG(A)^3
-1.453152027xG(A)^4+1.061405429xG(A)^5)xEXP(-G(C)^2÷2)÷2)
-PExEXP(-RF%xT÷100)xABS(IF(G(D)<0:0:-1)
+(.254829592xG(B)-.284496736xG(B)^2+1.421413741xG(B)^3
-1.453152027xG(B)^4+1.061405429xG(B)^5)xEXP(-G(D)^2÷2)÷2)
-CALLV:
-PS+PExEXP(-RF%xT÷100)+CALLV-PUTV)

                   Exact Call        Calculated Call   Error           Execution Time
PE=47, d1=.6957 13.208118745061 13.208118448700 2.96361E-07 13 sec
PE=37, d1=.9876 18.961966848997 18.961966877200 -2.82031E-08 13 sec
PE=22, d1=2.0209 30.902477228531 30.902481308000 -4.07947E-06 13 sec
PE=13, d1=3.0666 39.393284752365 39.393281519000 3.23336E-06 13 sec
PE=02, d1=6.7869 50.059108932926 50.059108932900 2.57856E-11 11 sec
PE=01, d1=8.1645 51.029554466452 51.029554466500 -4.85088E-11 11 sec


Bob


#5

Gidday Bob! This really seems to highlight yet another issue with the 17BII+. I don't dispute your results, but on the 19BII execution time is not really an issue. Your excellently chosen worst case for the algorithm with d1 & d2 up there just under 7 executes in 30 seconds on the 19BII - about 18 times faster than on the 17BII+. The case for d1 near 3 executes in 13 seconds and the rest in 10 seconds or less.
The program takes about 15 seconds to "verify" on the 19BII so is fairly cumbersome to start, but exceutes well. In practice d1 and d2 will be under 3 so the execution time will be under about 10 seconds. Anything taking longer is probably a theoretical case :-) Cheers, and thanks for your contributions and ability to make the 17BII+ work! Tony

#6

Bob, me again, only a day or two late :-)

This may work on the 17BII+, as it uses L() only, not G() and
does not use IF(S(..., so we limit the things that can go awry
:-).It works on a 19BII.

It uses the same 5th degree polynomial approximation as your
BLK.SCHLS,7.4, just evaluated differently.

BLK.SCHLS:0*L(D1:(LN(PS/PE)+(RF%/100+S^2/2)*T)/S/SQRT(T))
*L(D2:D1-S*SQRT(T))*D2*PUTV+PS*ABS(IF(D1<0;0;-1)
+SIGMA(I:1:5:1:ITEM(NORM:I)*SPPV(23.16419*ABS(D1):I))
/EXP(D1^2/2))-PE/EXP(RF%*T/100)*ABS(IF(D2<0:0:-1)
+SIGMA(I:1:5:1:ITEM(NORM:I)*SPPV(23.16419*ABS(D2):I))
/EXP(D2^2/2))-CALLV+0*L(PUTV:CALLV-PS+PE/EXP(RF%*T/100))

The first page of Solver shows, here on the 19BII:

PS  PE  RF%  S     T MORE
These are the five *inputs*.

The second page shows:

D1  D1  PUTV CALLV   MORE

These are the 4 *outputs*. They are all calculated
simultaneously, by pressing CALLV. Then RCL PUTV shows PUTV
and likewise for D1 and D2. It is often useful to have D1 and
D2 available.**Only CALLV is "solved for"as such**. This is
the main difference - we don't first solve for CALLV and then
for PUTV, we just do the one solve.

NORM is a 5 element SUM List:

1      0.127414796
2 -0.142248368
3 0.710706871
4 -0.726576013
5 0.530702714
-----------
Total 0.500000000

SUM Lists are quite handy - here it reduces the typing required for the
equation quite a bit (by about a third) - maybe the nearest thing we have
to subroutines :-)

For the inputs: PS=52, RF%=.5, S=.2054 and T=6, and the various
PE you tabulate, this produces basically the same results you
list. RCL PUTV shows zero for the last 2 examples (PE=2 and
PE=1). Even for PE=13, RCL PUTV shows only 1 cent. For PE=47
D1 is .5121. PE=45 specifies the same example used on the HP
web site for the 17BII Black Scholes equation. The above
equation is similar to one given in my "Wronski" article in
DataFile. It does slow down Solver slightly as it is
calculating more than one output at once, and I don't know if
this is possible on the 17BII+ :-)

Cheers,
Tony


Possibly Related Threads…
Thread Author Replies Views Last Post
  17BII & 17BII+ Discounted Payback Period Revisited Tom Neudorfl 8 2,873 11-25-2013, 10:28 AM
Last Post: Don Shepherd
  HP PRIME - Bode and Black plots - first attempt dg1969 0 1,053 10-20-2013, 01:32 PM
Last Post: dg1969
  How much accuracy does one actually need? Matt Agajanian 23 5,772 08-26-2013, 12:46 PM
Last Post: Kimberly Thompson
  Creeping black pattern on HP-11C screen Larry Gagnon 6 2,105 04-12-2013, 10:09 AM
Last Post: Peter Murphy (Livermore)
  Estimating accuracy in finite precision computations mpi 17 4,367 02-22-2013, 09:44 AM
Last Post: mpi
  HP 12 C simple interest calcuation sam 6 2,020 01-16-2013, 10:22 AM
Last Post: fhub
  SpeedUI: Version 12.05 Holiday Edition released:-) Raymond Del Tondo 3 1,656 12-30-2012, 02:18 AM
Last Post: Han
  What are the most popular functions? (Poll until 18.12.) Walter B 62 12,546 12-18-2012, 08:18 AM
Last Post: Walter B
  HP 48GX with Black LCD - S/N ID Jeff Kearns 4 1,835 12-15-2012, 03:55 PM
Last Post: aurelio
  Happy 12/12/12 Day! Eddie W. Shore 6 1,968 12-15-2012, 11:18 AM
Last Post: Marcus von Cube, Germany

Forum Jump: