コード例 #1
0
 def init_bp_manager(self):
     if self.__bp_manager is None:
         self.__bp_manager = BPManager()
コード例 #2
0
class ZhongXingConverter(object):
    def __init__(self, work_dir=None):
        self.id = float('nan')
        self.__ZhongXing_meta_list = []
        self.work_dir = work_dir
        self.__bp_manager = None

    def set_meat_list(self, HeFeiV3_meta_list):
        self.__ZhongXing_meta_list = HeFeiV3_meta_list

    def get_meat_list(self):
        return self.__ZhongXing_meta_list

    def init_bp_manager(self):
        if self.__bp_manager is None:
            self.__bp_manager = BPManager()

    def init_strategy_id(self):
        self.id = get_max_id(self.work_dir)
        if self.id == -1:
            self.id = self.__bp_manager.get_max_portfolio_id()

    def start_converter(self):
        self.init_bp_manager()
        self.init_strategy_id()
        for meta in self.__ZhongXing_meta_list:
            self.strategy_to_json(meta)

    def strategy_to_json(self, ZhongXingMeta):
        data_json = {}
        try:
            signal_finder = SignalFinder()
            for member in ZhongXingMeta.get_const_member_list():
                member_value = getattr(ZhongXingMeta, member)
                if member in ZhongXingMeta.get_portfolio_list():
                    data_json[member] = reference_portfolio(member_value)
                    if data_json[member] == -1:
                        raise CSVConverterError(
                            ZhongXingMeta.Name, ZhongXingMeta.Type,
                            "Can't find portfolio: {0}".format(member_value))
                elif member in ZhongXingMeta.get_signal_list():
                    data_json[member] = (
                        signal_finder.get_signal_id_by_name(member_value),
                        member_value)[isinstance(member_value, int)]
                    if data_json[member] == -1:
                        raise CSVConverterError(
                            ZhongXingMeta.Name, ZhongXingMeta.Type,
                            "Can't find signal: {0}".format(member_value))

                elif member in ZhongXingMeta.get_bool_list():
                    data_json[member] = is_bool(member_value)
                elif member in ZhongXingMeta.get_MatchStrategyId():
                    data_json[member] = (get_strategy_id_by_name(
                        self.work_dir, member_value), member_value)[isinstance(
                            member_value, int)]
                    if data_json[member] == -1:
                        raise CSVConverterError(
                            ZhongXingMeta.Name, ZhongXingMeta.Type,
                            "Can't find matchstrategy:{0}".format(
                                member_value))
                else:
                    data_json[member] = member_value
            data_json['Instruments'] = generate_instruments(
                ZhongXingMeta, ZhongXingMeta.member_list)
            data_json['Ranges'] = generate_ranges(ZhongXingMeta,
                                                  ZhongXingMeta.member_list)
        except Exception as e:
            raise CSVConverterError(ZhongXingMeta.Name, ZhongXingMeta.Type,
                                    e.message)
        if self.work_dir is not None:
            self.__create_file(data_json)
        return data_json

    def __create_file(self, data):
        self.id += 1
        data['Id'] = self.id
        file_path = '{0}/Existed_Json_Module/{1:0>4}{2}.strategy'.format(
            self.work_dir, data['Id'], data['Name'])
        json.dump([data], open(file_path, 'w'))
        return self.id
コード例 #3
0
class TianJinConverter(object):
    def __init__(self, work_dir=None):
        self.id = float('nan')
        self.__TianJin_meta_list = []
        self.work_dir = work_dir
        self.__bp_manager = None
        
    def set_meat_list(self, HeFeiV3_meta_list):
        self.__TianJin_meta_list = HeFeiV3_meta_list

    def get_meat_list(self):
        return self.__TianJin_meta_list

    def init_bp_manager(self):
        if self.__bp_manager is None:
            self.__bp_manager = BPManager()

    def init_strategy_id(self):
        self.id = get_max_id(self.work_dir)
        if self.id == -1:
            self.id = self.__bp_manager.get_max_portfolio_id()

    def start_converter(self):
        self.init_bp_manager()
        self.init_strategy_id()
        for meta in self.__TianJin_meta_list:
            self.strategy_to_json(meta)

    def strategy_to_json(self, TianJinMeta):
        data_json = {}
        try:
            signal_finder = SignalFinder()
            for member in TianJinMeta.get_const_member_list():
                member_value = getattr(TianJinMeta, member)
                if member in TianJinMeta.get_portfolio_list():
                    data_json[member] = reference_portfolio(member_value)
                    if data_json[member] == -1:
                        raise CSVConverterError(TianJinMeta.Name, TianJinMeta.Type, "Can't find portfolio: {0}".format(member_value))
                elif member in TianJinMeta.get_signal_list():
                    data_json[member] = (signal_finder.get_signal_id_by_name(member_value), member_value)[isinstance(member_value, int)]
                    if data_json[member] == -1:
                        raise CSVConverterError(TianJinMeta.Name, TianJinMeta.Type, "Can't find signal: {0}".format(member_value))

                elif member in TianJinMeta.get_bool_list():
                    data_json[member] = is_bool(member_value)
                elif member in TianJinMeta.get_MatchStrategyId():
                    data_json[member] = (get_strategy_id_by_name(self.work_dir, member_value), member_value)[isinstance(member_value, int)]
                    if data_json[member] == -1:
                        raise CSVConverterError(TianJinMeta.Name, TianJinMeta.Type, "Can't find matchstrategy:{0}".format(member_value))
                else:
                    data_json[member] = member_value
            data_json['Instruments'] = generate_instruments(TianJinMeta, TianJinMeta.member_list)
            data_json['Ranges'] = generate_ranges(TianJinMeta, TianJinMeta.member_list)
        except Exception as e:
            raise CSVConverterError(TianJinMeta.Name, TianJinMeta.Type, e.message)
        if self.work_dir is not None:
            self.__create_file(data_json)
        return data_json
    def __create_file(self, data):
        self.id += 1
        data['Id'] = self.id
        file_path = '{0}/Existed_Json_Module/{1:0>4}{2}.strategy'.format(self.work_dir, data['Id'], data['Name'])
        json.dump([data], open(file_path, 'w'))
        return self.id
コード例 #4
0
 def init_bp_manager(self):
     if self.__bp_manager is None:
         self.__bp_manager = BPManager()