Black-Scholes for 17BII+ with 12 Digit Accuracy



Post: #2

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


Post: #3

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

Post: #4

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


Forum Jump: