Esempio n. 1
0
    def mfi_calc(self, df, print_log=True):
        df['volume_aver'] = (df['volume_ask'] + df['volume_bid']) / 2
        for tmprd_mfi in self.mfi_tmprd_arr:
            postfix = '_' + processing.digit_to_text(tmprd_mfi)
            new_clmn_names = [self.mfi_base_clmn_name + postfix]
            if print_log: print('new_clmn_names: ', new_clmn_names)
            inp = {
                'df': df,
                'function': tl.MFI,
                'add_columns': new_clmn_names,
                'shift': 1,
                'high': df['high'].values,
                'low': df['low'].values,
                'close': df['close'].values,
                'volume': df['volume_aver'].values,
                'timeperiod': tmprd_mfi
            }
            df = processing.features_add(**inp)

        for item in self.mfi_compare_arr:
            clmn_1 = self.mfi_base_clmn_name + '_' + processing.digit_to_text(
                item[0])
            clmn_2 = self.mfi_base_clmn_name + '_' + processing.digit_to_text(
                item[1])
            new_clmn_name = self.mfi_base_clmn_name + '_cmpr_' + processing.digit_to_text(item[0]) + '_' + \
                            processing.digit_to_text(item[1])
            df = processing.clmn_compare(df=df,
                                         clmn_1=clmn_1,
                                         clmn_2=clmn_2,
                                         new_clmn_name=new_clmn_name)

        return df
Esempio n. 2
0
    def tema_calc(self, df, print_log=True):
        for tmprd_tema in self.tema_tmprd_arr:
            postfix = '_' + processing.digit_to_text(tmprd_tema)
            new_clmn_names = [self.tema_base_clmn_name + postfix]
            if print_log: print('new_clmn_names: ', new_clmn_names)
            inp = {
                'df': df,
                'function': tl.TEMA,
                'add_columns': new_clmn_names,
                'shift': 0,
                'real': df['open'].values,
                'timeperiod': tmprd_tema
            }
            df = processing.features_add(**inp)

            inp = (df, 'open', new_clmn_names[0], 'tema_open' + postfix)
            df = processing.clmn_compare(*inp)

        for item in self.tema_compare_arr:
            clmn_1 = self.tema_base_clmn_name + '_' + processing.digit_to_text(
                item[0])
            clmn_2 = self.tema_base_clmn_name + '_' + processing.digit_to_text(
                item[1])
            new_clmn_name = self.tema_base_clmn_name + '_cmpr_' + processing.digit_to_text(item[0]) + '_' + \
                            processing.digit_to_text(item[1])
            df = processing.clmn_compare(df=df,
                                         clmn_1=clmn_1,
                                         clmn_2=clmn_2,
                                         new_clmn_name=new_clmn_name)

        return df
Esempio n. 3
0
    def bb_calc(self, df, print_log=True):
        for tmprd_bb in self.bb_tmprd_arr:
            for d in self.bb_d_arr:
                nbdevup, nbdevdn = d, d
                postfix = '_' + processing.digit_to_text(
                    tmprd_bb) + '_' + processing.digit_to_text(d)
                new_clmn_names = [
                    name + postfix for name in self.bb_base_clmn_names
                ]
                if print_log: print('new_clmn_names: ', new_clmn_names)
                inp = {
                    'df': df,
                    'function': tl.BBANDS,
                    'add_columns': new_clmn_names,
                    'real': df['open'].values,
                    'timeperiod': tmprd_bb,
                    'nbdevup': nbdevup,
                    'nbdevdn': nbdevdn,
                    'matype': 0
                }
                df = processing.features_add(**inp)

                new_clmn_name = 'bb_rp' + postfix
                df = self.bb_price_position(df, 'open', new_clmn_names[0],
                                            new_clmn_names[1],
                                            new_clmn_names[2], new_clmn_name)
                # удаляем столбцы со значениями ubb, mbb, lbb. Остаётся только отн. положение цены в BB-канале.
                df.drop(columns=new_clmn_names[0], inplace=True)
                df.drop(columns=new_clmn_names[1], inplace=True)
                df.drop(columns=new_clmn_names[2], inplace=True)

        for item in self.bb_compare_arr:
            clmn_1 = 'bb_rp' + '_' + processing.digit_to_text(
                item[0]) + '_' + processing.digit_to_text(item[2])
            clmn_2 = 'bb_rp' + '_' + processing.digit_to_text(
                item[1]) + '_' + processing.digit_to_text(item[2])
            new_clmn_name = 'bb_rp_cmpr_' + processing.digit_to_text(item[0]) + '_' + \
                            processing.digit_to_text(item[1]) + '_' + processing.digit_to_text(item[2])
            df = processing.clmn_compare(df=df,
                                         clmn_1=clmn_1,
                                         clmn_2=clmn_2,
                                         new_clmn_name=new_clmn_name)

        return df
Esempio n. 4
0
    def macd_calc(self, df, print_log=True):
        for params_macd in self.macd_params_arr:
            postfix = '_' + processing.digit_to_text(params_macd[0]) \
                      + '_' + processing.digit_to_text(params_macd[1]) + '_' + processing.digit_to_text(params_macd[2])
            new_clmn_names = [
                name + postfix for name in self.macd_base_clmn_names
            ]
            if print_log: print('new_clmn_names: ', new_clmn_names)
            inp = {
                'df': df,
                'function': tl.MACD,
                'add_columns': new_clmn_names,
                'shift': 0,
                'real': df['open'].values,
                'fastperiod': params_macd[0],
                'slowperiod': params_macd[1],
                'signalperiod': params_macd[2]
            }
            df = processing.features_add(**inp)

        return df
Esempio n. 5
0
    def so_calc(self, df, print_log=True):
        for param_so in self.so_param_arr:
            postfix = '_' + processing.digit_to_text(
                param_so[0]) + '_' + processing.digit_to_text(param_so[1])
            new_clmn_names = [
                name + postfix for name in self.so_base_clmn_names
            ]
            if print_log: print('new_clmn_names: ', new_clmn_names)
            inp = {
                'df': df,
                'function': tl.STOCH,
                'add_columns': new_clmn_names,
                'shift': 1,
                'high': df['high'].values,
                'low': df['low'].values,
                'close': df['close'].values,
                'fastk_period': param_so[0],
                'slowk_period': int(param_so[0] * self.so_k_slowk_period),
                'slowd_period': param_so[1]
            }
            df = processing.features_add(**inp)

            inp = (df, new_clmn_names[0], new_clmn_names[1],
                   'so_k_d' + postfix)
            df = processing.clmn_compare(*inp)

        for item in self.so_compare_arr:
            clmn_1 = 'so_k' + '_' + processing.digit_to_text(
                item[0][0]) + '_' + processing.digit_to_text(item[0][1])
            clmn_2 = 'so_k' + '_' + processing.digit_to_text(
                item[1][0]) + '_' + processing.digit_to_text(item[1][1])
            new_clmn_name = 'so_k_cmpr_' + processing.digit_to_text(item[0][0]) + '_' + \
                            processing.digit_to_text(item[0][1]) + '_' + processing.digit_to_text(item[1][0]) + '_' + \
                            processing.digit_to_text(item[1][1])
            df = processing.clmn_compare(df=df,
                                         clmn_1=clmn_1,
                                         clmn_2=clmn_2,
                                         new_clmn_name=new_clmn_name)

        return df