-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContract.py
More file actions
73 lines (60 loc) · 2.44 KB
/
Copy pathContract.py
File metadata and controls
73 lines (60 loc) · 2.44 KB
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
71
72
73
from datetime import datetime
class Contract:
def __init__(self, conid, asset_class, currency, mkt_price):
self.conid = conid
self.asset_class = asset_class
self.currency = currency
self.mkt_price = mkt_price
self.last_update = self._date_and_time()
self.und_conid = conid # und means underlying, default for STK
# for option contract
self.ticker = None
self.expiry = None
self.strike = None
self.put_or_call = None
self.multiplier = None
self.und_price = None # und means underlying
# moneyness
self.dte = None
self.intrinsic = None
self.extrinsic = None
self.ann_extrinsic = None
self.target = None
@staticmethod
def _date_and_time():
now = datetime.now()
return now.strftime("%d/%m/%Y %H:%M:%S")
@staticmethod
def _get_ann_target(dte):
# TODO: adjust ann_target by dte
return 0.1
def _set_moneyness(self):
expiry = datetime.strptime(self.expiry, "%Y%m%d")
self.dte = (expiry - datetime.now()).days
if self.put_or_call == "P":
self.intrinsic = max(0, -self.und_price+self.strike)
else:
self.intrinsic = max(0, self.und_price-self.strike)
self.extrinsic = self.mkt_price - self.intrinsic
self.ann_extrinsic = self.extrinsic/self.strike * (365/self.dte)
ann_target = self._get_ann_target(self.dte)
self.target = ann_target * self.strike * self.dte/365
self.target = round(self.target, 2)
def set_mkt_price(self, mkt_price):
self.last_update = self._date_and_time()
self.mkt_price = mkt_price
if self.asset_class == "OPT" and self.mkt_price is not None and self.und_price is not None:
self._set_moneyness()
def set_und_price(self, und_price):
self.last_update = self._date_and_time()
self.und_price = und_price
if self.asset_class == "OPT" and self.mkt_price is not None and self.und_price is not None:
self._set_moneyness()
def set_detail(self, detail):
self.ticker = detail['ticker']
if self.asset_class == "OPT":
self.expiry = detail['expiry']
self.strike = detail['strike']
self.put_or_call = detail['putOrCall']
self.multiplier = detail['multiplier']
self.und_conid = detail['undConid'] # und means underlying