Exemplo n.º 1
0
    def get_future_daily(self, date: DateUtils.DateType):
        renaming_dict = self._factor_param['行情数据']
        tickers = self.future_tickers.ticker(date)
        tickers = [self.windcode2jqcode(it) for it in tickers]

        data = jq.get_price(tickers,
                            start_date=date,
                            end_date=date,
                            frequency='daily',
                            fq=None,
                            fill_paused=True,
                            fields=[
                                'open', 'high', 'low', 'close', 'volume',
                                'money', 'open_interest'
                            ])
        settle_data = jq.get_extras('futures_sett_price',
                                    tickers,
                                    start_date=date,
                                    end_date=date)
        settle = settle_data.stack().reset_index()
        settle.columns = ['time', 'code', 'settle']
        combined_data = pd.merge(data, settle)
        db_data = self._standardize_df(combined_data,
                                       renaming_dict).sort_index()
        self.db_interface.insert_df(db_data, '期货日行情')
Exemplo n.º 2
0
def get_stock_list(cur_date='2018-06-26',
                   begin_date='2018-01-01',
                   MARKET_MIN_CAP=100,
                   MARKET_MAX_CAP=500):
    """
    获取从指定日期开始的,市值在指定区间的,非st,股票列表, 以及详细信息(code,circulating_cap,circulating_market_cap)
    """

    # 总市值在100-500亿
    q = jq.query(jq.valuation.code, jq.valuation.circulating_cap,
                 jq.valuation.circulating_market_cap).filter(
                     jq.valuation.code.notin_(['002473.XSHE',
                                               '000407.XSHE']),  # why?
                     jq.valuation.circulating_market_cap < MARKET_MAX_CAP,
                     jq.valuation.circulating_market_cap >= MARKET_MIN_CAP)

    df = jq.get_fundamentals(q, date=begin_date)
    df.index = list(df['code'])
    # 去除st
    st = jq.get_extras('is_st',
                       list(df['code']),
                       start_date=cur_date,
                       end_date=cur_date,
                       df=True)

    st = st.iloc[0]
    stock_list = list(st[st == False].index)

    return stock_list, df
Exemplo n.º 3
0
def remove_st(stocks, start, end):
    """
    去掉ST股票之后的股票列表
    """
    # 去除st
    st = jq.get_extras(
        'is_st', stocks, start_date=start, end_date=end, df=True)

    st = st.iloc[0]
    stock_list = list(st[st == False].index)

    return stock_list
Exemplo n.º 4
0
def get_jj_data():
    clear('./bob')
    today = '2019-06-27'
    data = jq.get_price(security='150019.XSHE', start_date='2015-01-01', end_date=today)
    jz = jq.get_extras(info='unit_net_value', security_list='150019.XSHE', start_date='2015-01-01', end_date=today, df=True,count=None)
    result = []
    for indexs in data.index:
        w_time = indexs
        w_close = data.loc[indexs].values[1]
        w_jz = jz.loc[indexs].values[0]
        diff = float(w_close)-float(w_jz)
        diffrea = diff/float(w_close)
        write('{0}--{1}--{2}--{3}--{4}\n'.format(w_time,w_close,w_jz,diff,diffrea),'./bob')    
Exemplo n.º 5
0
    def _get_future_settle_info(self, date):
        # table_name = '期货结算参数'
        tickers = self.future_tickers.ticker(date)
        tickers = [self.windcode2jqcode(it) for it in tickers]

        data = jq.get_extras('futures_sett_price',
                             tickers,
                             start_date=date,
                             end_date=date)
        data.columns = [self.jqcode2windcode(it) for it in data.columns]
        df = data.stack()
        df.name = '结算价'
        df.index.names = ['DateTime', 'ID']
        return df
def get_day_st(security, date):
    data_df = jq.get_extras("is_st",
                            security,
                            start_date=date,
                            end_date=date,
                            df=True)
    if data_df.empty:
        return pd.DataFrame({col: [] for col in ["security", "is_st", "date"]})
    data_df.index = [0]
    data_df.columns = ["is_st"]
    data_df["security"] = security
    data_df["date"] = date
    result_df = data_df[["security", "is_st", "date"]]
    return result_df
def get_securities_day_st(security_list, date):
    data_df = jq.get_extras("is_st",
                            security_list,
                            start_date=date,
                            end_date=date,
                            df=True)
    if data_df.empty:
        return pd.DataFrame({col: [] for col in ["security", "is_st", "date"]})
    data_df = data_df.reset_index(drop=True).T
    data_df.columns = ["is_st"]
    data_df["security"] = data_df.index
    data_df["date"] = date
    data_df = data_df.reset_index(drop=True)
    result_df = data_df[["security", "is_st", "date"]]
    return result_df
Exemplo n.º 8
0
def fetch_magic_candidators(engine, t_day):
    # 中证价值回报量化策略指数的样本空间由满足以下条件的沪深 A 股构成:
    # (1)非 ST、*ST 股票,非暂停上市股票; (2)非金融类股票。

    all_stocks = list(jq.get_all_securities(types=['stock'], date=t_day).index)
    #all_stocks = all_stocks[:100]

    # 排除金融类的股票
    banks = jq.get_industry_stocks('J66', date=t_day)
    brokers = jq.get_industry_stocks('J67', date=t_day)
    insurances = jq.get_industry_stocks('J68', date=t_day)
    others = jq.get_industry_stocks('J69', date=t_day)
    exclude = banks + brokers + insurances + others

    filtered_1 = []

    for code in all_stocks:
        if (code in exclude):
            print "  ... %s 是金融类, 排除..." % code
            continue

        filtered_1.append(code)

    # 排除 ST
    st = jq.get_extras('is_st',
                       filtered_1,
                       start_date=t_day,
                       end_date=t_day,
                       df=False)

    filtered_2 = []
    for code in filtered_1:
        if st[code][0]:
            print "  ...  %s 是ST,排除" % code
            continue

        filtered_2.append(code)

    filtered_3 = []
    # 排除停牌
    for code in filtered_2:
        if data_fetcher.is_paused(engine, code, t_day):
            print "  ...  %s 停牌,排除" % code
            continue

        filtered_3.append(code)

    return filtered_3
def get_stock(stockPool,begin_date):
    if stockPool=='HS300':
        stockList=jq.get_index_stocks('000300.XSHG',begin_date)
    elif stockPool=='ZZ500':
        stockList=jq.get_index_stocks('399905.XSHE',begin_date)
    elif stockPool=='ZZ800':
        stockList=jq.get_index_stocks('399906.XSHE',begin_date)   
    elif stockPool=='CYBZ':
        stockList=jq.get_index_stocks('399006.XSHE',begin_date)
    elif stockPool=='ZXBZ':
        stockList=jq.get_index_stocks('399005.XSHE',begin_date)
    elif stockPool=='A':
        stockList=jq.get_index_stocks('000002.XSHG',begin_date)+jq.get_index_stocks('399107.XSHE',begin_date)
    #剔除ST股
    st_data=jq.get_extras('is_st',stockList, count = 1,end_date=begin_date)
    stockList = [stock for stock in stockList if not st_data[stock][0]]
    #剔除停牌、新股及退市股票
    stockList=delect_stop(stockList,begin_date)
    #print(stockList)
    return stockList
Exemplo n.º 10
0
def del_st(date):
    stocks_sql = "select code from security"
    stock_codes = my.select_all(stocks_sql, ())

    jq.login()

    st_list = []
    for stock_code in stock_codes:
        code = stock_code['code']

        st_data = sdk.get_extras('is_st', [code],
                                 start_date=date,
                                 end_date=date)
        result = st_data.iloc[0][code]

        if result:
            print('%s 结果为:%s', code, result)
            st = code
            st_list.append(st)

    print(st_list)
    del_sql = "delete from security where code in (%s)"
    my.delete_many(del_sql, st_list)
Exemplo n.º 11
0
def get_extras(*args, **kwargs):
    return jqdatasdk.get_extras(*args, **kwargs)