コード例 #1
0
def test_TA(date):
    if not get_calendar('stock.sse').is_tradingday(date):
        date = get_calendar('stock.sse').shift_tradingdays(date, -1)
    sample = get_sample(date, 500)
    # sample = ['300167.SZ']
    sql_result = pd.Series({
        symbol: bs_shift_db(symbol, date, 'TotalAssets', 1)
        for symbol in sample
    }).fillna(-1000)
    db_result = query('TA', date).reindex(sql_result.index).fillna(-1000)
    if not np.all(np.isclose(sql_result, db_result)):
        diff = ~np.isclose(sql_result, db_result)
        print(sql_result[diff])
        print(db_result[diff])
        raise "Error in TA test!"
    print('All test passed!')
コード例 #2
0
def test_NI5S(date):
    if not get_calendar('stock.sse').is_tradingday(date):
        date = get_calendar('stock.sse').shift_tradingdays(date, -1)
    sample = get_sample(date, 500)
    # sample = ['300167.SZ']
    sql_result = pd.Series({
        symbol: cshift_db(symbol, date, 'NPParentCompanyOwners',
                          'LC_IncomeStatementAll', 5)
        for symbol in sample
    }).fillna(-1000)
    db_result = query('NI5S', date).reindex(sql_result.index).fillna(-1000)
    if not np.all(np.isclose(sql_result, db_result)):
        diff = ~np.isclose(sql_result, db_result)
        print(sql_result[diff])
        print(db_result[diff])
        raise "Error in NI5S test!"
    print('All test passed!')
コード例 #3
0
def test_TA2Y(date):
    if not get_calendar('stock.sse').is_tradingday(date):
        date = get_calendar('stock.sse').shift_tradingdays(date, -1)
    last_date = get_calendar('stock.sse').shift_tradingdays(date, -3)
    sample = get_sample(date, 500)
    # sample = ['300167.SZ']
    sql_result = pd.Series({
        symbol: bs_shift_db_year(symbol, date, 2, 'TotalAssets')
        for symbol in sample
    }).fillna(-1000)
    db_result = query('TA2Y', date).reindex(sql_result.index).fillna(-1000)
    # db_result = data_simu_calculation('FIEXP_TTM', last_date, date).iloc[-1].reindex(sql_result.index).fillna(-1000)
    if not np.all(np.isclose(sql_result, db_result)):
        diff = ~np.isclose(sql_result, db_result)
        print(sql_result[diff])
        print(db_result[diff])
        raise "Error in TA test!"
    print('All test passed!')
コード例 #4
0
def test_SPS3Y(date):
    if not get_calendar('stock.sse').is_tradingday(date):
        date = get_calendar('stock.sse').shift_tradingdays(date, -1)
    last_date = get_calendar('stock.sse').shift_tradingdays(date, -3)
    sample = get_sample(date, 500)
    # sample = ['600571.SH']
    sql_result = pd.Series({
        symbol: xps_shift_year(symbol, date, 'TotalOperatingRevenue',
                               'LC_IncomeStatementAll', 3)
        for symbol in sample
    }).fillna(-1000)
    db_result = query('SPS3Y', date).reindex(sql_result.index).fillna(-1000)
    # db_result = data_simu_calculation('FIEXP_TTM', last_date, date).iloc[-1].reindex(sql_result.index).fillna(-1000)
    if not np.all(np.isclose(sql_result, db_result)):
        diff = ~np.isclose(sql_result, db_result)
        print(sql_result[diff])
        print(db_result[diff])
        raise "Error in TA test!"
    print('All test passed!')
コード例 #5
0
def test_NI3Y(date):
    if not get_calendar('stock.sse').is_tradingday(date):
        date = get_calendar('stock.sse').shift_tradingdays(date, -1)
    last_date = get_calendar('stock.sse').shift_tradingdays(date, -3)
    sample = get_sample(date, 500)
    # sample = ['300167.SZ']
    sql_result = pd.Series({
        symbol: cshift_year_db(symbol, date, 'NPParentCompanyOwners',
                               'LC_IncomeStatementAll', 3)
        for symbol in sample
    }).fillna(-1000)
    db_result = query('NI3Y', date).reindex(sql_result.index).fillna(-1000)
    # db_result = data_simu_calculation('FIEXP_TTM', last_date, date).iloc[-1].reindex(sql_result.index).fillna(-1000)
    if not np.all(np.isclose(sql_result, db_result)):
        diff = ~np.isclose(sql_result, db_result)
        print(sql_result[diff])
        print(db_result[diff])
        raise "Error in TA test!"
    print('All test passed!')
コード例 #6
0
#!/usr/bin/env python
# -*- coding:utf-8
"""
Author:  Hao Li
Email: [email protected]
Github: https://github.com/SAmmer0
Created: 2018/5/2
"""
from pitdata import update_all
from pitdata import query, query_group

update_all()

# query single ts data
tmp1 = query('universe', '2018-01-01', '2018-03-01')
print(tmp1.head())
print(tmp1.tail())

# query single cs data
tmp2 = query('universe', '2018-01-01')
print(tmp2)
tmp3 = query('universe', '2018-01-02')
print(tmp3.head())

# query_group ts data
tmp4 = query_group(['universe', 'close'], '2018-01-01', '2018-03-01')
print(tmp4.head())

# query_group cs data
tmp5 = query_group(['universe', 'close'], '2018-01-01')
print(tmp5)
コード例 #7
0
def get_sample(date, sample_size):
    # date: 测试数据的时间
    # sample_size: 样本量大小
    universe = query('UNIVERSE', date).index.tolist()
    sample_res = sample(universe, sample_size)
    return sample_res