def get_average_strategy_eval(self, exchange, active_only=False): eval_list = [ s.get_eval_note() for s in self.get_strategies_eval_list(exchange, active_only) if isinstance(s.get_eval_note(), (int, float)) ] return DataUtil.mean(eval_list)
def get_progress(self): if not self.min_time_frame_to_consider: return 0 else: progresses = [] for symbol in self.time_frame_get_times: if symbol in self.min_time_frame_to_consider: current = self.time_frame_get_times[symbol][self.min_time_frame_to_consider[symbol]] nb_max = len(self.data[symbol][self.min_time_frame_to_consider[symbol]]) progresses.append(current / nb_max) return int(DataUtil.mean(progresses) * 100)
def _find_optimal_configuration_using_results(self): for time_frame in self.all_time_frames: time_frame_sorted_results = self.get_sorted_results(self.run_results, time_frame) self.sorted_results_by_time_frame[time_frame.value] = time_frame_sorted_results results_through_all_time_frame = {} for results in self.sorted_results_by_time_frame.values(): for rank, result in enumerate(results): result_summary = result.get_config_summary() if result_summary not in results_through_all_time_frame: results_through_all_time_frame[result_summary] = [[], 0] results_through_all_time_frame[result_summary][RANK] += rank results_through_all_time_frame[result_summary][TRADES] += result.trades_counts result_list = [(result, trades_and_rank[RANK], DataUtil.mean(trades_and_rank[TRADES])) for result, trades_and_rank in results_through_all_time_frame.items()] self.sorted_results_through_all_time_frame = sorted(result_list, key=lambda res: res[RANK])
def _create_orders(self, lower_bound, upper_bound, side, sorted_orders, portfolio, current_price, missing_orders, state): if lower_bound >= upper_bound: self.logger.warning(f"No {side} orders for {self.symbol} possible: current price beyond boundaries.") return [] orders = [] selling = side == TradeOrderSide.SELL currency, market = split_symbol(self.symbol) order_limiting_currency = currency if selling else market order_limiting_currency_amount = portfolio[order_limiting_currency][Portfolio.AVAILABLE] \ if order_limiting_currency in portfolio else 0 if state == self.NEW: # create staggered orders starting_bound = lower_bound * (1 + self.spread / 2) if selling else upper_bound * (1 - self.spread / 2) self.flat_spread = AbstractTradingModeCreator.adapt_price(self.symbol_market, current_price * self.spread) orders_count, average_order_quantity = \ self._get_order_count_and_average_quantity(current_price, selling, lower_bound, upper_bound, order_limiting_currency_amount, currency=order_limiting_currency) for i in range(orders_count): price = self._get_price_from_iteration(starting_bound, selling, i) if price is not None: quantity = self._get_quantity_from_iteration(average_order_quantity, self.mode, side, i, orders_count, price) if quantity is not None: orders.append(OrderData(side, quantity, price, self.symbol)) if not orders: self.logger.error(f"Not enough {order_limiting_currency} to create {side.name} orders. " f"For the strategy to work better, add {order_limiting_currency} funds or " f"change change the strategy settings to make less but bigger orders.") else: orders.reverse() if state == self.FILL: # complete missing orders if missing_orders: max_quant_per_order = order_limiting_currency_amount / len(missing_orders) missing_orders_around_spread = [] for missing_order_price, missing_order_side in missing_orders: if missing_order_side == side: previous_o = None following_o = None for o in sorted_orders: if previous_o is None: previous_o = o elif o.origin_price > missing_order_price: following_o = o break else: previous_o = o if previous_o.side == following_o.side: # missing order between similar orders quantity = min(DataUtil.mean([previous_o.origin_quantity, following_o.origin_quantity]), max_quant_per_order / missing_order_price) orders.append(OrderData(missing_order_side, quantity, missing_order_price, self.symbol, False)) self.logger.debug(f"Creating missing orders not around spread: {orders[-1]}") else: missing_orders_around_spread.append((missing_order_price, missing_order_side)) if missing_orders_around_spread: # missing order next to spread starting_bound = upper_bound if selling else lower_bound increment_window = self.flat_increment/2 order_limiting_currency_available_amount = \ portfolio[order_limiting_currency][Portfolio.AVAILABLE] \ if order_limiting_currency in portfolio else 0 portfolio_total = portfolio[order_limiting_currency][Portfolio.TOTAL] \ if order_limiting_currency in portfolio else 0 order_limiting_currency_amount = portfolio_total if order_limiting_currency_available_amount: orders_count, average_order_quantity = \ self._get_order_count_and_average_quantity(current_price, selling, lower_bound, upper_bound, portfolio_total, currency=order_limiting_currency) for missing_order_price, missing_order_side in missing_orders_around_spread: limiting_amount_from_this_order = order_limiting_currency_amount price = starting_bound found_order = False i = 0 while not found_order and i < orders_count: quantity = self._get_quantity_from_iteration(average_order_quantity, self.mode, side, i, orders_count, price) limiting_currency_quantity = quantity if selling else quantity / price if price is not None and limiting_amount_from_this_order > 0 and \ price-increment_window <= missing_order_price <= price+increment_window: if limiting_currency_quantity > limiting_amount_from_this_order or \ limiting_currency_quantity > order_limiting_currency_available_amount: limiting_currency_quantity = min(limiting_amount_from_this_order, order_limiting_currency_available_amount) found_order = True if limiting_currency_quantity is not None: orders.append(OrderData(side, limiting_currency_quantity, price, self.symbol, False)) self.logger.debug(f"Creating missing order around spread {orders[-1]}") price = price - self.flat_increment if selling else price + self.flat_increment limiting_amount_from_this_order -= limiting_currency_quantity i += 1 elif state == self.ERROR: self.logger.error("Impossible to create staggered orders when incompatible order are already in place. " "Cancel these orders of you want to use this trading mode.") return orders
def get_average_trades_count(self): return DataUtil.mean(self.trades_counts)
def get_average_score(self): bot_profitabilities = [ profitability_result[self.BOT_PROFITABILITY] - profitability_result[self.MARKET_PROFITABILITY] for profitability_result in self.run_profitabilities] return DataUtil.mean(bot_profitabilities)