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 strategy_to_json(self, TradingUniverseMeta): data_json = {} try: signal_finder = SignalFinder() is_error = False for member in TradingUniverseMeta.get_const_member_list(): member_value = getattr(TradingUniverseMeta, member) if member in TradingUniverseMeta.get_bool_list(): data_json[member] = is_bool( getattr(TradingUniverseMeta, member)) elif member in TradingUniverseMeta.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: is_error = True else: data_json[member] = getattr(TradingUniverseMeta, member) data_json["TradingUniverse"] = reference_arg_manager( "$GetTradingUniverse({0})".format(None)) if not is_error: signal_object = SignalObject() signal_object.name = TradingUniverseMeta.Name signal_object.type = TradingUniverseMeta.Type signal_object.enable = True signal_object.node = json.dumps(data_json) self.__signal_object_list.append(signal_object) except Exception as e: raise CSVConverterError(TradingUniverseMeta.Name, TradingUniverseMeta.Type, e.message)
def strategy_to_json(self, SouthMeta): data_json = {} try: signal_finder = SignalFinder() is_error = False for member in SouthMeta.get_const_member_list(): member_value = getattr(SouthMeta, member) if member in SouthMeta.get_bool_list(): data_json[member] = is_bool(getattr(SouthMeta, member)) elif member in SouthMeta.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: is_error=True else: data_json[member] = getattr(SouthMeta, member) param = data_json["South"].strip().split('$') param = param[1].split(',') param[0] = param[0][1:] param[-1] = param[-1][:-1] data_json["South"] = reference_arg_manager("$GetSouth({0},{1})".format(SouthMeta.BalanceDate,param[-1])) param = data_json["South1"].strip().split('$') param = param[1].split(',') param[0] = param[0][1:] param[-1] = param[-1][:-1] data_json["South1"] = reference_arg_manager("$GetSouth({0},{1})".format(SouthMeta.BalanceDate,param[-1])) if not is_error: signal_object = SignalObject() signal_object.name = SouthMeta.Name signal_object.type = SouthMeta.Type signal_object.enable = True signal_object.node = json.dumps(data_json) self.__signal_object_list.append(signal_object) except Exception as e: raise CSVConverterError(SouthMeta.Name, SouthMeta.Type, e.message)
def strategy_to_json(self, ExtraDayReturnSquareMeta): data_json = {} try: signal_finder = SignalFinder() is_error = False for member in ExtraDayReturnSquareMeta.get_const_member_list(): member_value = getattr(ExtraDayReturnSquareMeta, member) if member in ExtraDayReturnSquareMeta.get_bool_list(): data_json[member] = is_bool( getattr(ExtraDayReturnSquareMeta, member)) elif member in ExtraDayReturnSquareMeta.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: is_error = True else: data_json[member] = getattr(ExtraDayReturnSquareMeta, member) if not is_error: signal_object = SignalObject() signal_object.name = ExtraDayReturnSquareMeta.Name signal_object.type = ExtraDayReturnSquareMeta.Type signal_object.enable = True signal_object.node = json.dumps(data_json) self.__signal_object_list.append(signal_object) except Exception as e: raise CSVConverterError(ExtraDayReturnSquareMeta.Name, ExtraDayReturnSquareMeta.Type, e.message)
def strategy_to_json(self, HFStrategyMeta): data_json = {} try: signal_finder = SignalFinder() for member in HFStrategyMeta.get_const_member_list(): member_value = getattr(HFStrategyMeta, member) if member in HFStrategyMeta.get_portfolio_list(): data_json[member] = reference_portfolio(member_value) if data_json[member] == -1: raise CSVConverterError(HFStrategyMeta.Name, HFStrategyMeta.Type, "Can't find portfolio: {0}".format(member_value)) elif member in HFStrategyMeta.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(HFStrategyMeta.Name, HFStrategyMeta.Type, "Can't find signal: {0}".format(member_value)) elif member in HFStrategyMeta.get_bool_list(): data_json[member] = is_bool(member_value) elif member in HFStrategyMeta.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(HFStrategyMeta.Name, HFStrategyMeta.Type, "Can't find matchstrategy:{0}".format(member_value)) else: data_json[member] = member_value data_json['Instruments'] = generate_instruments(HFStrategyMeta, HFStrategyMeta.member_list) data_json['Ranges'] = generate_ranges(HFStrategyMeta, HFStrategyMeta.member_list) except Exception as e: raise CSVConverterError(HFStrategyMeta.Name, HFStrategyMeta.Type, e.message) if self.work_dir is not None: self.__create_file(data_json) return data_json
def strategy_to_json(self, SectorAmountDiversificationMeta): data_json = {} try: signal_finder = SignalFinder() is_error = False for member in SectorAmountDiversificationMeta.get_const_member_list(): member_value = getattr(SectorAmountDiversificationMeta, member) if member in SectorAmountDiversificationMeta.get_bool_list(): data_json[member] = is_bool(getattr(SectorAmountDiversificationMeta, member)) elif member in SectorAmountDiversificationMeta.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: is_error=True else: data_json[member] = getattr(SectorAmountDiversificationMeta, member) data_json["SectorAmountDiversification"] = reference_arg_manager("$GetSectorAmountDiversification({0},{1},{2})".format(SectorAmountDiversificationMeta.CalculateDate,SectorAmountDiversificationMeta.SegmentDays,SectorAmountDiversificationMeta.MAWin)) if not is_error: signal_object = SignalObject() signal_object.name = SectorAmountDiversificationMeta.Name signal_object.type = SectorAmountDiversificationMeta.Type signal_object.enable = True signal_object.node = json.dumps(data_json) self.__signal_object_list.append(signal_object) except Exception as e: raise CSVConverterError(SectorAmountDiversificationMeta.Name, SectorAmountDiversificationMeta.Type, e.message)
def strategy_to_json(self, SouthMeta): data_json = {} try: signal_finder = SignalFinder() is_error = False for member in SouthMeta.get_const_member_list(): member_value = getattr(SouthMeta, member) if member in SouthMeta.get_bool_list(): data_json[member] = is_bool(getattr(SouthMeta, member)) elif member in SouthMeta.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: is_error = True else: data_json[member] = getattr(SouthMeta, member) param = data_json["South"].strip().split('$') param = param[1].split(',') param[0] = param[0][1:] param[-1] = param[-1][:-1] data_json["South"] = reference_arg_manager( "$GetSouth({0},{1})".format(SouthMeta.BalanceDate, param[-1])) param = data_json["South1"].strip().split('$') param = param[1].split(',') param[0] = param[0][1:] param[-1] = param[-1][:-1] data_json["South1"] = reference_arg_manager( "$GetSouth({0},{1})".format(SouthMeta.BalanceDate, param[-1])) if not is_error: signal_object = SignalObject() signal_object.name = SouthMeta.Name signal_object.type = SouthMeta.Type signal_object.enable = True signal_object.node = json.dumps(data_json) self.__signal_object_list.append(signal_object) except Exception as e: raise CSVConverterError(SouthMeta.Name, SouthMeta.Type, e.message)
def strategy_to_json(self, SectorAmountDiversificationMeta): data_json = {} try: signal_finder = SignalFinder() is_error = False for member in SectorAmountDiversificationMeta.get_const_member_list( ): member_value = getattr(SectorAmountDiversificationMeta, member) if member in SectorAmountDiversificationMeta.get_bool_list(): data_json[member] = is_bool( getattr(SectorAmountDiversificationMeta, member)) elif member in SectorAmountDiversificationMeta.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: is_error = True else: data_json[member] = getattr( SectorAmountDiversificationMeta, member) data_json["SectorAmountDiversification"] = reference_arg_manager( "$GetSectorAmountDiversification({0},{1},{2})".format( SectorAmountDiversificationMeta.CalculateDate, SectorAmountDiversificationMeta.SegmentDays, SectorAmountDiversificationMeta.MAWin)) if not is_error: signal_object = SignalObject() signal_object.name = SectorAmountDiversificationMeta.Name signal_object.type = SectorAmountDiversificationMeta.Type signal_object.enable = True signal_object.node = json.dumps(data_json) self.__signal_object_list.append(signal_object) except Exception as e: raise CSVConverterError(SectorAmountDiversificationMeta.Name, SectorAmountDiversificationMeta.Type, e.message)
def strategy_to_json(self, JinMeta): data_json = {} try: signal_finder = SignalFinder() is_error = False for member in JinMeta.get_const_member_list(): member_value = getattr(JinMeta, member) if member in JinMeta.get_bool_list(): data_json[member] = is_bool(getattr(JinMeta, member)) elif member in JinMeta.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: is_error=True else: data_json[member] = getattr(JinMeta, member) if not is_error: signal_object = SignalObject() signal_object.name = JinMeta.Name signal_object.type = JinMeta.Type signal_object.enable = True signal_object.node = json.dumps(data_json) self.__signal_object_list.append(signal_object) except Exception as e: raise CSVConverterError(JinMeta.Name, JinMeta.Type, e.message)