forked from sa-ccr/sa-ccr-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trade.py
43 lines (32 loc) · 1.03 KB
/
Trade.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
from math import exp, sqrt
class Trade(object):
def __init__(self,**kwargs):
for key,val in kwargs.items():
setattr(self,key,val)
def __repr__(self):
return "{}({})".format(self.__class__.__name__, self.__dict__)
@property
def isOption(self):
return getattr(self,'TradeType',False)=='Option'
@property
def AdjNotional(self):
if self.TradeGroup in ['IRD', 'Credit']:
return self.Notional*self.SupervDuration
else:
return self.Notional
@property
def SupervDuration(self):
if self.Ei < 1:
return sqrt(self.Ei)
else:
return (exp(-0.05*self.Si)-exp(-0.05*self.Ei))/0.05
@property
def MaturityFactor(self):
if self.Ei < 1:
return sqrt(self.Ei)
else:
return 1
def CalcSupervDelta(self, Superv_Vol=None):
# Only the simpler calculation is relevant for Non-options
if not Superv_Vol:
return 1 if self.BuySell=="Buy" else -1