Added some more unit tests for Portfolio and Position. Added a README and a requirements file now that qsforex is open-source under an MIT license.
This commit is contained in:
@@ -12,8 +12,8 @@ class Position(object):
|
||||
self.exposure = Decimal(str(exposure))
|
||||
self.avg_price = Decimal(str(avg_price))
|
||||
self.cur_price = Decimal(str(cur_price))
|
||||
self.profit_base = self.calculate_profit_base()
|
||||
self.profit_perc = self.calculate_profit_perc()
|
||||
self.profit_base = self.calculate_profit_base(self.exposure)
|
||||
self.profit_perc = self.calculate_profit_perc(self.exposure)
|
||||
|
||||
def calculate_pips(self):
|
||||
getcontext.prec = 6
|
||||
@@ -24,19 +24,19 @@ class Position(object):
|
||||
Decimal("0.00001"), ROUND_HALF_DOWN
|
||||
)
|
||||
|
||||
def calculate_profit_base(self):
|
||||
def calculate_profit_base(self, exposure):
|
||||
pips = self.calculate_pips()
|
||||
return (pips * self.exposure / self.cur_price).quantize(
|
||||
return (pips * exposure / self.cur_price).quantize(
|
||||
Decimal("0.00001"), ROUND_HALF_DOWN
|
||||
)
|
||||
|
||||
def calculate_profit_perc(self):
|
||||
return (self.profit_base / self.exposure * Decimal("100.00")).quantize(
|
||||
def calculate_profit_perc(self, exposure):
|
||||
return (self.profit_base / exposure * Decimal("100.00")).quantize(
|
||||
Decimal("0.00001"), ROUND_HALF_DOWN
|
||||
)
|
||||
|
||||
def update_position_price(self, cur_price):
|
||||
def update_position_price(self, cur_price, exposure):
|
||||
self.cur_price = cur_price
|
||||
self.profit_base = self.calculate_profit_base()
|
||||
self.profit_perc = self.calculate_profit_perc()
|
||||
self.profit_base = self.calculate_profit_base(exposure)
|
||||
self.profit_perc = self.calculate_profit_perc(exposure)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user