Esempio n. 1
0
def set_universe(code, refDate=None):
    if Settings.data_source == DataSource.WIND:
        from WindPy import w
        if not w.isconnected():
            w.start()
        if not refDate:
            rawData = w.wset('IndexConstituent',
                             'windcode=' + convert2WindSymbol(code),
                             'field=wind_code')
        else:
            rawData = w.wset('IndexConstituent', 'date=' + refDate,
                             'windcode=' + convert2WindSymbol(code),
                             'field=wind_code')
        if len(rawData.Data) == 0:
            return
        # convert to .xshg/.xshe suffix
        idx = [s.replace('SH', 'xshg') for s in rawData.Data[0]]
        idx = [s.replace('SZ', 'xshe') for s in idx]
        return idx
    elif Settings.data_source != DataSource.DXDataCenter:
        import os
        import tushare as ts

        try:
            ts.set_token(os.environ['DATAYES_TOKEN'])
        except KeyError:
            raise
        idx = ts.Idx()
        return list(idx.IdxCons(secID=code, field='consID')['consID'])
    else:
        from DataAPI import api
        data = api.GetIndexConstitutionInfo(
            code, refDate=refDate).sort_values('conSecurityID')
        return list(data.conSecurityID)
Esempio n. 2
0
def set_universe(code, refDate=None):
    if Settings.data_source != DataSource.DXDataCenter:
        import tushare as ts
        ts.set_token(
            '2bfc4b3b06efa5d8bba2ab9ef83b5d61f1c3887834de729b60eec9f13e1d4df8')
        idx = ts.Idx()
        return list(idx.IdxCons(secID=code, field='consID')['consID'])
    else:
        from DataAPI import api
        data = api.GetIndexConstitutionInfo(
            code, refDate=refDate).sort_values('conSecurityID')
        return list(data.conSecurityID)
Esempio n. 3
0
def set_universe(code, refDate=None):
    if Settings.data_source != DataSource.DXDataCenter:
        import os
        import tushare as ts

        try:
            ts.set_token(os.environ['DATAYES_TOKEN'])
        except KeyError:
            raise
        idx = ts.Idx()
        return list(idx.IdxCons(secID=code, field='consID')['consID'])
    else:
        from DataAPI import api
        data = api.GetIndexConstitutionInfo(code, refDate=refDate).sort_values('conSecurityID')
        return list(data.conSecurityID)