-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOptionSwap.py
50 lines (40 loc) · 1.66 KB
/
OptionSwap.py
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
# OptionSwap.py
#
#
#.
import math
from HTLCProductsSim import *
from HTLCProductsPlot import *
class LongCall(Contract):
#
def __init__(self, underlying, strikeprice, premium=1.10):
#
if isinstance(underlying, str):
underlying = AssetBag(facevalue)
if isinstance(strikeprice, str):
strikeprice = Price(todayprice)
Contract.__init__(self)
escrow = underlying.valuation(strikeprice.pair.quote, [strikeprice])
self.addNAccounts(2)
self.accounts[0].name = "Bonded Call Option on %s" % str(underlying)
self.accounts[0].facevalue = premium * escrow
self.accounts[0].facevalue.label = "List Price"
self.accounts[1].name = "Short Call locking %s" % str(underlying)
self.addTranche(OracleHash.GE(strikeprice), underlying, 1, 0)
self.addTranche(OracleHash.GE(strikeprice), escrow, 0, 1)
self.strikeprice = strikeprice
if __name__ == "__main__":
C = LongCall(AssetBag("10000 BTS"), Price("0.05 BTS:USD"), 1.15)
P = Price.linspace(0, 0.10, 200, "BTS:USD")
C.doStudy(P[1:])
SP = ProductPlot(C, 0, "USD")
SP.draw()
SP.plt.plot([0],[0])
SP.plt.text(0.001, 825, "Paired HTLC \"Atomic Swap.\"\nPreimage provided by oracle\nif price above strike.", va="top")
SP.plt.text(0.001, 375, "Below Strike:\nReturn of 500 USD bond;\nOther party keeps 10000 BTS\nunderlying asset.", va="top")
SP.plt.text(0.055, 375, "Above Strike:\nDelivery of 10000 BTS; Other\nparty keeps 500 USD bond.", va="top")
SP.printtofile("LongCall.png")
SP = ProductPlot(C, 1, "USD")
SP.draw()
SP.plt.plot([0],[0])
SP.printtofile("ShortCall.png")