forked from tchernicum/bcapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bc-binary-option.m
71 lines (43 loc) · 1.85 KB
/
bc-binary-option.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(*
Created to separate out binary/barrier options, which can be handled
easier than box options (ie, no numerical integration required
For this file, times are in years to correspond to volatility
*)
bincallvalue[p0_, v_, s_, e_] =
1-CDF[NormalDistribution[Log[p0],Sqrt[e]*v], Log[s]]
(* formula below was wrong, may still be *)
barriervalue[p0_, v_, s_, e_] =
1-(2*CDF[NormalDistribution[Log[p0],Sqrt[e]*v*Sqrt[2]], Log[s]]-1)
(*
Suppose I purchased $n worth of a parity at price p. My profit at
price p1 would be n*(1-p/p1).
Now, if I hedge this profit against a binary option (losing my entire
profit if the option goes in money), I make:
*)
binhedge[p_, n_, p0_, v_, s_, e_] = n*(1-p/s)*bincallvalue[p0,v,s,e]
barhedge[p_, n_, p0_, v_, s_, e_] = n*(1-p/s)*barriervalue[p0,v,s,e]
(*
Example: I bought 100K USDJPY at 78 and think it won't reach 79; if
USDJPY reaches 79, I've made $1265.82, so I bet that amount that it
won't. Assume vol = .1 and expiration one week from now; below shows I
could make $226.24 right now
binhedge[78, 100000, 78, .1, 79, 7/365.2425]
*)
(*
Of course, if I don't care about the strike price, I can maximize
profit (bs = best strike)
*)
bsbinhedge[p_, n_, p0_, v_, e_] = Maximize[binhedge[p,n,p0,v,s,e],s]
bsbarhedge[p_, n_, p0_, v_, e_] = Maximize[barhedge[p,n,p0,v,s,e],s]
(*
And if I'm not picky about expiration, I can maximize profit/time (bt
= best time)
Mathematica handles nested maximize poorly, so using 2-variable maximize
*)
bsbtbinhedge[p_, n_, p0_, v_] = Maximize[binhedge[p, n, p0, v, s, e]/e, {s,e}]
bsbtbarhedge[p_, n_, p0_, v_] = Maximize[barhedge[p, n, p0, v, s, e]/e, {s,e}]
showit := Module[{},
Export["/tmp/math.jpg",%, ImageSize->{800,600}]; Run["display /tmp/math.jpg&"]]
(* If oanda is willing to pay you x return on x0 investment, the
percentage change is of a miss is ... *)
oanda2pct[x0_, x_] = x0/x