Exemple #1
0
 def HeikinAshi(candles_open, candles_high, candles_low, candles_close):
     """
     Return HeikinAshi array of the given candles
     :param open: list of open
     :param high: list of high
     :param low: list of low
     :param close: list of close
     :return: HAopen, HAhigh, HAlow, HAclose
     """
     haOpen, haHigh, haLow, haClose = [np.array([]) for i in range(4)]
     for i, (open_value, high_value, low_value, close_value) \
                         in enumerate(zip(candles_open, candles_high, candles_low, candles_close)):
         if i == 0:
             haOpen = np.append(haOpen, open_value)
             haHigh = np.append(haHigh, high_value)
             haLow = np.append(haLow, low_value)
             haClose = np.append(haClose, close_value)
             continue
         haOpen = np.append(
             haOpen, mean([candles_open[i - 1], candles_close[i - 1]]))
         haHigh = np.append(haHigh, high_value)
         haLow = np.append(haLow, low_value)
         haClose = np.append(
             haClose, mean([open_value, high_value, low_value,
                            close_value]))
     return haOpen, haHigh, haLow, haClose
Exemple #2
0
    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],
                        data_util.mean(trades_and_rank[TRADES]))
                       for result, trades_and_rank in
                       results_through_all_time_frame.items()]

        # inner function to replace uncythonizable lambda expression
        def _sorting_key(elem):
            return elem[RANK]

        self.sorted_results_through_all_time_frame = sorted(result_list,
                                                            key=_sorting_key)
 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 data_util.mean(bot_profitabilities)
Exemple #4
0
 def HL2(candles_high, candles_low):
     """
     Return a list of HL2 value (high + low ) / 2
     :param high: list of high
     :param low: list of low
     :return: list of HL2
     """
     return np.array(
         list(
             map((lambda candles_high, candles_low: mean(
                 [candles_high, candles_low])), candles_high, candles_low)))
Exemple #5
0
 def HLC3(candles_high, candles_low, candles_close):
     """
     Return a list of HLC3 values (high + low + close) / 3
     :param high: list of high
     :param low: list of low
     :param close: list of close
     :return: list of HLC3
     """
     return np.array(
         list(
             map((lambda candles_high, candles_low, candles_close: mean(
                 [candles_high, candles_low, candles_close])), candles_high,
                 candles_low, candles_close)))
Exemple #6
0
 def OHLC4(candles_open, candles_high, candles_low, candles_close):
     """
     Return a list of OHLC4 value (open + high + low + close) / 4
     :param open: list of open
     :param high: list of high
     :param low: list of low
     :param close: list of close
     :return: list of OHLC4
     """
     return np.array(
         list(
             map((lambda candles_open, candles_high, candles_low,
                  candles_close: mean([
                      candles_open, candles_high, candles_low, candles_close
                  ])), candles_open, candles_high, candles_low,
                 candles_close)))
 async def _analyse_arbitrage_opportunities(self):
     other_exchanges_average_price = data_util.mean(self.other_exchanges_mark_prices.values())
     state = None
     if other_exchanges_average_price > self.own_exchange_mark_price * self.sup_triggering_price_delta_ratio:
         # min long = high price > own_price / (1 - 2fees)
         state = trading_enums.EvaluatorStates.LONG
     elif other_exchanges_average_price < self.own_exchange_mark_price * self.inf_triggering_price_delta_ratio:
         # min short = low price < own_price * (1 - 2fees)
         state = trading_enums.EvaluatorStates.SHORT
     if state is not None:
         # lock to prevent concurrent order management
         async with self.lock:
             # 1. cancel invalided opportunities if any
             await self._ensure_no_expired_opportunities(other_exchanges_average_price, state)
             # 2. handle new opportunities
             await self._trigger_arbitrage_opportunity(other_exchanges_average_price, state)
 def get_average_trades_count(self):
     return data_util.mean(self.trades_counts)
Exemple #9
0
def test_mean():
    assert mean([1, 2, 3, 4, 5, 6, 7]) == 4.0
    assert mean([0.684, 1, 2, 3, 4, 5.5, 6, 7.5]) == 3.7105
    assert mean([]) == 0