Esempio n. 1
0
def test_apply_split_SQL_dataloader():
    engine = create_engine("sqlite://")
    dl = DataLoader(directory="tests/data/NASDAQ/data",
                    mode="SQL",
                    engine=engine,
                    tablename="eod")
    dl.load_data()
    dl.apply_splits(directory="tests/data/NASDAQ/adjustments/")
    df = pd.read_sql_table("eod", engine)
    result = pd.read_csv("NASDAQ/nasdaq_results.csv", parse_dates=["date"])
    splits = pd.read_csv("tests/data/NASDAQ/adjustments/splits.csv",
                         parse_dates=["date"])
    for i, row in splits.iterrows():
        sym = row.at["symbol"]
        cond = 'symbol == "{}"'.format(sym)
        frame1 = df.query(cond).sort_values(by="date").reset_index(drop=True)
        frame2 = result.query(cond).sort_values(by="date").reset_index(
            drop=True)
        L = len(frame1)
        cols = frame1.columns
        for i in range(L):
            for j in cols:
                if j in ["open", "high", "low", "close", "volume"]:
                    a = frame1.loc[i, j]
                    b = frame2.loc[i, j]
                    assert isclose(a, b, abs_tol=0.015)
                else:
                    assert frame1.loc[i, j] == frame2.loc[i, j]
Esempio n. 2
0
def test_apply_split_HDF_dataloader():
    with tempfile.NamedTemporaryFile() as fp:
        engine = fp.name
        dl = DataLoader(
            directory="tests/data/NASDAQ/data",
            mode="HDF",
            engine=engine,
            tablename="eod",
        )
        dl.load_data()
        dl.apply_splits(directory="tests/data/NASDAQ/adjustments/")
        df = pd.read_hdf(engine, "data/eod")
        result = pd.read_csv("tests/data/NASDAQ/nasdaq_results.csv",
                             parse_dates=["date"])
        splits = pd.read_csv("tests/data/NASDAQ/adjustments/splits.csv",
                             parse_dates=["date"])
        for i, row in splits.iterrows():
            sym = row.at["symbol"]
            cond = 'symbol == "{}"'.format(sym)
            frame1 = df.query(cond).sort_values(by="date").reset_index(
                drop=True)
            frame2 = result.query(cond).sort_values(by="date").reset_index(
                drop=True)
            L = len(frame1)
            cols = frame1.columns
            for i in range(L):
                for j in cols:
                    if j in ["open", "high", "low", "close", "volume"]:
                        a = frame1.loc[i, j]
                        b = frame2.loc[i, j]
                        print(a, b, sym)
                        assert isclose(a, b, abs_tol=0.015)
                    else:
                        assert frame1.loc[i, j] == frame2.loc[i, j]
Esempio n. 3
0
def test_apply_split_HDF_dataloader():
    with tempfile.NamedTemporaryFile() as fp:
        engine = fp.name
        dl = DataLoader(directory='tests/data/NASDAQ/data',
                        mode='HDF',
                        engine=engine,
                        tablename='eod')
        dl.load_data()
        dl.apply_splits(directory='tests/data/NASDAQ/adjustments/')
        df = pd.read_hdf(engine, 'data/eod')
        result = pd.read_csv('tests/data/NASDAQ/nasdaq_results.csv',
                             parse_dates=['date'])
        splits = pd.read_csv('tests/data/NASDAQ/adjustments/splits.csv',
                             parse_dates=['date'])
        for i, row in splits.iterrows():
            sym = row.at['symbol']
            cond = 'symbol == "{}"'.format(sym)
            frame1 = df.query(cond).sort_values(by='date').reset_index(
                drop=True)
            frame2 = result.query(cond).sort_values(by='date').reset_index(
                drop=True)
            L = len(frame1)
            cols = frame1.columns
            for i in range(L):
                for j in cols:
                    if j in ['open', 'high', 'low', 'close', 'volume']:
                        a = frame1.loc[i, j]
                        b = frame2.loc[i, j]
                        print(a, b, sym)
                        assert isclose(a, b, abs_tol=0.015)
                    else:
                        assert frame1.loc[i, j] == frame2.loc[i, j]