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.
 

33 lines
847 B

'''
'''
class Trade:
'''
'''
LONG = 1
SHORT = 2
def __init__(self, entry_price, exit_price, entry_bar, exit_bar, direction = LONG):
'''
Constructor
'''
self.direction = direction
self.entry_price = entry_price
self.exit_price = exit_price
self.entry_bar = entry_bar
self.exit_bar = exit_bar
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