You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
758 B
31 lines
758 B
|
8 years ago
|
'''
|
||
|
|
'''
|
||
|
|
|
||
|
|
class Trade:
|
||
|
|
'''
|
||
|
|
'''
|
||
|
|
|
||
|
|
LONG = 1
|
||
|
|
SHORT = 2
|
||
|
|
|
||
|
|
def __init__(self, entry_price, exit_price, direction = LONG):
|
||
|
|
'''
|
||
|
|
Constructor
|
||
|
|
'''
|
||
|
|
|
||
|
|
self.direction = direction
|
||
|
|
self.entry_price = entry_price
|
||
|
|
self.exit_price = exit_price
|
||
|
|
|
||
|
|
|
||
|
|
def pnl(self):
|
||
|
|
if self.direction == Trade.LONG:
|
||
|
|
return self.exit_price - self.entry_price
|
||
|
|
else:
|
||
|
|
return self.entry_price - self.exit_price
|
||
|
|
|
||
|
|
def pnl_percentage(self):
|
||
|
|
if self.direction == Trade.LONG:
|
||
|
|
return (self.exit_price - self.entry_price) / self.entry_price * 100
|
||
|
|
else:
|
||
|
|
return (self.entry_price - self.exit_price) / self.entry_price * 100
|