Beispiel #1
0
    def __calc_signals_concurrency(self):
        """
        deprecated: 速度慢
        :return:
        """
        futures = set()
        with concurrent.futures.ProcessPoolExecutor(max_workers=4) as executor:
            for func_name, param_dict in self.__ta_factors:
                try:
                    func = self.func_lib[func_name]
                except KeyError as e:
                    raise e

                if not param_dict and func_name in inspect.getmembers(lsta, inspect.isfunction):
                    param_dict = get_default_args(func)

                if func_name in inspect.getmembers(lsta, inspect.isfunction):
                    max_period = num_bars_to_accumulate(func_name=func_name, **param_dict)
                else:
                    max_period = func.lookback + 1
                if len(self.dataframe) < max_period:
                    continue
                else:
                    future = executor.submit(func, self.dataframe.tail(max_period), **param_dict)
                    futures.add(future)

        for future in concurrent.futures.as_completed(futures):
            ret = future.result()
            if len(ret.shape) > 1:
                ret = ret.ix[:, 0]
            ind = self.dataframe.index[-1]
            print len(self.dataframe), func_name, ind, ret[-1]
            self.dataframe.ix[ind, func_name] = ret[-1]
Beispiel #2
0
    def __calc_signals(self):
        for func_name, param_dict in self.__ta_factors:

            try:
                func = self.func_lib[func_name]
            except KeyError as e:
                raise e

            if not param_dict and func_name in dict(inspect.getmembers(lsta, inspect.isfunction)):
                param_dict = get_default_args(func)

            if func_name in dict(inspect.getmembers(lsta, inspect.isfunction)):
                max_period = num_bars_to_accumulate(func_name=func_name, **param_dict)
            else:
                max_period = func.lookback + 1
            if len(self.dataframe) < max_period:
                continue
            else:
                try:
                    # TODO: 这里需要修改,合成一句
                    ret = func(self.dataframe.iloc[-max_period:], **param_dict)
                    if len(ret.shape) > 1:
                        ret = ret.ix[:, 0]
                    ind = self.dataframe.index[-1]
                    print len(self.dataframe), func_name, ind, ret[-1]
                    self.dataframe.ix[ind, func_name] = ret[-1]
                except IndexError as e:
                    print('__name={0},ind={1}'.format(func_name, ind))
                    raise e(func_name + ' ' + ind)
Beispiel #3
0
    def __calc_signals(self):
        for func_name, param_dict in self.__ta_factors:

            try:
                func = self.func_lib[func_name]
            except KeyError as e:
                raise e

            if not param_dict and func_name in dict(
                    inspect.getmembers(lsta, inspect.isfunction)):
                param_dict = get_default_args(func)

            if func_name in dict(inspect.getmembers(lsta, inspect.isfunction)):
                max_period = num_bars_to_accumulate(func_name=func_name,
                                                    **param_dict)
            else:
                max_period = func.lookback + 1
            if len(self.dataframe) < max_period:
                continue
            else:
                try:
                    # TODO: 这里需要修改,合成一句
                    ret = func(self.dataframe.iloc[-max_period:], **param_dict)
                    if len(ret.shape) > 1:
                        ret = ret.ix[:, 0]
                    ind = self.dataframe.index[-1]
                    print len(self.dataframe), func_name, ind, ret[-1]
                    self.dataframe.ix[ind, func_name] = ret[-1]
                except IndexError as e:
                    print('__name={0},ind={1}'.format(func_name, ind))
                    raise e(func_name + ' ' + ind)
Beispiel #4
0
    def __calc_signals_concurrency(self):
        """
        deprecated: 速度慢
        :return:
        """
        futures = set()
        with concurrent.futures.ProcessPoolExecutor(max_workers=4) as executor:
            for func_name, param_dict in self.__ta_factors:
                try:
                    func = self.func_lib[func_name]
                except KeyError as e:
                    raise e

                if not param_dict and func_name in inspect.getmembers(
                        lsta, inspect.isfunction):
                    param_dict = get_default_args(func)

                if func_name in inspect.getmembers(lsta, inspect.isfunction):
                    max_period = num_bars_to_accumulate(func_name=func_name,
                                                        **param_dict)
                else:
                    max_period = func.lookback + 1
                if len(self.dataframe) < max_period:
                    continue
                else:
                    future = executor.submit(func,
                                             self.dataframe.tail(max_period),
                                             **param_dict)
                    futures.add(future)

        for future in concurrent.futures.as_completed(futures):
            ret = future.result()
            if len(ret.shape) > 1:
                ret = ret.ix[:, 0]
            ind = self.dataframe.index[-1]
            print len(self.dataframe), func_name, ind, ret[-1]
            self.dataframe.ix[ind, func_name] = ret[-1]