Modelo Black-Scholes para a HP-12C

Opcode #OperationRemarks
0.196854
STO 3N(x) 1st coefficient
0.115194
STO 4N(x) 2nd coefficient
0.000344
STO 5N(x) 3rd coefficient
0.019527
STO 6N(x) 4th coefficient
f P/RGoes into programming mode
f CLEAR PRGMClears programming memory
01RCL nt
02g vxvt
03RCL PMT100.s
04%vt.s
05STO 2Let mem2 = vt.s
06RCL nt
07RCL i100.r
08%r.t
09RCL 2vt.s
102
11Yxt.s2
122
13÷t.s2/2
14+(r + s2/2).t
15RCL PVS
16RCL FVK
17÷S/K
18g LNln(S/K)
19+ln(S/K) + (r + s2/2).t
20RCL 2vt.s
21÷d1
22STO 1Let mem1 = d1
23STO 0Let mem0 = d1
24RCL 2vt.s
25STO – 0Let mem0 = d1 – vt.s = d2
26RCL 0swap mem0 and mem1
27RCL 1
28STO 0
29R?
30STO 1swap done
31RCL 0Get d1 or d2 (whichever is at mem0) and
324calculate cummulative normal distribution
33Yxd4
34RCL 6c4
35x?y
36×c4.d4
37g LSTxd4
38g vxd2
39RCL 4c2
40x?y
41×c2.d2
42g LSTxd2
43g vxd (guaranteed to be positive)
44RCL 3c1
45×c1.d
46+c1.d+c2.d2
47+c1.d+c2.d2+c4.d4
48RCL 0d
496
50Yxd6
51g vxd3 (guaranteed to be positive)
52RCL 5c3
53×c3.d3
54+c1.d+c2.d2+c3.d3+c4.d4
551
56+1+c1.d+c2.d2+c3.d3+c4.d4
574
58CHS
59Yx(1+c1.d+c2.d2+c3.d3+c4.d4)-4
602
61÷(1+c1.d+c2.d2+c3.d3+c4.d4)-4/2
620Current result is 1-N(abs(d))
63RCL 0
64g x=yd < 0?
65GTO 72d<0, N(d)=1-N(-d), we are done, jump ahead
66R?d>0, need to do 1-(1-(N(d))
67R?Restore 1-N(d) into register X
68CHS
691
70+N(d) corrected, we are done
71GTO 74Jump ahead
72R?Restore N(d) into register X
73R?
74STO 0Let mem0 = N(d)
75RCL 2mem2 is vt.s at 1st round, zero otherwise
76g x=0mem2 is zero?
77GTO 81Jump to calculate call and put
780
79STO 2Let mem2 = 0
80GTO 26Go back to 2nd round of N(d) calculation
81RCL PVS
82STO × 1Let mem1 = S.N(d1)
83RCL nt
84RCL ir
85%r.t
86CHS-r.t
87g exe-r.t
88RCL FVK
89×K.e-rt
90STO × 0Let mem0 = K.e-rt.N(d2)
91RCL PVS
92K.e-rt – S
93RCL 1S.N(d1)
94RCL 0K.e-rt.N(d2)
95S.N(d1) – K.e-rt.N(d2) = Call
96+Call + K.e-rt – S = Put
97g LSTxCall at X, put at Y
f P/RBack to normal mode

Como usar o modelo Black-Scholes na HP-12C

  • Fill “i” register with the interest, as usual (e.g. 12 for 12% per year).
  • Fill “PV” with the spot value of the underlying asset.
  • Fill “PMT” with the volatility, as a percentage (e.g. 25 for 25% per year).
  • Fill “n” with the time to expiration. Use the same time unit as interest and volatility. If you enter interest and volatility as % per year, you must supply the time to expiration expressed in years (e.g. 2 months = 0.1666 years).
  • Fill “FV” with the strike of the option.
  • Press R/S to get the call value. It takes several seconds.
  • The shown value is the call value. Press x?y to see the put value, and again to go back to call value.

The option parameters are not changed during calculation, so you can fiddle with themand press R/S as many times as you want.

Notas da implementação do modelo Black-Scholes

Não foi fácil criar uma equação que se adequasse a HP-12C, já que um programa para ela pode ter até 99 passos, a linguagem de programação é “pobre” e usar os 99 passos reduz o números de posições de memória disponíveis, o que por sua vez torna o programa mais complicado e força o uso de mais opcodes.

A função mais complicada é a distribuição normal cumulativa, que foi implementada usando a aproximação racional com precisão de 4 dígitos decimais. O coeficiente dessa função é adicionado como parte do programa mas ele precisa de posições de memória ao invés do programa. Uma função melhor com sete coeficientes não pode ser utilizada devido ao opcode e limites de memória.

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Carrinho de compras