Beispiel #1
0
def other_indicator(model: OfflineTaskModel):
    # 离线计算其他指标

    indicatorInfo = model.taskModel

    indicatorId = model.extVal

    if del_data(sqlPa="delete from fof_index_value where INDICATOR_ID = '%s'" % indicatorId) == False:
        raise Error("删除历史数据失败,任务结束")

    if indicatorId not in INDEX_CODE_NAME_CACHE.keys():
        raise Error("指标id不存在:{}".format(indicatorId))

    indexName = INDEX_CODE_NAME_CACHE[indicatorId]

    # fundAdjNav = getPublicData(['股票型', '混合型'])
    fundAdjNav = getPublicData()
    fundSymbols = list(fundAdjNav.columns)
    updatedType = []
    fundClass_1 = pd.Series('混合型基金', index=fundSymbols)
    fundClass_tmp = getData_fundInformation(fundSymbols)['FUND_INVESTTYPE']
    fundClass_1[fundClass_tmp.index] = fundClass_tmp
    for symbol in fundSymbols:
        allIndicators = []
        fundType = fundClass_1[symbol]
        if fundType not in updatedType:
            for cycle in n_cycle_tp:
                btParms = {'indexName': indexName, 'cycle': cycle, 'symbol': symbol, 'sample': '一级',
                           'marketIndex': '',
                           'otherPar': ''}
                self = indexScore_fund(btParms, fundAdjNav, 'auto')
                op = self.output
                val = op['factorValue']
                allIndicators.append(val)
                updatedType.append(fundType)
        df = pd.DataFrame(allIndicators).fillna(bus_const.blank)
        cols = df.columns.tolist()
        for col in cols:
            res = df[col]
            lst = res.values.tolist()
            lst = [transformFloatIfAvaliable(l) for l in lst]
            objId = uuid_util.gen_uuid()
            lst.insert(0, str(objId))
            lst.insert(1, str(indicatorId))
            lst.insert(2, col)
            date = formatDate2yyyymmdd()
            lst.insert(3, str(date))
            lst.append("sys")
            lst.append(datetime.datetime.now())
            lst.append("sys")
            lst.append(datetime.datetime.now())

            tp = tuple(lst)
            sql = "INSERT INTO fof_index_value (`OBJECT_ID`, `INDICATOR_ID`, `J_WINDCODE`, `TRADE_DT`, `THISYEAR_VALUE`, `QUARTER_VALUE`, `HALFYEAR_VALUE`, `YEAR_VALUE`, `TWOYEA_VALUE`, `THREEYEAR_VALUE`, `FIVEYEAR_VALUE`, `N1_VALUE`, `N2_VALUE`, `CREATE_USER_ID`, `CREATE_TIME`, `UPDATE_USER_ID`, `UPDATE_TIME`, `DELETE_FLAG`) VALUES ( %s, %s, %s, %s, %s, %s,%s,%s,  %s,%s, %s, %s, %s, %s, %s, %s, %s,0)"

            mysqlops.insert_one(MysqlConf.DB.fof, sql, tp)
        allIndicators.clear()
Beispiel #2
0
def volatility(model: OfflineTaskModel):
    # 离线计算年化波动率
    if del_data('fof_variance') == False:
        raise Error("删除历史数据失败,任务结束")

    indicatorInfo = model.taskModel
    taskName = indicatorInfo.value[0]

    indiId = get_indicator_id(taskName)

    # fundAdjNav = getPublicData(['股票型', '混合型'])
    fundAdjNav = getPublicData()
    fundSymbols = list(fundAdjNav.columns)
    fundClass_1 = pd.Series('混合型基金', index=fundSymbols)
    fundClass_tmp = getData_fundInformation(fundSymbols)['FUND_INVESTTYPE']
    fundClass_1[fundClass_tmp.index] = fundClass_tmp
    halfs = indicatorInfo.value[1]
    for half in halfs:
        updatedType = []
        allIndicators = []
        for symbol in fundSymbols:
            fundType = fundClass_1[symbol]
            if fundType not in updatedType:
                for cycle in n_cycle_tp:
                    btParms = {'indexName': taskName, 'cycle': cycle, 'symbol': symbol, 'sample': '一级',
                               'marketIndex': '',
                               'otherPar': half}
                    self = indexScore_fund(btParms, fundAdjNav, 'auto')
                    op = self.output
                    val = op['factorValue']
                    allIndicators.append(val)
                    updatedType.append(fundType)
            df = pd.DataFrame(allIndicators).fillna(bus_const.blank)
            cols = df.columns.tolist()
            for col in cols:
                res = df[col]
                lst = res.values.tolist()
                lst = [transformFloatIfAvaliable(l) for l in lst]

                objId = uuid_util.gen_uuid()
                lst.insert(0, str(objId))
                lst.insert(1, str(indiId))
                lst.insert(2, str(col))
                date = formatDate2yyyymmdd()
                lst.insert(3, str(date))
                lst.insert(4, transformString2Decimal(half))
                lst.append("sys")
                lst.append(datetime.datetime.now())
                lst.append("sys")
                lst.append(datetime.datetime.now())

                tp = tuple(lst)
                sql = "INSERT INTO fof_variance (`OBJECT_ID`, `INDICATOR_ID`, `J_WINDCODE`, `TRADE_DT`, `F_WEIGHT`, `THISYEAR_VALUE`, `QUARTER_VALUE`, `HALFYEAR_VALUE`, `YEAR_VALUE`, `TWOYEA_VALUE`, `THREEYEAR_VALUE`, `FIVEYEAR_VALUE`, `N1_VALUE`, `N2_VALUE`, `CREATE_USER_ID`, `CREATE_TIME`, `UPDATE_USER_ID`, `UPDATE_TIME`, `DELETE_FLAG`) VALUES ( %s, %s, %s, %s, %s, %s, %s,%s, %s, %s,  %s, %s, %s, %s, %s, %s, %s,%s,0)"
                mysqlops.insert_one(MysqlConf.DB.fof, sql, tp)
            allIndicators.clear()
Beispiel #3
0
def indicator_score_rank(model: OfflineTaskModel):
    # 离线计算指标得分

    indicatorId = model.extVal
    if indicatorId not in INDEX_CODE_NAME_CACHE.keys():
        raise Error("指标id不存在:{}".format(indicatorId))

    if not del_data(
            sqlPa="delete from fof_index_score where INDICATOR_ID = '%s' " %
            indicatorId):
        raise Error("删除历史数据失败,任务结束")

    iName = INDEX_CODE_NAME_CACHE[indicatorId]

    # fundAdjNav = getPublicData(['股票型', '混合型'])
    fundAdjNav = getPublicData()
    fundSymbols = list(fundAdjNav.columns)
    updatedType = []
    fundClass_1 = pd.Series('混合型基金', index=fundSymbols)
    fundClass_tmp = getData_fundInformation(fundSymbols)['FUND_INVESTTYPE']
    fundClass_1[fundClass_tmp.index] = fundClass_tmp
    for symbol in fundSymbols:
        indicators = []
        ranks = []
        fundType = fundClass_1[symbol]
        if fundType not in updatedType:
            for cycle in cycle_score:
                btParms = {
                    'indexName': iName,
                    'cycle': cycle,
                    'symbol': symbol,
                    'sample': '一级',
                    'marketIndex': '',
                    'otherPar': ''
                }
                self = indexScore_fund(btParms, fundAdjNav, 'auto')
                op = self.output
                score = op['factorScore']
                rank = op['factorRank']
                # 这个值是用来记录当前cycle及分类下参与排名的样本数量,因为前端显示的排名都是5 / 200
                # 这种形式,本意是要存入数据库的,但我跟平赞沟通过了,他说他们前端直接根据数据库里的数据处理即可,不用存这个字段了
                # sc = op['sampleCounts']
                # tp = score
                # for ti in tp.index:
                #     tp[ti] = str(sc)
                indicators.append(score)
                ranks.append(rank)
                ranks.append(pd.Series())  # 一级分类排名样本
                ranks.append(pd.Series())  # 二级分类排名一期不上,先做个空值
                ranks.append(pd.Series())  # 二级分类排名样本一期不上,先做个空值
                updatedType.append(fundType)

        indicators.extend(ranks)
        df = pd.DataFrame(indicators).fillna('9999999999999.0')
        cols = df.columns.tolist()
        for col in cols:
            res = df[col]  # [基金id,score,score,...]
            lst = res.values.tolist()
            lst = [transformFloatIfAvaliable2(l) for l in lst]
            objId = uuid_util.gen_uuid()
            lst.insert(0, str(objId))
            lst.insert(1, str(indicatorId))
            lst.insert(2, col)
            # lst.insert(2, list(map(lambda x: x[-2:] + x[:-2], [col]))[0])
            date = formatDate2yyyymmdd()
            lst.insert(3, str(date))
            lst.append("sys")
            lst.append(datetime.datetime.now())
            lst.append("sys")
            lst.append(datetime.datetime.now())
            lst = [
                '9999999999999.0' if type(ele) == pd.Series else ele
                for ele in lst
            ]
            tp = tuple(lst)
            sql = "INSERT INTO fof_index_score VALUES ( %s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s, %s, %s,%s,%s,%s, %s, %s, %s, %s, %s, %s, %s,%s,%s,%s, %s, %s, %s, %s, %s, %s, %s,%s,0)"
            mysqlops.insert_one(MysqlConf.DB.fof, sql, tp)
        indicators.clear()
        ranks.clear()
Beispiel #4
0
def information_ratio(model: OfflineTaskModel):
    # 离线计算信息比率

    if del_data('fof_inforatio') == False:
        raise Error("删除历史数据失败,任务结束")

    # sql = "delete from fof_inforatio "
    # mysqlops.fetch_one(MysqlConf.DB.fof, sql)
    indicatorInfo = model.taskModel
    taskName = indicatorInfo.value[0]
    indiId = get_indicator_id(taskName)
    # fundAdjNav = getPublicData(['股票型', '混合型'])
    fundAdjNav = getPublicData()
    fundSymbols = list(fundAdjNav.columns)
    updatedType = []
    fundClass_1 = pd.Series('混合型基金', index=fundSymbols)
    fundClass_tmp = getData_fundInformation(fundSymbols)['FUND_INVESTTYPE']
    fundClass_1[fundClass_tmp.index] = fundClass_tmp
    for symbol in fundSymbols:
        allIndicators = []
        fundType = fundClass_1[symbol]
        if fundType not in updatedType:
            for cycle in n_cycle_tp:
                btParms = {'indexName': taskName, 'cycle': cycle, 'symbol': symbol, 'sample': '一级',
                           'marketIndex': '',
                           'otherPar': ''}
                self = indexScore_fund(btParms, fundAdjNav, 'auto')
                op = self.output
                val = op['factorValue']
                allIndicators.append(val)
                updatedType.append(fundType)
        df = pd.DataFrame(allIndicators).fillna(bus_const.blank)
        cols = df.columns.tolist()
        for col in cols:
            res = df[col]
            dd = res.values.tolist()

            lst = [transformFloatIfAvaliable(l) for l in dd]

            objId = uuid_util.gen_uuid()
            lst.insert(0, str(objId))
            lst.insert(1, str(indiId))
            lst.insert(2, col)
            date = formatDate2yyyymmdd()
            lst.insert(3, str(date))

            # idxVal = None
            # try:
            #     idxVal = CODE_INDEX_CACHE[col]
            # except:
            #     # 缓存没有查一次数据库
            #     sql = "SELECT s_info_windcode,s_info_indexwindcode  FROM chinamutualfundbenchmark where S_INFO_WINDCODE = '{}'".format(
            #         col)
            #     res = mysqlops.fetchmany(MysqlConf.DB.fof, sql)
            #     if res and 's_info_indexwindcode' in res and res['s_info_indexwindcode'] is not None:
            #         idxVal = res['s_info_indexwindcode'].decode()

            lst.insert(4, indicatorInfo.value[1])  # 比较基准wind代码
            lst.append("sys")
            lst.append(datetime.datetime.now())
            lst.append("sys")
            lst.append(datetime.datetime.now())

            tp = tuple(lst)
            sql = "INSERT INTO fof_inforatio (`OBJECT_ID`, `INDICATOR_ID`, `J_WINDCODE`, `TRADE_DT`, `B_WINDCODE`, `THISYEAR_VALUE`, `QUARTER_VALUE`, `HALFYEAR_VALUE`, `YEAR_VALUE`, `TWOYEA_VALUE`, `THREEYEAR_VALUE`, `FIVEYEAR_VALUE`, `N1_VALUE`, `N2_VALUE`, `CREATE_USER_ID`, `CREATE_TIME`, `UPDATE_USER_ID`, `UPDATE_TIME`, `DELETE_FLAG`) VALUES ( %s, %s, %s, %s, %s, %s, %s,%s,%s,%s, %s, %s, %s, %s, %s, %s, %s, %s,0)"
            mysqlops.insert_one(MysqlConf.DB.fof, sql, tp)
        allIndicators.clear()