def compute_profit_loss(self): selection_id = self.list_runner[self.the_draw]["selection_id"] market_id = self.list_runner[self.the_draw]["market_id"] pc = Execution(market_id=market_id, selection_id=selection_id, customer_order_ref=self.customer_ref, strategy_id=self.strategy_id) closed_market_outcome = 0 for key in self.lost.keys(): if key < self.the_draw: closed_market_outcome += self.lost[key] current_profit = 0 if pc.ask_for_price(): current_lay = pc.current_lay if current_lay is None: return None current_profit = ( self.win[self.the_draw] + self.lost[self.the_draw] * current_lay) / current_lay profit = closed_market_outcome + current_profit return profit
def cashout(self): selection_id = self.list_runner[self.active]["selection_id"] market_id = self.list_runner[self.active]["market_id"] pc = Execution(market_id=market_id, selection_id=selection_id) unhedged_position = pc.compute_unhedged_position() if pc.ask_for_price(): current_lay = pc.current_lay if current_lay is None: return None get_logger().info("cashout", cashout=unhedged_position / current_lay) lay_hedge = unhedged_position / current_lay * 0.5 if lay_hedge > self.target_profit: pc.cashout(0.5)
def compute_profit_loss(self): selection_id = self.list_runner[self.active]["selection_id"] market_id = self.list_runner[self.active]["market_id"] pc = Execution(market_id=market_id, selection_id=selection_id) closed_market_outcome = 0 for key in self.lost.keys(): if key < self.active: closed_market_outcome += self.lost[key] current_profit = 0 if pc.ask_for_price(): current_lay = pc.current_lay if current_lay is None: return None current_profit = (self.win[self.active] + self.lost[self.active] * current_lay) / current_lay profit = closed_market_outcome + current_profit return profit